From 1716a17093955daee5d6c9ca8d3cdeb375b61ae8 Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 14 Jul 2016 10:30:46 +0000 Subject: [PATCH] CCM NG: More classes for the content section application git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4196 8810af33-2d31-482b-a856-94f89814c4df --- .../main/java/org/librecms/CmsConstants.java | 3 + .../contentsection/ContentSection.java | 44 ++-- .../contentsection/ContentSectionConfig.java | 34 +++ .../contentsection/ContentSectionCreator.java | 46 ++++ .../contentsection/ContentSectionServlet.java | 210 ++++++++++++++++++ .../ContentSectionResources.properties | 19 ++ .../ContentSectionResources_de.properties | 19 ++ .../ui/login/LoginApplicationCreator.java | 4 +- .../com/arsdigita/ui/login/LoginServlet.java | 3 +- .../java/com/arsdigita/web/BaseServlet.java | 2 +- .../main/java/org/libreccm/core/CcmCore.java | 2 - 11 files changed, 361 insertions(+), 25 deletions(-) create mode 100644 ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionConfig.java create mode 100644 ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionCreator.java create mode 100644 ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionServlet.java create mode 100644 ccm-cms/src/main/resources/org/librecms/contentsection/ContentSectionResources.properties create mode 100644 ccm-cms/src/main/resources/org/librecms/contentsection/ContentSectionResources_de.properties diff --git a/ccm-cms/src/main/java/org/librecms/CmsConstants.java b/ccm-cms/src/main/java/org/librecms/CmsConstants.java index 0a33e7302..79f7e464a 100644 --- a/ccm-cms/src/main/java/org/librecms/CmsConstants.java +++ b/ccm-cms/src/main/java/org/librecms/CmsConstants.java @@ -28,6 +28,9 @@ public class CmsConstants { public static final String DB_SCHEMA = "CCM_CMS"; + public static final String CONTENT_SECTION_APP_TYPE = "org.librecms.contentsection.ContentSection"; + public static final String CONTENT_SECTION_SERVLET_PATH = "/templates/servlet/content-section/*"; + public static final String PRIVILEGE_ADMINISTER_CATEGORIES = "administer_categories"; public static final String PRIVILEGE_ADMINISTER_CONTENT_TYPES = "administer_content_types"; public static final String PRIVILEGE_ADMINISTER_LIFECYLES = "administer_lifecyles"; diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java index 5c3d3fbe4..d8eddcdb9 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSection.java @@ -35,6 +35,7 @@ import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.OneToOne; import javax.persistence.Table; +import org.libreccm.web.ApplicationType; import static org.librecms.CmsConstants.*; @@ -44,10 +45,16 @@ import static org.librecms.CmsConstants.*; */ @Entity @Table(name = "CONTENT_SECTIONS", schema = DB_SCHEMA) +@ApplicationType( + name = CONTENT_SECTION_APP_TYPE, + descBundle = "org.librecms.contentsection.ContentSectionResources", + singleton = false, + creator = ContentSectionCreator.class, + servlet = ContentSectionServlet.class) public class ContentSection extends CcmApplication implements Serializable { private static final long serialVersionUID = -671718122153931727L; - + protected static final String ROOT = "root"; protected static final String ASSETS = "assets"; protected static final String ALERT_RECIPIENT = "alert_recipient"; @@ -56,7 +63,6 @@ public class ContentSection extends CcmApplication implements Serializable { protected static final String MANAGER = "manager"; protected static final String PUBLISHER = "publisher"; protected static final String CONTENT_READER = "content_reader"; - @Column(name = "LABEL", length = 512) private String label; @@ -241,23 +247,23 @@ public class ContentSection extends CcmApplication implements Serializable { @Override public String toString(final String data) { return super.toString(String.format( - ", label = \"%s\", " - + "rootDocumentsFolder = \"%s\", " - + "rootAssetsFolder = \"%s\", " - + "pageResolverClass = \"%s\", " - + "itemResolverClass = \"%s\", " - + "templateResolverClass = \"%s\", " - + "xmlGeneratorClass = \"%s\", " - + "defaultLocale = \"%s\"%s", - label, - Objects.toString(rootDocumentsFolder), - Objects.toString(rootAssetsFolder), - pageResolverClass, - itemResolverClass, - templateResolverClass, - xmlGeneratorClass, - Objects.toString(defaultLocale), - data)); + ", label = \"%s\", " + + "rootDocumentsFolder = \"%s\", " + + "rootAssetsFolder = \"%s\", " + + "pageResolverClass = \"%s\", " + + "itemResolverClass = \"%s\", " + + "templateResolverClass = \"%s\", " + + "xmlGeneratorClass = \"%s\", " + + "defaultLocale = \"%s\"%s", + label, + Objects.toString(rootDocumentsFolder), + Objects.toString(rootAssetsFolder), + pageResolverClass, + itemResolverClass, + templateResolverClass, + xmlGeneratorClass, + Objects.toString(defaultLocale), + data)); } } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionConfig.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionConfig.java new file mode 100644 index 000000000..bc9d9b806 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionConfig.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2016 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.contentsection; + +import org.libreccm.configuration.Configuration; +import org.libreccm.configuration.Setting; + +/** + * Global settings for content sections. Some of these settings control + * the initial values for new content sections. + * + * @author Jens Pelzetter + */ +@Configuration +public class ContentSectionConfig { + + +} diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionCreator.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionCreator.java new file mode 100644 index 000000000..cf943619e --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionCreator.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2016 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.contentsection; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import org.libreccm.web.ApplicationCreator; +import org.libreccm.web.ApplicationRepository; +import org.libreccm.web.ApplicationType; +import org.libreccm.web.CcmApplication; + +/** + * + * @author Jens Pelzetter + */ +@RequestScoped +public class ContentSectionCreator + implements ApplicationCreator{ + + @Inject + private ApplicationRepository appRepo; + + @Override + public CcmApplication createInstance(final String primaryUrl, + final ApplicationType type) { + return appRepo.retrieveApplicationForPath(primaryUrl); + } + + +} diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionServlet.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionServlet.java new file mode 100644 index 000000000..d40e0329b --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionServlet.java @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2016 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.contentsection; + +import com.arsdigita.bebop.Page; +import com.arsdigita.web.ApplicationFileResolver; +import com.arsdigita.web.BaseApplicationServlet; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.libreccm.web.CcmApplication; +import org.librecms.CmsConstants; + +/* + * This servlet will maybe removed. Our current plan is to integrate the navigation + * application into ccm-cms, and to deliver all content using that app. Then + * this servlet becomes useless. + */ + + /* + * NOTE: + * Repaired ItemURLCache to save multilingual items with automatic + * language negotiation. The cache now uses the remaining url part + * and the language concatinated as a hash table key. The delimiter + * is CACHE_KEY_DELIMITER. + */ + + /* + * NOTE 2: + * In a process of refactoring from legacy compatible to legacy free applications. + * TODO: + * - replace url check using RequestContext which resolves to SiteNodeRequest + * implementation (due to SiteNodeRequest used in BaseApplicationServlet). + * - Refactor content item UI bebop ApplicationPage or PageFactory instead of + * legacy infected sitenode / package dispatchers. + */ +/** + * Content Section's Application Servlet according CCM core web application + * structure { + * + * @see com.arsdigita.web.Application} implements the content section UI. + * + * It handles the UI for content items and delegates the UI for sections and + * folders to jsp templates. + * + * @author unknown + * @author Peter Boy + * @author Jens Pelzetter + */ +@WebServlet(urlPatterns = {CmsConstants.CONTENT_SECTION_SERVLET_PATH}) +public class ContentSectionServlet extends BaseApplicationServlet { + + private static final long serialVersionUID = 8061725145564728637L; + + private static final Logger LOGGER = LogManager.getLogger( + ContentSectionServlet.class); + + /** + * Literal for the prefix (in url) for previewing items + */ + public static final String PREVIEW = "/preview"; + /** + * Literal Template files suffix + */ + public static final String FILE_SUFFIX = ".jsp"; + /** + * Literal of URL Stub for index file name (includes leading slash) + */ + public static final String INDEX_FILE = "/index"; + public static final String XML_SUFFIX = ".xml"; + public static final String XML_MODE = "xmlMode"; + public static final String MEDIA_TYPE = "templateContext"; + private static final String CACHE_KEY_DELIMITER = "%"; + + public static final String CONTENT_ITEM + = "com.arsdigita.cms.dispatcher.item"; + public static final String CONTENT_SECTION + = "com.arsdigita.cms.dispatcher.section"; + + //ToDo: private final ContentItemDispatcher m_disp = new ContentItemDispatcher(); + public static Map s_itemResolverCache = Collections + .synchronizedMap(new HashMap()); + private static Map s_itemURLCacheMap = null; + /** + * Whether to cache the content items + */ + private static final boolean s_cacheItems = true; + // NEW STUFF here used to process the pages in this servlet + /** + * URL (pathinfo) -> Page object mapping. Based on it (and the http request + * url) the doService method selects a page to display + */ + private final Map m_pages = new HashMap(); + /** + * Path to directory containg ccm-cms template (jsp) files + */ + private String m_templatePath; + + /** + * Resolver to actually use to find templates (JSP). JSP may be stored in + * file system or otherwise, depends on resolver. Resolver is retrieved from + * configuration. (probably used for other stuff as JSP's as well) + */ + private ApplicationFileResolver m_resolver; + + /** + * Init method overwrites parents init to pass in optional parameters + * {@link com.arsdigita.web.BaseServlet}. If not specified system wide + * defaults are used. + * + * @param config + * @throws javax.servlet.ServletException + */ + @Override + public void init(ServletConfig config) throws ServletException { + + super.init(config); + + // optional init-param named template-path from ~/WEB-INF/web.xml + // may overwrite configuration parameters + String templatePath = config.getInitParameter("template-path"); + //ToDo + /*if (templatePath == null) { + m_templatePath = ContentSection.getConfig().getTemplateRoot(); + } else { + m_templatePath = config.getInitParameter("template-path"); + }*/ + + // optional init-param named file-resolver from ~/WEB-INF/web.xml + String resolverName = config.getInitParameter("file-resolver"); + + //ToDo +// if (resolverName == null) { +// m_resolver = Web.getConfig().getApplicationFileResolver(); +// } else { +// m_resolver = (ApplicationFileResolver) Classes.newInstance( +// resolverName); +// } + LOGGER.debug("Template path is {} with resolver {}", + m_templatePath, + m_resolver.getClass().getName()); + + // NEW STUFF here will be used to process the pages in this servlet + // Currently NOT working + // addPage("/admin", new MainPage()); // index page at address ~/cs + // addPage("/admin/index.jsp", new MainPage()); + // addPage("/admin/item.jsp", new MainPage()); + } + + /** + * Internal service method, adds one pair of Url - Page to the internal hash + * map, used as a cache. + * + * @param pathInfo url stub for a page to display + * @param page Page object to display + */ + private void addPage(final String pathInfo, final Page page) { + m_pages.put(pathInfo, page); + } + + /** + * Implementation of parent's (abstract) doService method checks HTTP + * request to determine whether to handle a content item or other stuff + * which is delegated to jsp templates. + * { + * + * @see com.arsdigita.web.BaseApplicationServlet#doService + * (HttpServletRequest, HttpServletResponse, Application)} + * + * @param request + * @param response + * @param app + * @throws javax.servlet.ServletException + * @throws java.io.IOException + */ + @Override + protected void doService(final HttpServletRequest request, + final HttpServletResponse response, + final CcmApplication app) + throws ServletException, IOException { + + //ToDo + throw new UnsupportedOperationException(); + } + +} diff --git a/ccm-cms/src/main/resources/org/librecms/contentsection/ContentSectionResources.properties b/ccm-cms/src/main/resources/org/librecms/contentsection/ContentSectionResources.properties new file mode 100644 index 000000000..1c197ca17 --- /dev/null +++ b/ccm-cms/src/main/resources/org/librecms/contentsection/ContentSectionResources.properties @@ -0,0 +1,19 @@ +# Copyright (C) 2016 LibreCCM Foundation. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA + +application_title=Content Section +application_desc=A content section is used to group similar content. diff --git a/ccm-cms/src/main/resources/org/librecms/contentsection/ContentSectionResources_de.properties b/ccm-cms/src/main/resources/org/librecms/contentsection/ContentSectionResources_de.properties new file mode 100644 index 000000000..c1617c216 --- /dev/null +++ b/ccm-cms/src/main/resources/org/librecms/contentsection/ContentSectionResources_de.properties @@ -0,0 +1,19 @@ +# Copyright (C) 2016 LibreCCM Foundation. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301 USA + +application_title=Inhaltssektion +application_desc=A content section is used to group similar content. diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/LoginApplicationCreator.java b/ccm-core/src/main/java/com/arsdigita/ui/login/LoginApplicationCreator.java index 4474c522c..eaa7dc99b 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/LoginApplicationCreator.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/LoginApplicationCreator.java @@ -32,8 +32,8 @@ import static com.arsdigita.ui.login.LoginConstants.*; * @author Jens Pelzetter */ @RequestScoped -public class LoginApplicationCreator implements - ApplicationCreator { +public class LoginApplicationCreator + implements ApplicationCreator { @Inject private ApplicationRepository appRepository; diff --git a/ccm-core/src/main/java/com/arsdigita/ui/login/LoginServlet.java b/ccm-core/src/main/java/com/arsdigita/ui/login/LoginServlet.java index c8c394ac0..f0f9bdb4c 100644 --- a/ccm-core/src/main/java/com/arsdigita/ui/login/LoginServlet.java +++ b/ccm-core/src/main/java/com/arsdigita/ui/login/LoginServlet.java @@ -57,7 +57,8 @@ import static com.arsdigita.ui.login.LoginConstants.*; * expose various properties, especially the URL_MSG's of public subpages (e.g. * logout) and initializes the creation of the UI. * - * @author Peter Boy + * @author Peter Boy + * @author Jens Pelzetter */ @WebServlet(urlPatterns = {LOGIN_SERVLET_PATH}) public class LoginServlet extends BebopApplicationServlet { diff --git a/ccm-core/src/main/java/com/arsdigita/web/BaseServlet.java b/ccm-core/src/main/java/com/arsdigita/web/BaseServlet.java index 996133efe..83b098ca7 100644 --- a/ccm-core/src/main/java/com/arsdigita/web/BaseServlet.java +++ b/ccm-core/src/main/java/com/arsdigita/web/BaseServlet.java @@ -54,7 +54,7 @@ public abstract class BaseServlet extends HttpServlet { * @throws javax.servlet.ServletException */ @Override - public final void init(final ServletConfig config) throws ServletException { + public void init(final ServletConfig config) throws ServletException { LOGGER.info("Initialising servlet %s (class: %s)...", config.getServletName(), getClass().getName()); diff --git a/ccm-core/src/main/java/org/libreccm/core/CcmCore.java b/ccm-core/src/main/java/org/libreccm/core/CcmCore.java index 89877f441..273a0ff7a 100644 --- a/ccm-core/src/main/java/org/libreccm/core/CcmCore.java +++ b/ccm-core/src/main/java/org/libreccm/core/CcmCore.java @@ -30,10 +30,8 @@ import java.io.IOException; import java.io.InputStream; import java.util.Properties; import javax.persistence.EntityManager; -import javax.xml.bind.JAXB; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.libreccm.categorization.Domain; import org.libreccm.modules.CcmModule; import org.libreccm.modules.InitEvent;