PortletDataProvider now serves individual content items
git-svn-id: https://svn.libreccm.org/ccm/trunk@2525 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
ddff90e199
commit
648076f171
|
|
@ -13,6 +13,8 @@
|
|||
</ccm:dependencies>
|
||||
|
||||
<ccm:directories>
|
||||
<ccm:directory name="pdl"/>
|
||||
<ccm:directory name="sql"/>
|
||||
<ccm:directory name="src"/>
|
||||
</ccm:directories>
|
||||
<ccm:contacts>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
@ ddl/oracle-se/create.sql
|
||||
|
||||
@ ddl/oracle-se/deferred.sql
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
begin;
|
||||
\i ddl/postgres/create.sql
|
||||
\i ddl/postgres/deferred.sql
|
||||
end;
|
||||
|
|
@ -7,6 +7,11 @@
|
|||
<initalizer class="com.arsdigita.navigation.Initalizer"/>
|
||||
</requires>
|
||||
<provides>
|
||||
<initalizer class="com.arsdigita.cms.portletdataprovider.Initializer"/>
|
||||
</provides>
|
||||
<table name="cms_portletdataprovider"/>
|
||||
<initializer class="com.arsdigita.cms.portletdataprovider.Initializer"/>
|
||||
</provides>
|
||||
<scripts>
|
||||
<schema directory="ccm-cms-portletdataprovider"/>
|
||||
<data class="com.arsdigita.cms.portletdataprovider.Loader"/>
|
||||
</scripts>
|
||||
</load>
|
||||
|
|
@ -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 <jens@jp-digital.de>
|
||||
* @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);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <jens@jp-digital.de>
|
||||
* @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/";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 <jens@jp-digital.de>
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
|
||||
version="2.4">
|
||||
|
||||
<!-- Servlets for the ccm-cms-portletdataprovider application -->
|
||||
|
||||
<servlet>
|
||||
<servlet-name>PortletDataProviderServlet</servlet-name>
|
||||
<servlet-class>com.arsdigita.cms.portletdataprovider.PortletDataProviderServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>PortletDataProviderServlet</servlet-name>
|
||||
<url-pattern>/portletdataprovider/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
Loading…
Reference in New Issue