Author: apevec Date: 2005-09-22 04:44:04 +0200 (Thu, 22 Sep 2005) New Revision: 895 Added: trunk/ccm-core/src/com/arsdigita/dispatcher/PortletTypeXSLServlet.java Modified: trunk/ccm-core/src/com/arsdigita/portal/PortletType.java trunk/ccm-ldn-aplaws/bundles/camden/cfg/web.xml trunk/ccm-ldn-aplaws/bundles/complete/cfg/web.xml Log: SF patch [ 1181342 ] Allow portlets to be packaged up as applications Added: trunk/ccm-core/src/com/arsdigita/dispatcher/PortletTypeXSLServlet.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/dispatcher/PortletTypeXSLServlet.java 2005-09-22 01:46:23 UTC (rev 894) +++ trunk/ccm-core/src/com/arsdigita/dispatcher/PortletTypeXSLServlet.java 2005-09-22 02:44:04 UTC (rev 895) @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. + * + * The contents of this file are subject to the CCM Public + * License (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the + * License at http://www.redhat.com/licenses/ccmpl.html. + * + * Software distributed under the License is distributed on an + * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express + * or implied. See the License for the specific language + * governing rights and limitations under the License. + * + */ +package com.arsdigita.dispatcher; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Iterator; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.arsdigita.portal.PortletType; +import com.arsdigita.templating.Templating; +import com.arsdigita.util.IO; +import com.arsdigita.web.BaseServlet; + + +/** + * A servlet that multiplexes all XSL files registered + * against portlet types into one. + * + * Copied from ccm-cms/com.arsdigita.cms.dispatcher.ContentTypeXSLServlet + */ +public class PortletTypeXSLServlet extends BaseServlet { + + private static final Logger s_log = + Logger.getLogger(PortletTypeXSLServlet.class); + + protected void doService(HttpServletRequest sreq, + HttpServletResponse sresp) + throws ServletException, IOException { + s_log.debug("Servicing request for portlet type xsl imports"); + String path = sreq.getPathInfo(); + if (!path.equals("/index.xsl")) { + s_log.error("Only index.xsl is supported " + path); + sresp.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + Iterator paths = PortletType.getXSLFileURLs(); + InputStream is = Templating.multiplexXSLFiles(paths); + + sresp.setContentType("text/xml; charset=UTF-8"); + IO.copy(is, sresp.getOutputStream()); + } + +} Modified: trunk/ccm-core/src/com/arsdigita/portal/PortletType.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/portal/PortletType.java 2005-09-22 01:46:23 UTC (rev 894) +++ trunk/ccm-core/src/com/arsdigita/portal/PortletType.java 2005-09-22 02:44:04 UTC (rev 895) @@ -18,17 +18,26 @@ */ package com.arsdigita.portal; +import java.math.BigDecimal; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.apache.log4j.Logger; + +import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.kernel.PackageType; import com.arsdigita.kernel.ResourceType; -import com.arsdigita.web.ApplicationType; -import com.arsdigita.kernel.PackageType; -import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; import com.arsdigita.persistence.SessionManager; import com.arsdigita.util.Assert; -import org.apache.log4j.Logger; -import java.math.BigDecimal; +import com.arsdigita.util.UncheckedWrapperException; +import com.arsdigita.web.ApplicationType; +import com.arsdigita.web.Web; /** @@ -215,4 +224,104 @@ set("profile", profile); } + // SF patch [ 1181342 ] Allow portlets to be packaged up as applications + private static Set s_xsl = new HashSet(); + + /** + * + * NB - Based on ccm-cms/com.arsdigita.cms.ContentType + * interface is liable to change. + * + * Registers an XSL file against a portlet type. + * @param portletType the portlet's base data object type + * @param path the path relative to the server root + */ + public static void registerXSLFile(String portletType, String path) { + s_cat.debug("registering xsl file " + path + " to portlet type " + + portletType); + + s_xsl.add(new XSLEntry(portletType, path)); + } + + /** + * NB this interface is liable to change. + * + * Unregisters an XSL file against a content type. + * @param type the content type + * @param path the path relative to the server root + */ + public static void unregisterXSLFile(String portletType, String path) { + s_xsl.remove(new XSLEntry(portletType, path)); + } + + /** + * Gets an iterator of java.net.URL objects for + * all registered XSL files + */ + public static Iterator getXSLFileURLs() { + s_cat.debug("getXSLFileURLs - returningan iterator over " + + s_xsl.size() + " entries"); + return new EntryIterator(s_xsl.iterator()); + } + + private static class EntryIterator implements Iterator { + private Iterator m_inner; + + public EntryIterator(Iterator inner) { + m_inner = inner; + } + + public boolean hasNext() { + return m_inner.hasNext(); + } + + public Object next() { + XSLEntry entry = (XSLEntry) m_inner.next(); + String path = entry.getPath(); + + try { + return new URL(Web.getConfig().getDefaultScheme(), Web + .getConfig().getHost().getName(), Web.getConfig() + .getHost().getPort(), path); + } catch (MalformedURLException ex) { + throw new UncheckedWrapperException("path malformed" + path, ex); + } + } + + public void remove() { + m_inner.remove(); + } + } + + private static class XSLEntry { + private String m_type; + + private String m_path; + + public XSLEntry(String portletType, String path) { + m_type = portletType; + m_path = path; + } + + public PortletType getType() { + return PortletType.retrievePortletTypeForPortlet(m_type); + } + + public String getPath() { + return m_path; + } + + public boolean equals(Object o) { + if (!(o instanceof XSLEntry)) { + return false; + } + XSLEntry e = (XSLEntry) o; + return m_path.equals(e.m_path) && m_type.equals(e.m_type); + } + + public int hashCode() { + return m_path.hashCode() + m_type.hashCode(); + } + } + } Modified: trunk/ccm-ldn-aplaws/bundles/camden/cfg/web.xml =================================================================== --- trunk/ccm-ldn-aplaws/bundles/camden/cfg/web.xml 2005-09-22 01:46:23 UTC (rev 894) +++ trunk/ccm-ldn-aplaws/bundles/camden/cfg/web.xml 2005-09-22 02:44:04 UTC (rev 895) @@ -182,7 +182,17 @@ </init-param> </servlet> + <servlet> + <servlet-name>portlet-type-xsl</servlet-name> + <servlet-class>com.arsdigita.dispatcher.PortletTypeXSLServlet</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>portlet-type-xsl</servlet-name> + <url-pattern>/__ccm__/servlet/portlet-type/*</url-pattern> + </servlet-mapping> + + <servlet-mapping> <servlet-name>reg</servlet-name> <url-pattern>/__ccm__/null/reg/*</url-pattern> </servlet-mapping> Modified: trunk/ccm-ldn-aplaws/bundles/complete/cfg/web.xml =================================================================== --- trunk/ccm-ldn-aplaws/bundles/complete/cfg/web.xml 2005-09-22 01:46:23 UTC (rev 894) +++ trunk/ccm-ldn-aplaws/bundles/complete/cfg/web.xml 2005-09-22 02:44:04 UTC (rev 895) @@ -182,7 +182,17 @@ </init-param> </servlet> + <servlet> + <servlet-name>portlet-type-xsl</servlet-name> + <servlet-class>com.arsdigita.dispatcher.PortletTypeXSLServlet</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>portlet-type-xsl</servlet-name> + <url-pattern>/__ccm__/servlet/portlet-type/*</url-pattern> + </servlet-mapping> + + <servlet-mapping> <servlet-name>reg</servlet-name> <url-pattern>/__ccm__/null/reg/*</url-pattern> </servlet-mapping> |