diff --git a/ccm-cms-portletdataprovider/application.xml b/ccm-cms-portletdataprovider/application.xml index cd523a6db..7850cacaa 100644 --- a/ccm-cms-portletdataprovider/application.xml +++ b/ccm-cms-portletdataprovider/application.xml @@ -13,6 +13,8 @@ + + diff --git a/ccm-cms-portletdataprovider/pdl/com/arsdigita/cms/portletdataprovider/PortletDataProvider.pdl b/ccm-cms-portletdataprovider/pdl/com/arsdigita/cms/portletdataprovider/PortletDataProvider.pdl new file mode 100644 index 000000000..ea379888f --- /dev/null +++ b/ccm-cms-portletdataprovider/pdl/com/arsdigita/cms/portletdataprovider/PortletDataProvider.pdl @@ -0,0 +1,25 @@ +// +// Copyright (C) 2014 Jens Pelzetter +// +// 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 +// +// +model com.arsdigita.cms.portletdataprovider; + +import com.arsdigita.web.Application; + +object type PortletDataProvider extends Application { + reference key (cms_portletdataprovider.application_id); +} diff --git a/ccm-cms-portletdataprovider/sql/ccm-cms-portletdataprovider/oracle-se-create.sql b/ccm-cms-portletdataprovider/sql/ccm-cms-portletdataprovider/oracle-se-create.sql new file mode 100644 index 000000000..129c89678 --- /dev/null +++ b/ccm-cms-portletdataprovider/sql/ccm-cms-portletdataprovider/oracle-se-create.sql @@ -0,0 +1,3 @@ +@ ddl/oracle-se/create.sql + +@ ddl/oracle-se/deferred.sql \ No newline at end of file diff --git a/ccm-cms-portletdataprovider/sql/ccm-cms-portletdataprovider/postgres-create.sql b/ccm-cms-portletdataprovider/sql/ccm-cms-portletdataprovider/postgres-create.sql new file mode 100644 index 000000000..38716a0ca --- /dev/null +++ b/ccm-cms-portletdataprovider/sql/ccm-cms-portletdataprovider/postgres-create.sql @@ -0,0 +1,4 @@ +begin; +\i ddl/postgres/create.sql +\i ddl/postgres/deferred.sql +end; \ No newline at end of file diff --git a/ccm-cms-portletdataprovider/src/ccm-cms-portletdataprovider.load b/ccm-cms-portletdataprovider/src/ccm-cms-portletdataprovider.load index 356dff722..9ae4ac2b4 100644 --- a/ccm-cms-portletdataprovider/src/ccm-cms-portletdataprovider.load +++ b/ccm-cms-portletdataprovider/src/ccm-cms-portletdataprovider.load @@ -7,6 +7,11 @@ - - + + + + + + + \ No newline at end of file diff --git a/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/Initalizer.java b/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/Initializer.java similarity index 66% rename from ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/Initalizer.java rename to ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/Initializer.java index 7b35f05dd..4b8216654 100644 --- a/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/Initalizer.java +++ b/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/Initializer.java @@ -18,6 +18,10 @@ */package com.arsdigita.cms.portletdataprovider; import com.arsdigita.db.DbHelper; +import com.arsdigita.domain.DomainObject; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.kernel.ACSObjectInstantiator; +import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.pdl.ManifestSource; import com.arsdigita.persistence.pdl.NameFilter; import com.arsdigita.runtime.CompoundInitializer; @@ -30,20 +34,31 @@ import com.arsdigita.runtime.RuntimeConfig; * @author Jens Pelzetter * @version $Id$ */ -public class Initalizer extends CompoundInitializer { +public class Initializer extends CompoundInitializer { - public Initalizer() { + public Initializer(){ + super(); final String jdbcUrl = RuntimeConfig.getConfig().getJDBCURL(); final int database = DbHelper.getDatabaseFromURL(jdbcUrl); - add(new PDLInitializer(new ManifestSource("empty.pdl.mf", + add(new PDLInitializer(new ManifestSource("ccm-cms-portletdataprovider.pdl.mf", new NameFilter(DbHelper. - getDatabaseSuffix(database), "pdl")))); - } - + getDatabaseSuffix(database), "pdl")))); + } + @Override public void init(final DomainInitEvent event) { super.init(event); + + DomainObjectFactory.registerInstantiator( + PortletDataProvider.BASE_DATA_OBJECT_TYPE, + new ACSObjectInstantiator() { + @Override + public DomainObject doNewInstance(final DataObject dataObject) { + return new PortletDataProvider(dataObject); + } + + }); } - + } diff --git a/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/Loader.java b/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/Loader.java index 5d563c22b..ce4d418ac 100644 --- a/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/Loader.java +++ b/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/Loader.java @@ -18,8 +18,12 @@ */ package com.arsdigita.cms.portletdataprovider; +import com.arsdigita.kernel.Kernel; +import com.arsdigita.kernel.KernelExcursion; import com.arsdigita.loader.PackageLoader; import com.arsdigita.runtime.ScriptContext; +import com.arsdigita.web.Application; +import com.arsdigita.web.ApplicationType; /** * @@ -30,7 +34,24 @@ public class Loader extends PackageLoader { @Override public void run(final ScriptContext ctx) { - //Nothing to do. + new KernelExcursion() { + + @Override + protected void excurse() { + setEffectiveParty(Kernel.getSystemParty()); + + final ApplicationType type = new ApplicationType( + "PortletDataProvider", PortletDataProvider.BASE_DATA_OBJECT_TYPE); + type.setSingleton(true); + type.setDescription("DataProvider for JSR-286 portlets and other applications"); + + Application.createApplication(PortletDataProvider.BASE_DATA_OBJECT_TYPE, + "portletdataprovider", + "PortletDataProvider", + null); + } + + }.run(); } } diff --git a/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/PortletDataProvider.java b/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/PortletDataProvider.java new file mode 100644 index 000000000..31cfaac48 --- /dev/null +++ b/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/PortletDataProvider.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014 Jens Pelzetter + * + * 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.portletdataprovider; + +import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.persistence.DataObject; +import com.arsdigita.persistence.OID; +import com.arsdigita.web.Application; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class PortletDataProvider extends Application { + + public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.portletdataprovider.PortletDataProvider"; + + public PortletDataProvider(final DataObject dobj) { + super(dobj); + } + + public PortletDataProvider(final OID oid) throws DataObjectNotFoundException{ + super(oid); + } + + public PortletDataProvider(final BigDecimal key) throws DataObjectNotFoundException { + this(new OID(BASE_DATA_OBJECT_TYPE, key)); + } + + @Override + public String getServletPath() { + return "/portletdataprovider/"; + } + +} diff --git a/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/PortletDataProviderServlet.java b/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/PortletDataProviderServlet.java new file mode 100644 index 000000000..27c36c646 --- /dev/null +++ b/ccm-cms-portletdataprovider/src/com/arsdigita/cms/portletdataprovider/PortletDataProviderServlet.java @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2013 Jens Pelzetter, + * + * 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.portletdataprovider; + +import com.arsdigita.bebop.Page; +import com.arsdigita.bebop.PageFactory; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.SimpleComponent; +import com.arsdigita.cms.CMS; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.dispatcher.SimpleXMLGenerator; +import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.templating.PresentationManager; +import com.arsdigita.templating.Templating; +import com.arsdigita.web.Application; +import com.arsdigita.web.BaseApplicationServlet; +import com.arsdigita.xml.Document; +import com.arsdigita.xml.Element; +import java.io.IOException; +import java.math.BigDecimal; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class PortletDataProviderServlet extends BaseApplicationServlet { + + private static final long serialVersionUID = 60123844988240232L; + + private static final String ITEMS = "items"; + private static final String CATEGORIES = "categories"; + + @Override + protected void doService(final HttpServletRequest request, + final HttpServletResponse response, + final Application app) throws ServletException, IOException { + String path = request.getPathInfo(); + if (path.startsWith("/")) { + path = path.substring(1); + } + final String[] pathTokens = path.split("/"); + + if (pathTokens.length == 0) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + return; + } + + if (ITEMS.equals(pathTokens[0])) { + serveContentItem(pathTokens, request, response); + } else if (CATEGORIES.equals(pathTokens[0])) { + throw new UnsupportedOperationException("Not implemtend yet"); + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + protected void serveContentItem(final String[] pathTokens, + final HttpServletRequest request, + final HttpServletResponse response) throws IOException, + ServletException { + final String itemIdString = pathTokens[1]; + final BigDecimal itemId; + try { + itemId = new BigDecimal(itemIdString); + } catch (NumberFormatException ex) { + response.sendError(HttpServletResponse.SC_BAD_REQUEST, + String.format("'%s' is not a valid item id", itemIdString)); + return; + } + + ContentItem item = null; + try { + final ContentItem tmpItem = new ContentItem(itemId); + if (tmpItem.isLiveVersion()) { + item = tmpItem; + } else { + if (tmpItem.isLive()) { + item = tmpItem.getLiveVersion(); + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND, + String.format("Item with ID %d is not published.", + itemIdString)); + } + } + } catch (DataObjectNotFoundException ex) { + response.sendError(HttpServletResponse.SC_NOT_FOUND, + String.format("Item with ID %d not found.", itemIdString)); + return; + } + final Page page = PageFactory.buildPage( + "PortletDataProvider", + String.format("ContentItem %s", item.getOID().toString())); + final PortletDataItemPanel panel = new PortletDataItemPanel(item); + + page.add(panel); + + page.lock(); + + final Document document = page.buildDocument(request, response); + final PresentationManager presenter = Templating.getPresentationManager(); + presenter.servePage(document, request, response); + } + + private class PortletDataItemPanel extends SimpleComponent { + + private final XMLGenerator xmlGenerator; + + public PortletDataItemPanel(final ContentItem item) { + this.xmlGenerator = new XMLGenerator(item); + } + + @Override + public void generateXML(final PageState state, final Element parent) { + final Element content = parent.newChildElement("cms:contentPanel", + CMS.CMS_XML_NS); + xmlGenerator.generateXML(state, content, ""); + } + + } + + private class XMLGenerator extends SimpleXMLGenerator { + + private final ContentItem item; + + public XMLGenerator(final ContentItem item) { + super(); + this.item = item; + } + + @Override + protected ContentItem getContentItem(final PageState state) { + return item; + } + + } + +} diff --git a/ccm-cms-portletdataprovider/web/WEB-INF/web.ccm-cms-portletdataprovider.xml b/ccm-cms-portletdataprovider/web/WEB-INF/web.ccm-cms-portletdataprovider.xml new file mode 100644 index 000000000..87be18a3c --- /dev/null +++ b/ccm-cms-portletdataprovider/web/WEB-INF/web.ccm-cms-portletdataprovider.xml @@ -0,0 +1,19 @@ + + + + + + + PortletDataProviderServlet + com.arsdigita.cms.portletdataprovider.PortletDataProviderServlet + + + + PortletDataProviderServlet + /portletdataprovider/* + + + \ No newline at end of file