diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/AbstractItemResolver.java b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/AbstractItemResolver.java
deleted file mode 100755
index 557b313f3..000000000
--- a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/AbstractItemResolver.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-package com.arsdigita.cms.dispatcher;
-
-import com.arsdigita.bebop.PageState;
-
-import org.librecms.contentsection.ContentItem;
-import org.librecms.contentsection.ContentSection;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-
-import java.util.StringTokenizer;
-
-/**
- * @author bche
- */
-public abstract class AbstractItemResolver implements ItemResolver {
-
- protected static final String TEMPLATE_CONTEXT_PREFIX = "tem_";
-
- @Override
- public abstract ContentItem getItem(
- ContentSection section,
- String url,
- String context);
-
- @Override
- public abstract String getCurrentContext(PageState state);
-
- @Override
- public abstract String generateItemURL(
- PageState state,
- Long itemId,
- String name,
- ContentSection section,
- String context);
-
- @Override
- public abstract String generateItemURL(PageState state,
- Long itemId,
- String name,
- ContentSection section,
- String context,
- String templateContext);
-
- @Override
- public abstract String generateItemURL(PageState state,
- ContentItem item,
- ContentSection section,
- String context);
-
- @Override
- public abstract String generateItemURL(PageState state,
- ContentItem item,
- ContentSection section,
- String context,
- String templateContext);
-
- @Override
- public abstract CMSPage getMasterPage(ContentItem item,
- HttpServletRequest request)
- throws ServletException;
-
- /**
- * Finds the template context from the URL and returns it, if it is there.
- * Otherwise, returns null.
- *
- * @param inUrl the URL from which to get the template context
- *
- * @return the template context, or null if there is no template context
- */
- @Override
- public String getTemplateFromURL(final String inUrl) {
- String tempUrl;
- String url;
- if (inUrl.startsWith("/")) {
- tempUrl = inUrl.substring(1);
- } else {
- tempUrl = inUrl;
- }
-
- String templateContext = null;
- StringTokenizer tokenizer = new StringTokenizer(tempUrl, "/");
-
- if (tokenizer.hasMoreTokens()) {
- templateContext = tokenizer.nextToken();
- }
-
- if (templateContext != null && templateContext.startsWith(
- TEMPLATE_CONTEXT_PREFIX)) {
- return templateContext.substring(TEMPLATE_CONTEXT_PREFIX.length());
- } else {
- return null;
- }
- }
-
- /**
- * Removes the template context from the inUrl.
- *
- * @param inUrl URL, possibly including the template context.
- *
- * @return inUrl with the template context removed
- */
- @Override
- public String stripTemplateFromURL(final String inUrl) {
-
- String sTemplateContext = getTemplateFromURL(inUrl);
-
- if (sTemplateContext != null) {
- //there is a template context, so strip it
- int iTemplateLength = TEMPLATE_CONTEXT_PREFIX.length()
- + sTemplateContext.length() + 1;
- String sStripped = inUrl.substring(iTemplateLength, inUrl.length());
- return sStripped;
- } else {
- return inUrl;
- }
- }
-
-}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/CMSDispatcher.java b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/CMSDispatcher.java
index c2bb8a271..d050b44fa 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/CMSDispatcher.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/CMSDispatcher.java
@@ -24,6 +24,7 @@ import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.dispatcher.JSPApplicationDispatcher;
import com.arsdigita.dispatcher.RedirectException;
import com.arsdigita.dispatcher.RequestContext;
+import com.arsdigita.util.UncheckedWrapperException;
import com.arsdigita.web.LoginSignal;
import com.arsdigita.web.URL;
@@ -45,8 +46,10 @@ import org.libreccm.security.User;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
+import org.librecms.contentsection.ContentSectionManager;
import org.librecms.contentsection.ContentSectionRepository;
import org.librecms.contentsection.privileges.ItemPrivileges;
+import org.librecms.dispatcher.ItemResolver;
/**
*
@@ -139,7 +142,7 @@ public class CMSDispatcher implements Dispatcher, ChainedDispatcher { // Content section cache private static HashMap s_pageResolverCache = new HashMap(); - private static HashMap s_itemResolverCache = new HashMap(); +// private static HashMap s_itemResolverCache = new HashMap(); private static HashMap s_xmlGeneratorCache = new HashMap(); private boolean m_adminPagesOnly = false; @@ -489,17 +492,17 @@ public class CMSDispatcher implements Dispatcher, ChainedDispatcher { * @param context The use context * * @return The item associated with the URL, or null if no such item exists + * @throws javax.servlet.ServletException */ protected ContentItem getContentItem(ContentSection section, String url, String context) throws ServletException { - ItemResolver itemResolver = CMSDispatcher.getItemResolver(section); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentSectionManager sectionManager = cdiUtil.findBean(ContentSectionManager.class); + final ItemResolver itemResolver = sectionManager.getItemResolver(section); - ContentItem item = null; - item = itemResolver.getItem(section, url, context); - - return item; + return itemResolver.getItem(section, url, context); } /** @@ -584,21 +587,16 @@ public class CMSDispatcher implements Dispatcher, ChainedDispatcher { * @return The ItemResolver associated with the content section */ public static ItemResolver getItemResolver(ContentSection section) { - String name = section.getLabel(); - ItemResolver itemResolver = (ItemResolver) s_itemResolverCache.get(name); - if (itemResolver == null) { - final String itemResolverClassName = section.getItemResolverClass(); - try { - itemResolver = (ItemResolver) Class.forName( - itemResolverClassName).newInstance(); - } catch (ClassNotFoundException | - IllegalAccessException | - InstantiationException ex) { - throw new RuntimeException(ex); - } - s_itemResolverCache.put(name, itemResolver); + + final Class> clazz; + try { + clazz = Class.forName(section.getItemResolverClass()); + } catch(ClassNotFoundException ex) { + throw new UncheckedWrapperException(ex); } - return itemResolver; + + return (ItemResolver) CdiUtil.createCdiUtil().findBean(clazz); + } /** diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ContentPanel.java b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ContentPanel.java index 3704fd3ed..920538f65 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ContentPanel.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ContentPanel.java @@ -28,6 +28,7 @@ import com.arsdigita.xml.Element; import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSectionServlet; +import org.librecms.dispatcher.ItemResolver; import java.util.logging.Level; import java.util.logging.Logger; @@ -116,7 +117,7 @@ public class ContentPanel extends SimpleComponent { ContentSectionServlet.PREVIEW); } pathInfo.newChildElement("cms:templatePrefix", CMS.CMS_XML_NS).setText( - "/" + AbstractItemResolver.TEMPLATE_CONTEXT_PREFIX); + "/" + ItemResolver.TEMPLATE_CONTEXT_PREFIX); if (CMS.getContext().hasContentItem()) { ContentItem item = CMS.getContext().getContentItem(); diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ItemDispatcher.java b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ItemDispatcher.java index 5b7959e3b..23eec1e50 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ItemDispatcher.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ItemDispatcher.java @@ -21,6 +21,7 @@ package com.arsdigita.cms.dispatcher; import com.arsdigita.dispatcher.ChainedDispatcher; import com.arsdigita.dispatcher.DispatcherHelper; import com.arsdigita.dispatcher.RequestContext; +import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.web.LoginSignal; import java.io.IOException; @@ -38,8 +39,10 @@ import org.libreccm.security.PermissionChecker; import org.libreccm.security.Shiro; import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.ContentSectionManager; import org.librecms.contentsection.ContentSectionServlet; import org.librecms.contentsection.privileges.ItemPrivileges; +import org.librecms.dispatcher.ItemResolver; /** * Dispatches to the JSP or Servlet for rendering a content item. @@ -167,9 +170,7 @@ public class ItemDispatcher implements ChainedDispatcher { // This part assumes the template is JSP. // final String templateURL = getTemplateURL(section, item, request, // actx); - // s_log.debug("TEMPLATE " + templateURL); - DispatcherHelper.setRequestContext(request, actx); DispatcherHelper.forwardRequestByPath(null, request, response); @@ -235,7 +236,7 @@ public class ItemDispatcher implements ChainedDispatcher { } /** - * Fetches the ItemResolver for a content section. Checks cache first. + * Fetches the ItemResolver for a content section. * * @param section The content section * @@ -243,22 +244,11 @@ public class ItemDispatcher implements ChainedDispatcher { */ public ItemResolver getItemResolver(ContentSection section) { - String name = section.getLabel(); - ItemResolver ir = (ItemResolver) s_itemResolverCache.get(name); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentSectionManager sectionManager = cdiUtil.findBean( + ContentSectionManager.class); - if (ir == null) { - try { - ir = (ItemResolver) Class - .forName(section.getItemResolverClass()).newInstance(); - s_itemResolverCache.put(name, ir); - } catch (ClassNotFoundException | - IllegalAccessException | - InstantiationException ex) { - throw new RuntimeException(ex); - } - } - - return ir; + return sectionManager.getItemResolver(section); } /** @@ -281,7 +271,6 @@ public class ItemDispatcher implements ChainedDispatcher { // // return ir; // } - /** * Fetches the URL of a template for an item. The returned URL is relative * to the webapp context. @@ -297,5 +286,4 @@ public class ItemDispatcher implements ChainedDispatcher { // // return templateURL; // } - } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ItemResolver.java b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ItemResolver.java deleted file mode 100755 index 2c77b5a8a..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ItemResolver.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.dispatcher; - -import com.arsdigita.bebop.PageState; - -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentSection; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; - - -/** - *
- * The ItemResolver is responsible for mapping a URL in a particular - * content section to a content item.
- * - *- * As an example, here is the item resolution process for a request to - * http://yourserver/cms/cheese:
- * - *- * The item resolver would be asked to map the URL stub /cheese - * in the content section mounted at /cms to a content item. To this - * end, the dispatcher calls the getItem method, passing in the - * {@link com.arsdigita.cms.ContentSection} and the URL stub for the item within - * the section, /cheese in our example. As a final argument, the - * dispatcher passes either ContentItem.DRAFT or - * ContentItem.LIVE to the ItemResolver, depending on whether - * the returned item should be the live version (for public pages) or the draft - * version (for previewing).
- * - * @author Michael Pih (pihman@arsdigita.com) - * @author Stanislav Freidin (sfreidin@arsdigita.com) - * @version $Revision$ $DateTime: 2004/08/17 23:15:09 $ - * @version $Id$ - */ -public interface ItemResolver { - - /** - * Return a content item based on section, url, and use context. - * - * @param section The current content section - * @param url The section-relative URL - * @param context The use context - * @return The content item, or null if no such item exists - */ - public ContentItem getItem(ContentSection section, - String url, - String context); - - /** - * Fetches the current context based on the page state. - * - * @param state the current page state - * @return the context of the current URL, such as "live" or "admin" - */ - public String getCurrentContext(PageState state); - - /** - * Generates a URL for a content item. - * - * @param itemId The item ID - * @param name The name of the content page - * @param state The page state - * @param section the content section to which the item belongs - * @param context the context of the URL, such as "live" or "admin" - * @return The URL of the item - * @see #getCurrentContext - */ - public String generateItemURL(PageState state, - Long itemId, - String name, - ContentSection section, - String context); - - /** - * Generates a URL for a content item. - * - * @param itemId The item ID - * @param name The name of the content page - * @param state The page state - * @param section the content section to which the item belongs - * @param context the context of the URL, such as "live" or "admin" - * @param templateContext the context for the URL, such as "public" - * @return The URL of the item - * @see #getCurrentContext - */ - public String generateItemURL(PageState state, - Long itemId, - String name, - ContentSection section, - String context, - String templateContext - ); - - /** - * Generates a URL for a content item. - * - * @param item The item - * @param state The page state - * @param section the content section to which the item belongs - * @param context the context of the URL, such as "live" or "admin" - * @return The URL of the item - * @see #getCurrentContext - */ - public String generateItemURL(PageState state, - ContentItem item, - ContentSection section, - String context); - - /** - * Generates a URL for a content item. - * - * @param item The item - * @param state The page state - * @param section the content section to which the item belongs - * @param context the context of the URL, such as "live" or "admin" - * @param templateContext the context for the URL, such as "public" - * @return The URL of the item - * @see #getCurrentContext - */ - public String generateItemURL(PageState state, - ContentItem item, - ContentSection section, - String context, - String templateContext); - - /** - * Return a master page based on page state (and content section). - * - * @param item The content item - * @param request The HTTP request - * @return The master page - */ - public CMSPage getMasterPage(ContentItem item, HttpServletRequest request) - throws ServletException; - - - /* - * Having to stick the following methods, getTemplateFromURL, and - * stripTemplateFromURL in the ItemResolver interface is somewhat ugly. - * But, the relationship between ItemResolver and TemplateResolver needs - * to be cleaned up to fix this. As it is, ItemResolver parses URL's for - * template contexts, and TemplateResolver sets the actual template contexts - * in the request. - */ - /** - * Finds the template context from the URL and returns it, if it is there. - * Otherwise, returns null. - * - * @param inUrl the URL from which to get the template context - * @return the template context, or null if there is no template context - */ - public String getTemplateFromURL(String inUrl); - - /** - * Removes the template context from theinUrl.
- *
- * @param inUrl URL, possibly including the template context.
- * @return inUrl with the template context removed
- */
- public String stripTemplateFromURL(String inUrl);
-
-}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java
index 5755de924..5229877fd 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java
@@ -43,7 +43,6 @@ import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.PageLocations;
import com.arsdigita.cms.dispatcher.CMSDispatcher;
import com.arsdigita.cms.dispatcher.CMSPage;
-import com.arsdigita.cms.dispatcher.ItemResolver;
import com.arsdigita.cms.ui.authoring.WizardSelector;
import com.arsdigita.cms.ui.item.ContentItemRequestLocal;
import com.arsdigita.cms.ui.item.CustomizedPreviewLink;
@@ -70,7 +69,9 @@ import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.ContentItemVersion;
import org.librecms.contentsection.ContentSection;
+import org.librecms.contentsection.ContentSectionManager;
import org.librecms.contentsection.ContentType;
+import org.librecms.dispatcher.ItemResolver;
import java.io.IOException;
import java.util.Optional;
@@ -93,7 +94,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
* Private Logger instance for debugging purpose.
*/
private static final Logger LOGGER = LogManager.getLogger(
- ContentItemPage.class);
+ ContentItemPage.class);
/**
* The URL parameter that must be passed in in order to set the current tab.
* This is a KLUDGE right now because the TabbedDialog's current tab is
@@ -164,6 +165,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
protected final Object initialValue(final PageState state) {
return CMS.getContext().getContentItem();
}
+
}
private class TitlePrinter implements PrintListener {
@@ -172,10 +174,11 @@ public class ContentItemPage extends CMSPage implements ActionListener {
public final void prepare(final PrintEvent event) {
final Label label = (Label) event.getTarget();
final ContentItem item = itemRequestLocal.getContentItem(event.
- getPageState());
+ getPageState());
label.setLabel(item.getDisplayName());
}
+
}
/**
@@ -197,12 +200,12 @@ public class ContentItemPage extends CMSPage implements ActionListener {
// Add the selected item language as parameter
final StringParameter selectedLanguage = new StringParameter(
- SELECTED_LANGUAGE);
+ SELECTED_LANGUAGE);
selectedLanguage.addParameterListener(new NotNullValidationListener(
- SELECTED_LANGUAGE));
+ SELECTED_LANGUAGE));
addGlobalStateParam(selectedLanguage);
selectedLanguageModel = new ParameterSingleSelectionModel<>(
- selectedLanguage);
+ selectedLanguage);
// Add the content type global state parameter
final LongParameter contentType = new LongParameter(CONTENT_TYPE);
@@ -210,7 +213,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
// Add the streamlined creation global state parameter
final StringParameter streamlinedCreation = new StringParameter(
- STREAMLINED_CREATION);
+ STREAMLINED_CREATION);
addGlobalStateParam(streamlinedCreation);
typeModel = new ACSObjectSelectionModel(ContentType.class.getName(),
@@ -219,7 +222,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
// Validate the item ID parameter (caches the validation).
getStateModel().addValidationListener(
- event -> validateItemID(event.getPageState()));
+ event -> validateItemID(event.getPageState()));
// Add the return url global state parameter
returnUrlParameter = new StringParameter(RETURN_URL);
@@ -248,7 +251,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
tabbedPane.addTab(new Label(gz("cms.ui.item.summary")), summaryPane);
tabbedPane.
- addTab(new Label(gz("cms.ui.item.authoring")), wizardPane);
+ addTab(new Label(gz("cms.ui.item.authoring")), wizardPane);
tabbedPane.addTab(new Label(gz("cms.ui.item.languages")),
languagesPane);
tabbedPane.addTab(new Label(gz("cms.ui.item.workflow")),
@@ -261,6 +264,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
templatesPane);
tabbedPane.addActionListener(new ActionListener() {
+
@Override
public final void actionPerformed(final ActionEvent event) {
@@ -271,19 +275,23 @@ public class ContentItemPage extends CMSPage implements ActionListener {
((Resettable) pane).reset(state);
}
}
+
});
// Build the preview link.
m_previewLink = new Link(new Label(gz("cms.ui.preview")),
new PrintListener() {
- @Override
- public final void prepare(final PrintEvent event) {
- final Link link = (Link) event.getTarget();
- link.setTarget(getPreviewURL(event.
+
+ @Override
+ public final void prepare(
+ final PrintEvent event) {
+ final Link link = (Link) event.getTarget();
+ link.setTarget(getPreviewURL(event.
getPageState()));
- link.setTargetFrame(Link.NEW_FRAME);
- }
- });
+ link.setTargetFrame(Link.NEW_FRAME);
+ }
+
+ });
m_previewLink.setIdAttr("preview_link");
add(m_previewLink);
@@ -294,21 +302,22 @@ public class ContentItemPage extends CMSPage implements ActionListener {
@Override
public void validate(final FormSectionEvent event)
- throws FormProcessException {
+ throws FormProcessException {
PageState s = event.getPageState();
FormData data = event.getFormData();
final ContentItem item = itemRequestLocal.getContentItem(s);
if (item != null
- && ContentItemVersion.LIVE == item.getVersion()) {
+ && ContentItemVersion.LIVE == item.getVersion()) {
LOGGER.error(String.format(
- "The item %d is live and cannot be edited.", item.
- getObjectId()));
+ "The item %d is live and cannot be edited.", item.
+ getObjectId()));
throw new FormProcessException(new GlobalizedMessage(
- "cms.ui.live_item_not_editable",
- CmsConstants.CMS_BUNDLE));
+ "cms.ui.live_item_not_editable",
+ CmsConstants.CMS_BUNDLE));
}
}
+
});
}
@@ -317,16 +326,17 @@ public class ContentItemPage extends CMSPage implements ActionListener {
* com.arsdigita.cms.ContentItem}.
*
* @param state The page state
+ *
* @pre state != null
* @exception FormProcessException if the item_id is not valid
*/
protected void validateItemID(final PageState state) throws
- FormProcessException {
+ FormProcessException {
final ContentItem item = itemRequestLocal.getContentItem(state);
if (item == null) {
throw new FormProcessException(new GlobalizedMessage(
- "cms.ui.invalid_item_id", CmsConstants.CMS_BUNDLE));
+ "cms.ui.invalid_item_id", CmsConstants.CMS_BUNDLE));
}
}
@@ -336,6 +346,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
* @deprecated use com.arsdigita.cms.CMS.getContext().getContentSection()
* instead
* @param request The HTTP request
+ *
* @return The current content section
*/
@Override
@@ -352,6 +363,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
*
* @deprecated Use the ItemSelectionModel
* @param state The page state
+ *
* @return The current content item, null if there is none
*/
@Override
@@ -361,6 +373,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
/**
* Set the current tab, if necessary
+ *
* @param event
*/
@Override
@@ -406,8 +419,9 @@ public class ContentItemPage extends CMSPage implements ActionListener {
* Construct a URL for displaying a certain item
*
* @param nodeURL The URL where this page is mounted
- * @param itemId The id of the item to display
- * @param tab The index of the tab to display
+ * @param itemId The id of the item to display
+ * @param tab The index of the tab to display
+ *
* @return
*/
public static String getItemURL(final String nodeURL,
@@ -419,10 +433,11 @@ public class ContentItemPage extends CMSPage implements ActionListener {
/**
* Construct a URL for displaying a certain item
*
- * @param nodeURL The URL where this page is mounted
- * @param itemId The id of the item to display
- * @param tab The index of the tab to display
+ * @param nodeURL The URL where this page is mounted
+ * @param itemId The id of the item to display
+ * @param tab The index of the tab to display
* @param streamlinedCreation Whether to activate Streamlined item authoring
+ *
* @return
*/
public static String getItemURL(final String nodeURL,
@@ -432,25 +447,25 @@ public class ContentItemPage extends CMSPage implements ActionListener {
final StringBuilder urlBuilder = new StringBuilder();
urlBuilder
- .append(nodeURL)
- .append(PageLocations.ITEM_PAGE)
- .append("?")
- .append(ITEM_ID)
- .append("=")
- .append(itemId.toString())
- .append("&")
- .append(SET_TAB)
- .append("=")
- .append(tab);
+ .append(nodeURL)
+ .append(PageLocations.ITEM_PAGE)
+ .append("?")
+ .append(ITEM_ID)
+ .append("=")
+ .append(itemId.toString())
+ .append("&")
+ .append(SET_TAB)
+ .append("=")
+ .append(tab);
if (streamlinedCreation
- && CMSConfig.getConfig().isUseStreamlinedCreation()) {
+ && CMSConfig.getConfig().isUseStreamlinedCreation()) {
urlBuilder
- .append("&")
- .append(STREAMLINED_CREATION)
- .append("=")
- .append(STREAMLINED_CREATION_ACTIVE);
+ .append("&")
+ .append(STREAMLINED_CREATION)
+ .append("=")
+ .append(STREAMLINED_CREATION_ACTIVE);
}
return urlBuilder.toString();
@@ -459,21 +474,23 @@ public class ContentItemPage extends CMSPage implements ActionListener {
/**
* @param itemId
* @param tab
+ *
* @return
+ *
* @deprecated Use getItemURL instead
*/
public static String getRelativeItemURL(final Long itemId, final int tab) {
final StringBuilder url = new StringBuilder();
url
- .append(PageLocations.ITEM_PAGE)
- .append("?")
- .append(ITEM_ID)
- .append("=")
- .append(itemId.toString())
- .append("&")
- .append(SET_TAB)
- .append("=")
- .append(tab);
+ .append(PageLocations.ITEM_PAGE)
+ .append("?")
+ .append(ITEM_ID)
+ .append("=")
+ .append(itemId.toString())
+ .append("&")
+ .append(SET_TAB)
+ .append("=")
+ .append(tab);
return url.toString();
}
@@ -482,7 +499,8 @@ public class ContentItemPage extends CMSPage implements ActionListener {
* Constructs a URL for displaying a certain item.
*
* @param item the ContentItem object to display
- * @param tab The index of the tab to display
+ * @param tab The index of the tab to display
+ *
* @return
*/
public static String getItemURL(final ContentItem item,
@@ -502,14 +520,15 @@ public class ContentItemPage extends CMSPage implements ActionListener {
* Constructs a URL for displaying a certain item.
*
* @param itemId the id of the ContentItem object to display
- * @param tab The index of the tab to display
+ * @param tab The index of the tab to display
+ *
* @return
*/
public static String getItemURL(final long itemId,
final int tab) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentItemRepository itemRepo = cdiUtil.findBean(
- ContentItemRepository.class);
+ ContentItemRepository.class);
final OptionalinUrl.
+ *
+ * @param inUrl URL, possibly including the template context.
+ *
+ * @return inUrl with the template context removed
+ */
+ default String stripTemplateFromURL(final String inUrl) {
+ final String sTemplateContext = getTemplateFromURL(inUrl);
+
+ if (sTemplateContext != null) {
+ //there is a template context, so strip it
+ final int iTemplateLength = TEMPLATE_CONTEXT_PREFIX.length()
+ + sTemplateContext.length() + 1;
+ return inUrl.substring(iTemplateLength, inUrl.length());
+ } else {
+ return inUrl;
+ }
+ }
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/MultilingualItemResolver.java b/ccm-cms/src/main/java/org/librecms/dispatcher/MultilingualItemResolver.java
old mode 100755
new mode 100644
similarity index 84%
rename from ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/MultilingualItemResolver.java
rename to ccm-cms/src/main/java/org/librecms/dispatcher/MultilingualItemResolver.java
index ea70c4b2d..bac2fb103
--- a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/MultilingualItemResolver.java
+++ b/ccm-cms/src/main/java/org/librecms/dispatcher/MultilingualItemResolver.java
@@ -1,64 +1,70 @@
/*
- * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
+ * Copyright (C) 2017 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.
+ * 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
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
*/
-package com.arsdigita.cms.dispatcher;
+package org.librecms.dispatcher;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.CMS;
+import com.arsdigita.cms.dispatcher.CMSDispatcher;
+import com.arsdigita.cms.dispatcher.CMSPage;
+import com.arsdigita.cms.dispatcher.MasterPage;
import com.arsdigita.cms.ui.ContentItemPage;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.util.Assert;
-import org.apache.logging.log4j.Logger;
-import org.librecms.contentsection.ContentItem;
-import org.librecms.contentsection.ContentSection;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Objects;
-import java.util.StringTokenizer;
-
import org.apache.logging.log4j.LogManager;
-import org.libreccm.cdi.utils.CdiUtil;
+import org.apache.logging.log4j.Logger;
import org.libreccm.core.CcmObject;
-import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.CmsConstants;
+import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemManager;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.ContentItemVersion;
+import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.Folder;
import org.librecms.contentsection.FolderManager;
-import org.librecms.util.LanguageUtil;
+import org.librecms.contentsection.FolderRepository;
-import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
+import java.util.Objects;
import java.util.Optional;
+import java.util.StringTokenizer;
-import static javax.naming.ldap.SortControl.*;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.transaction.Transactional;
/**
* Resolves items to URLs and URLs to items for multiple language variants.
*
+ * For version 7.0.0 this call has been moved from the
+ * {@code com.arsdigita.cms.dispatcher} package to the
+ * {@code org.librecms.dispatcher} package and refactored to an CDI bean. This
+ * was necessary to avoid several problems when accessing the entity beans for
+ * {@link Category} and {@link ContentItem}, primarily the infamous
+ * {@code LazyInitializationException}. Also several checks for null parameters
+ * were added to avoid {@code NullPointerExcpetions}.
+ *
*
* AS of version 7.0.0 this class not longer part of the public API. It is left
* here to keep the changes to the UI classes as minimal as possible. For new
@@ -73,13 +79,12 @@ import static javax.naming.ldap.SortControl.*;
* @author Michael Hanisch
* @author Jens Pelzetter
*/
-public class MultilingualItemResolver
- extends AbstractItemResolver implements ItemResolver {
+@RequestScoped
+public class MultilingualItemResolver implements ItemResolver {
private static final Logger LOGGER = LogManager.getLogger(
MultilingualItemResolver.class);
- private static MasterPage s_masterP = null;
private static final String ADMIN_PREFIX = "admin";
/**
@@ -92,9 +97,17 @@ public class MultilingualItemResolver
*/
protected static final String SEPARATOR = "&";
- public MultilingualItemResolver() {
- LOGGER.debug("Undergoing creation");
- }
+ @Inject
+ private FolderRepository folderRepo;
+
+ @Inject
+ private FolderManager folderManager;
+
+ @Inject
+ private ContentItemRepository itemRepo;
+
+ @Inject
+ private ContentItemManager itemManager;
/**
* Returns a content item based on section, url, and use context.
@@ -108,25 +121,32 @@ public class MultilingualItemResolver
*
* @return The content item, or null if no such item exists
*/
+ @Transactional(Transactional.TxType.REQUIRED)
@Override
public ContentItem getItem(final ContentSection section,
final String itemUrl,
final String context) {
+ if (section == null) {
+ throw new IllegalArgumentException(
+ "Can't get item from section null.");
+ }
+ if (itemUrl == null) {
+ throw new IllegalArgumentException("Can't get item for URL null.");
+ }
+ if (context == null) {
+ throw new IllegalArgumentException(
+ "Can't get item for context null.");
+ }
+
LOGGER.debug("Resolving the item in content section \"{}\" at URL "
+ "\"{}\" for context \"{}\"...",
section.getLabel(),
itemUrl,
context);
- Assert.exists(section, "ContentSection section");
- Assert.exists(itemUrl, "String url");
- Assert.exists(context, "String context");
-
final Folder rootFolder = section.getRootDocumentsFolder();
String url = stripTemplateFromURL(itemUrl);
- final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
-
if (rootFolder == null) {
// nothing to do, if root folder is null
LOGGER.debug("The root folder is null; returning no item");
@@ -139,8 +159,6 @@ public class MultilingualItemResolver
LOGGER.debug("The root folder has a live version; recursing");
- final FolderManager folderManager = cdiUtil.findBean(
- FolderManager.class);
final String prefix = String.join(
"",
section.getPrimaryUrl(),
@@ -229,6 +247,7 @@ public class MultilingualItemResolver
*
* ToDo: Refactor to use the {@link ContentItemVersion} directly.
*/
+ @Transactional(Transactional.TxType.REQUIRED)
@Override
public String getCurrentContext(final PageState state) {
LOGGER.debug("Getting the current context");
@@ -276,6 +295,7 @@ public class MultilingualItemResolver
*
* @see #getCurrentContext
*/
+ @Transactional(Transactional.TxType.REQUIRED)
@Override
public String generateItemURL(final PageState state,
final Long itemId,
@@ -299,6 +319,7 @@ public class MultilingualItemResolver
*
* @see #getCurrentContext
*/
+ @Transactional(Transactional.TxType.REQUIRED)
@Override
public String generateItemURL(final PageState state,
final Long itemId,
@@ -306,20 +327,25 @@ public class MultilingualItemResolver
final ContentSection section,
final String context,
final String templateContext) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Generating an item URL for item id " + itemId
- + ", section " + section + ", and context '"
- + context
- + "' with name '" + name + "'");
+ if (itemId == null) {
+ throw new IllegalArgumentException(
+ "Can't generate item URL for item id null.");
+ }
+ if (context == null) {
+ throw new IllegalArgumentException(
+ "Can't generate item URL for context null.");
+ }
+ if (section == null) {
+ throw new IllegalArgumentException(
+ "Can't generate item URL for section null.");
}
- Assert.exists(itemId, "BigDecimal itemId");
- Assert.exists(context, "String context");
- Assert.exists(section, "ContentSection section");
-
- final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
- final ContentItemRepository itemRepo = cdiUtil.findBean(
- ContentItemRepository.class);
+ LOGGER.debug("Generating an item URL for item id {}, section \"{}\" "
+ + "and context \"{}\" with name \"{}\"...",
+ itemId,
+ section.getLabel(),
+ context,
+ name);
if (ContentItemVersion.DRAFT.toString().equals(context)) {
// No template context here.
@@ -349,6 +375,7 @@ public class MultilingualItemResolver
*
* @see #getCurrentContext
*/
+ @Transactional(Transactional.TxType.REQUIRED)
@Override
public String generateItemURL(final PageState state,
final ContentItem item,
@@ -370,16 +397,20 @@ public class MultilingualItemResolver
*
* @see #getCurrentContext
*/
+ @Transactional(Transactional.TxType.REQUIRED)
@Override
public String generateItemURL(final PageState state,
final ContentItem item,
final ContentSection section,
final String context,
final String templateContext) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Generating an item URL for item " + item
- + ", section "
- + section + ", and context " + context);
+ if (item == null) {
+ throw new IllegalArgumentException(
+ "Can't generate URL for item null.");
+ }
+ if (context == null) {
+ throw new IllegalArgumentException(
+ "Can't generate URL for context null.");
}
final ContentSection contentSection;
@@ -389,6 +420,12 @@ public class MultilingualItemResolver
contentSection = section;
}
+ LOGGER.debug("Generating an item URL for item \"{}\", section \"{}\" "
+ + "and context \"{}\".",
+ item.getDisplayName(),
+ contentSection.getLabel(),
+ context);
+
if (ContentItemVersion.DRAFT.toString().equals(context)) {
return generateDraftURL(section, item.getObjectId());
} else if (CMSDispatcher.PREVIEW.equals(context)) {
@@ -401,35 +438,19 @@ public class MultilingualItemResolver
}
}
- /**
- * Returns a master page based on page state (and content section).
- *
- * @param item The content item
- * @param request The HTTP request
- *
- * @return The master page
- *
- * @throws javax.servlet.ServletException
- */
+ @Transactional(Transactional.TxType.REQUIRED)
@Override
public CMSPage getMasterPage(final ContentItem item,
final HttpServletRequest request)
throws ServletException {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Getting the master page for item " + item);
- }
- // taken from SimpleItemResolver
- if (s_masterP == null) {
- s_masterP = new MasterPage();
- s_masterP.init();
- }
+ LOGGER.debug("Getting the master page for item {}",
+ item.getDisplayName());
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Returning master page " + s_masterP);
- }
+ final MasterPage masterPage = new MasterPage();
+ masterPage.init();
- return s_masterP;
+ return masterPage;
}
/**
@@ -512,9 +533,6 @@ public class MultilingualItemResolver
.append("/");
}
- final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
- final ContentItemManager itemManager = cdiUtil.findBean(
- ContentItemManager.class);
url.append(itemManager.getItemPath(item));
return url.toString();
@@ -561,9 +579,6 @@ public class MultilingualItemResolver
.append("/");
}
- final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
- final ContentItemManager itemManager = cdiUtil.findBean(
- ContentItemManager.class);
url.append(itemManager.getItemPath(item));
return url.toString();
@@ -581,19 +596,10 @@ public class MultilingualItemResolver
* url
*/
protected ContentItem getItemFromDraftURL(final String url) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Looking up the item from draft URL " + url);
- }
+ LOGGER.debug("Looking up the item from draft URL ", url);
int pos = url.indexOf(ITEM_ID);
- // XXX this is wrong: here we abort on not finding the
- // parameter; below we return null.
- if (Assert.isEnabled()) {
- Assert.isTrue(pos >= 0,
- "Draft URL must contain parameter " + ITEM_ID);
- }
-
String item_id = url.substring(pos); // item_id == ITEM_ID=.... ?
pos = item_id.indexOf("="); // should be exactly after the ITEM_ID string
@@ -612,13 +618,7 @@ public class MultilingualItemResolver
int i = item_id.indexOf(SEPARATOR);
item_id = item_id.substring(pos, Math.min(i, item_id.length() - 1));
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Looking up item using item ID " + item_id);
- }
-
- final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
- final ContentItemRepository itemRepo = cdiUtil.findBean(
- ContentItemRepository.class);
+ LOGGER.debug("Looking up item using item ID {}", item_id);
final Optional