You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by dd...@apache.org on 2005/02/21 01:30:21 UTC
svn commit: r154581 [2/3] - in portals/pluto/trunk/portal: ./
src/java/org/apache/commons/ src/java/org/apache/commons/fileupload/
src/java/org/apache/pluto/portlet/ src/java/org/apache/pluto/portlet/admin/
src/java/org/apache/pluto/portlet/admin/bean/
src/java/org/apache/pluto/portlet/admin/controller/
src/java/org/apache/pluto/portlet/admin/model/
src/java/org/apache/pluto/portlet/admin/services/
src/java/org/apache/pluto/portlet/admin/taglib/
src/java/org/apache/pluto/portlet/admin/util/ src/webapp/
src/webapp/WEB-INF/ src/webapp/WEB-INF/aggregation/ src/webapp/WEB-INF/data/
Added: portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/controller/PageRegistryPortlet.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/controller/PageRegistryPortlet.java?view=auto&rev=154581
==============================================================================
--- portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/controller/PageRegistryPortlet.java (added)
+++ portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/controller/PageRegistryPortlet.java Sun Feb 20 16:30:14 2005
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2003,2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.portlet.admin.controller;
+
+import java.io.IOException;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.pluto.portlet.admin.PlutoAdminConstants;
+import org.apache.pluto.portlet.admin.services.PageRegistryService;
+import org.apache.pluto.portlet.admin.controller.ControllerPortlet;
+
+/**
+ * PageRegistryPortlet
+ *
+ * @author Craig Doremus
+ *
+ */
+public class PageRegistryPortlet extends ControllerPortlet {
+
+ private PageRegistryService service = null;
+
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#doEdit(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+ */
+ protected void doEdit(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+ String rows = request.getParameter("rows");
+ String cols = request.getParameter("cols");
+ if (rows != null && cols != null) {
+ request.setAttribute("rows", rows);
+ request.setAttribute("cols", cols);
+ _incEdit = "/PageRegistryEdit2.jsp";
+ }
+ super.doEdit(request, response);
+ }
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+ */
+ protected void doView(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+ service.getAllPages(request);
+ super.doView(request, response);
+ }
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#init()
+ */
+ public void init() throws PortletException {
+ super.init();
+ service = new PageRegistryService();
+ }
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#doHelp(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+ */
+ protected void doHelp(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+ // TODO Auto-generated method stub
+ super.doHelp(request, response);
+ }
+ /* (non-Javadoc)
+ * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
+ */
+ public void processAction(ActionRequest request, ActionResponse response)
+ throws PortletException, IOException {
+
+ try {
+ String action = request.getParameter("action");
+ log("Action param == " + action);
+
+ /* TODO: Implement portlet deletion
+ if (action == null) {
+ ;//do nothing
+ } else if (action.equals("showallpages")) {
+
+ } else if (action.equals("showhome")) {
+ _incView = "/PageRegistryView.jsp";
+ response.setPortletMode(PortletMode.VIEW);
+ } else if (action.equals("showpage")) {
+ //TODO: finish implementation
+ //shows page for editing of attributes
+ service.getPage(request);
+ _incEdit = "/PageRegistryEdit.jsp";
+ response.setPortletMode(PortletMode.EDIT);
+ } else if (action.equals("showpagelayout")) {
+ //TODO: finish implementation
+ //shows page for editing of layout cells
+ service.modifyPageAttributes(request);
+ _incEdit = "/PageRegistryEdit2.jsp";
+ response.setPortletMode(PortletMode.EDIT);
+ } else if (action.equals("savepagelayout")) {
+ //TODO: process new layout
+// delegate.savePage(prPath, request);
+ response.setPortletMode(PortletMode.VIEW);
+ _incView = "/PageRegistryView.jsp";
+ }
+ */
+ } catch (Throwable e) {
+ log("Error! ", e);
+ request.getPortletSession().setAttribute(PlutoAdminConstants.ERROR_ATTR, e);
+ }
+ }
+}
Added: portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/controller/PortletEntityRegistryPortlet.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/controller/PortletEntityRegistryPortlet.java?view=auto&rev=154581
==============================================================================
--- portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/controller/PortletEntityRegistryPortlet.java (added)
+++ portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/controller/PortletEntityRegistryPortlet.java Sun Feb 20 16:30:14 2005
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2003,2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.portlet.admin.controller;
+
+import java.io.IOException;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import org.apache.pluto.portlet.admin.services.PortletRegistryService;
+
+
+/**
+ * Portlet concerned with portletentityregistry.xml persistence.
+ *
+ * @author Craig Doremus
+ *
+ */
+public class PortletEntityRegistryPortlet extends ControllerPortlet {
+ private PortletRegistryService service = null;
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#doEdit(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+ */
+ protected void doEdit(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+ log("Edit Mode");
+ super.doEdit(request, response);
+ }
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+ */
+ protected void doView(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+ log("View Mode");
+ String perPath = getPortletRegistryFilePath();
+ log("PER file path = " + perPath);
+ //get the new registry list and add to session
+ service.getPortletEntityRegistry(request);
+ super.doView(request, response);
+ }
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#init()
+ */
+ public void init() throws PortletException {
+ super.init();
+ service = new PortletRegistryService();
+ }
+ /* (non-Javadoc)
+ * @see javax.portlet.GenericPortlet#doHelp(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+ */
+ protected void doHelp(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+ log("Help Mode");
+ super.doHelp(request, response);
+ }
+ /* (non-Javadoc)
+ * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
+ */
+ public void processAction(ActionRequest request, ActionResponse response)
+ throws PortletException, IOException {
+ String action = request.getParameter("action");
+ log("action param == " + action);
+ /*//TODO: Implement editing
+ printParams(request);
+ if (action == null) {
+ ;//so we don't have to do null checks later
+ response.setPortletMode(PortletMode.EDIT);
+ } else if (action.equals("showportlet")) {
+ //Edit link clicked on View page
+ service.getPortletEntityRegistryApp(request);
+// delegate.getPortletEntityRegistryApp(perPath, request, response);
+ _incEdit = "/PortletEntityRegistryEdit.jsp";
+ response.setPortletMode(PortletMode.EDIT);
+ } else if (action.equals("addportlet")) {
+ //Add Portlet button on View page clicked
+// delegate.addPortletEntityRegistryApp(perPath, request, response);
+ _incEdit = "/PortletEntityRegistryEdit.jsp";
+ response.setPortletMode(PortletMode.EDIT);
+ } else if (action.equals("showprefs")) {
+ //show portlet preferences
+ String appId = request.getParameter("appId");
+ String portletId = request.getParameter("portletId");
+// delegate.getPortletPreferences(perPath, request, response);
+ service.getPortletPreferences(request);
+ _incEdit = "/PERPortletPreferencesEdit.jsp?appId=" + appId + "&portletId=" + portletId;
+ response.setPortletMode(PortletMode.EDIT);
+ } else if (action.equals("addpref")) {
+ //add a portlet preference name/value pair
+ String appId = request.getParameter("appId");
+ String portletId = request.getParameter("portletId");
+// delegate.addPortletPreference(perPath, request, response);
+ _incEdit = "/PERPortletPreferencesEdit.jsp?appId=" + appId + "&portletId=" + portletId;
+ response.setPortletMode(PortletMode.EDIT);
+ } else if (action.equals("addportlettoapp")) {
+ //Add a portlet to App on Edit page
+ //add a portlet preference name/value pair
+ String appId = request.getParameter("appId");
+ String portletId = request.getParameter("portletId");
+// delegate.addPortlet(perPath, request, response);
+ _incEdit = "/PortletEntityRegistryEdit.jsp";
+ response.setPortletMode(PortletMode.EDIT);
+ } else if (action.equals("savepref")) {
+ //Button clicked on Preference Edit page
+ String submit = request.getParameter("submit");
+ log("Button clicked: " + submit);
+ //ignore Cancel button
+ if (submit.equalsIgnoreCase("OK")) {
+ //add the pref data to the session
+// delegate.savePreference(perPath, request, response);
+ }
+ _incEdit = "/PortletEntityRegistryEdit.jsp";
+ response.setPortletMode(PortletMode.EDIT);
+ } else if (action.equals("saveportlet")) {
+ String submit = request.getParameter("submit");
+ log("Button clicked: " + submit);
+ //ignore Cancel button
+ //Save button clicked on Edit page
+ if (submit.equalsIgnoreCase("Save")) {
+ //Save the portlet data to portletentityregistry.xml
+// delegate.savePortlet(perPath, request, response);
+ }
+ _incView = "/PortletEntityRegistryView.jsp";
+ response.setPortletMode(PortletMode.VIEW);
+ }
+ printParams(request);
+*/
+ }
+}
Added: portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/model/PageRegistryXao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/model/PageRegistryXao.java?view=auto&rev=154581
==============================================================================
--- portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/model/PageRegistryXao.java (added)
+++ portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/model/PageRegistryXao.java Sun Feb 20 16:30:14 2005
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2003,2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.portlet.admin.model;
+
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.pluto.portalImpl.om.page.impl.FragmentImpl;
+import org.apache.pluto.portalImpl.om.page.impl.PortalImpl;
+import org.exolab.castor.mapping.Mapping;
+import org.exolab.castor.xml.Marshaller;
+import org.exolab.castor.xml.Unmarshaller;
+
+import org.apache.pluto.portlet.admin.BaseAdminObject;
+import org.apache.pluto.portlet.admin.PlutoAdminException;
+import org.apache.pluto.portlet.admin.util.PlutoAdminContext;
+
+/**
+ *
+ * This class is used to access and store data in the pageregistry.xml file.
+ * It uses Castor and is loosely based on the
+ * org.apache.services.pageregistry.PageRegistryServiceFileImpl
+ * class in Pluto's 'portal' module.
+ *
+ * @author Craig Doremus
+ */
+public class PageRegistryXao extends BaseAdminObject {
+
+
+ // default configuration values
+ public final static String CONFIG_FILE = "WEB-INF/data/pageregistry.xml";
+ public final static String DEFAULT_MAPPING = "WEB-INF/data/xml/pageregistrymapping.xml";
+ private final static String CLASS_NAME = "PageRegistryXao";
+ // Castor mapping file
+ private Mapping mapping = null;
+
+ /**
+ *
+ */
+ public PageRegistryXao() throws Exception {
+ super(CLASS_NAME);
+ init();
+ }
+ public void init () throws Exception
+ {
+ final String METHOD_NAME = "init()";
+
+ String _mapping = PlutoAdminContext.getInstance().getPlutoHome() + "/" + DEFAULT_MAPPING;
+
+ this.mapping = new Mapping();
+ try
+ {
+ this.mapping.loadMapping(_mapping);
+ }
+ catch (Exception e)
+ {
+ logError(METHOD_NAME, "Failed to load mapping file "+_mapping,e);
+ throw e;
+ }
+
+ }
+
+
+ public void save(PortalImpl page) throws Exception {
+ final String METHOD_NAME = "save(PortalImpl)";
+ String filename = PlutoAdminContext.getInstance().getPlutoHome() + "/" + CONFIG_FILE;
+ logDebug(METHOD_NAME, "Registry file to save: " + filename);
+
+ FileWriter writer = new FileWriter(filename);
+
+ Marshaller marshaller = new Marshaller(writer);
+
+ marshaller.setMapping(this.mapping);
+
+ marshaller.marshal(page);
+ }
+
+ public PortalImpl load() throws Exception
+ {
+ final String METHOD_NAME = "load()";
+
+ String filename = PlutoAdminContext.getInstance().getPlutoHome() + "/" + CONFIG_FILE;
+ logDebug(METHOD_NAME, "File to load: " + filename);
+
+ Unmarshaller unmarshaller = new Unmarshaller(this.mapping);
+ unmarshaller.setMapping(this.mapping);
+
+ PortalImpl pages = (PortalImpl)unmarshaller.unmarshal(new FileReader(filename));
+ return pages;
+ }
+
+ public boolean pageExists(String page) {
+ final String METHOD_NAME = "pageExists(page)";
+ boolean exists = false;
+ Collection frags = null;
+ try {
+ PortalImpl portal = load();
+ frags = portal.getFragments();
+ } catch (Exception e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+ Iterator iter = frags.iterator();
+ while (iter.hasNext()) {
+ FragmentImpl frag = (FragmentImpl) iter.next();
+ String type = null;
+ String name = null;
+ if (frag != null) {
+ type = frag.getType();
+ name = frag.getName();
+ }
+ if(type != null && type.equalsIgnoreCase("page") && name != null && name.equalsIgnoreCase(page)) {
+ exists = true;
+ break;
+ }
+ }
+ return exists;
+ }
+}
Added: portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/model/PortletEntityRegistryXao.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/model/PortletEntityRegistryXao.java?view=auto&rev=154581
==============================================================================
--- portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/model/PortletEntityRegistryXao.java (added)
+++ portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/model/PortletEntityRegistryXao.java Sun Feb 20 16:30:14 2005
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2003,2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.portlet.admin.model;
+
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import org.apache.pluto.portalImpl.om.entity.impl.PortletApplicationEntityImpl;
+import org.apache.pluto.portalImpl.om.entity.impl.PortletApplicationEntityListImpl;
+import org.apache.pluto.portalImpl.om.entity.impl.PortletEntityImpl;
+import org.exolab.castor.mapping.Mapping;
+import org.exolab.castor.xml.Marshaller;
+import org.exolab.castor.xml.Unmarshaller;
+import org.apache.pluto.portlet.admin.PlutoAdminException;
+import org.apache.pluto.portlet.admin.BaseAdminObject;
+import org.apache.pluto.portlet.admin.util.PlutoAdminContext;
+import org.apache.pluto.util.StringUtils;
+
+/**
+ * This class is used to access and store data in the portletentityregistry.xml file.
+ * It uses Castor and is loosely based on the
+ * org.apache.services.portletentityregistry.PortletEntityRegistryServiceFileImpl
+ * class in Pluto's 'portal' module.
+ *
+ * @author Craig Doremus
+ *
+ */
+public class PortletEntityRegistryXao extends BaseAdminObject {
+
+
+ // default configuration values
+ public final static String CONFIG_FILE = "WEB-INF/data/portletentityregistry.xml";
+ public final static String DEFAULT_MAPPING = "WEB-INF/data/xml/portletentitymapping.xml";
+ private final static String CLASS_NAME = "PortletEntityRegistryXao";
+ //Application elements within the registry
+ private Collection castorApplications = new ArrayList();
+
+ // Castor mapping file
+ private Mapping mapping = null;
+
+ /**
+ *
+ */
+ public PortletEntityRegistryXao() throws Exception {
+ super(CLASS_NAME);
+ init();
+ }
+ public void init () throws Exception
+ {
+ final String METHOD_NAME = "init()";
+
+ String _mapping = PlutoAdminContext.getInstance().getPlutoHome() + "/" + DEFAULT_MAPPING;
+
+ this.mapping = new Mapping();
+ try
+ {
+ this.mapping.loadMapping(_mapping);
+ }
+ catch (Exception e)
+ {
+ logError(METHOD_NAME, "Failed to load mapping file "+_mapping,e);
+ throw e;
+ }
+
+ }
+
+
+
+ public void save(PortletApplicationEntityListImpl apps) throws Exception
+ {
+ final String METHOD_NAME = "save(AdminPortalImpl)";
+ String filename = PlutoAdminContext.getInstance().getPlutoHome() + "/" + CONFIG_FILE;
+ logDebug(METHOD_NAME, "Registry file to save: " + filename);
+
+ FileWriter writer = new FileWriter(filename);
+
+ Marshaller marshaller = new Marshaller(writer);
+
+ marshaller.setMapping(this.mapping);
+
+ marshaller.marshal(apps);
+ }
+
+ public PortletApplicationEntityListImpl load() throws Exception
+ {
+ final String METHOD_NAME = "load()";
+
+ String filename = PlutoAdminContext.getInstance().getPlutoHome() + "/" + CONFIG_FILE;
+ logDebug(METHOD_NAME, "Registry file to load: " + filename);
+
+ Unmarshaller unmarshaller = new Unmarshaller(this.mapping);
+ unmarshaller.setMapping(this.mapping);
+
+ PortletApplicationEntityListImpl apps = (PortletApplicationEntityListImpl)unmarshaller.unmarshal(new FileReader(filename));
+ castorApplications = apps.getCastorApplications();
+ return apps;
+ }
+
+ public String toString()
+ {
+ return toString(0);
+ }
+
+ public String toString(int indent)
+ {
+ StringBuffer buffer = new StringBuffer(1000);
+ StringUtils.newLine(buffer,indent);
+ buffer.append(getClass().toString());
+ buffer.append(":");
+ StringUtils.newLine(buffer,indent);
+ buffer.append("{");
+ Iterator iterator = castorApplications.iterator();
+ if (iterator.hasNext()) {
+ StringUtils.newLine(buffer,indent);
+ buffer.append("Portlet Application Entities");
+ int count = castorApplications.size();
+ buffer.append("(");
+ buffer.append(count);
+ buffer.append("):");
+ }
+ while (iterator.hasNext()) {
+ buffer.append(((PortletApplicationEntityImpl)iterator.next()).toString(indent+2));
+ }
+ StringUtils.newLine(buffer,indent);
+ buffer.append("}");
+ return buffer.toString();
+ }
+
+ public Collection getApplications() throws Exception {
+ String METHOD_NAME = "getApplications()";
+ logMethodStart(METHOD_NAME);
+ Collection elist = null;
+ PortletApplicationEntityListImpl per = load();
+ logDebug(METHOD_NAME, "PER: " + per);
+ if (per != null) {
+ elist = per.getCastorApplications();
+ }
+ logMethodEnd(METHOD_NAME, elist);
+ return elist;
+ }
+
+ public PortletApplicationEntityImpl getApplication(String castorId) throws Exception {
+ PortletApplicationEntityImpl app = null;
+ Collection apps = getApplications();
+ Iterator iter = apps.iterator();
+ while(iter.hasNext()) {
+ PortletApplicationEntityImpl currApp = (PortletApplicationEntityImpl)iter.next();
+ if (currApp.getCastorId().equalsIgnoreCase(castorId)) {
+ app = currApp;
+ break;
+ }
+ }
+ return app;
+ }
+
+ public Collection getPortletPreferences(String appId, String portletId) throws Exception {
+ Collection list = null;
+ PortletApplicationEntityImpl app = getApplication(appId);
+ Collection plets = app.getCastorPortlets();
+ Iterator iter = plets.iterator();
+ while(iter.hasNext()) {
+ PortletEntityImpl plet = (PortletEntityImpl)iter.next();
+ if (plet.getCastorId().equalsIgnoreCase(portletId)) {
+ list = plet.getCastorPreferences();
+ break;
+ }
+ }
+ return list;
+ }
+
+ public boolean applicationExists(String appContext) {
+ final String METHOD_NAME = "applicationExists(appContext)";
+ boolean exists = false;
+ Collection apps = null;
+ try {
+ apps = getApplications();
+ } catch (Exception e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+ Iterator iter = apps.iterator();
+ while (iter.hasNext()) {
+ PortletApplicationEntityImpl app = (PortletApplicationEntityImpl) iter.next();
+ if (app.getDefinitionId().equalsIgnoreCase(appContext)) {
+ exists = true;
+ break;
+ }
+ }
+ return exists;
+ }
+}
Added: portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/DeployWarService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/DeployWarService.java?view=auto&rev=154581
==============================================================================
--- portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/DeployWarService.java (added)
+++ portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/DeployWarService.java Sun Feb 20 16:30:14 2005
@@ -0,0 +1,532 @@
+/*
+ * Copyright 2003,2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.portlet.admin.services;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload.PortletDiskFileUpload;
+import org.apache.pluto.portlet.admin.BaseAdminObject;
+import org.apache.pluto.portlet.admin.PlutoAdminConstants;
+import org.apache.pluto.portlet.admin.PlutoAdminException;
+import org.apache.pluto.portlet.admin.bean.PageTO;
+import org.apache.pluto.portlet.admin.bean.PortletMessage;
+import org.apache.pluto.portlet.admin.bean.PortletMessageType;
+import org.apache.pluto.portlet.admin.bean.PortletTO;
+import org.apache.pluto.portlet.admin.model.PageRegistryXao;
+import org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao;
+import org.apache.pluto.portlet.admin.util.PlutoAdminContext;
+
+/**
+ * DeployWarService
+ *
+ * @author Ken Atherton
+ * @author Craig Doremus
+ *
+ */
+public class DeployWarService extends BaseAdminObject {
+
+ public static final String ERROR_NO_FILE = "ERROR_NO_FILE";
+ public static final String CLASS_NAME = "DeployWarService";
+
+ /**
+ *
+ */
+ public DeployWarService() {
+ super(CLASS_NAME);
+ }
+
+ /**
+ * @param className
+ * @param logId
+ */
+ public DeployWarService(String logId) {
+ super(CLASS_NAME, logId);
+ }
+
+ public String processFileUpload(ActionRequest request, ActionResponse response) {
+ final String METHOD_NAME = "processFileUpload(request,response)";
+ String fileName = null;
+ String serverFileName = null;
+ request.getPortletSession().setAttribute(PlutoAdminConstants.MESSAGE_ATTR, new PortletMessage("Deployment unsuccessful", PortletMessageType.ERROR));
+ // Check the request content type to see if it starts with multipart/
+ if (PortletDiskFileUpload.isMultipartContent(request))
+ {
+
+ PortletDiskFileUpload dfu = new PortletDiskFileUpload();
+
+ //maximum allowed file upload size (10 MB)
+ dfu.setSizeMax(10 * 1000 * 1000);
+
+ //maximum size in memory (vs disk) (100 KB)
+ dfu.setSizeThreshold(100 * 1000);
+
+ try
+ {
+ //get the FileItems
+ List fileItems = dfu.parseRequest(request);
+ Iterator iter = fileItems.iterator();
+ while (iter.hasNext())
+ {
+ FileItem item = (FileItem) iter.next();
+ if (item.isFormField())
+ {
+ //pass along to render request
+ String fieldName = item.getFieldName();
+ String value = item.getString();
+ response.setRenderParameter(fieldName, value);
+ }
+ else
+ {
+ //write the uploaded file to a new location
+ fileName = item.getName();
+ String contentType = item.getContentType();
+ long size = item.getSize();
+ response.setRenderParameter("size", Long.toString(size));
+ response.setRenderParameter("contentType", contentType);
+ String tempDir = System.getProperty("java.io.tmpdir");
+ serverFileName = getRootFilename(File.separatorChar, fileName);
+ File serverFile = new File(tempDir, serverFileName);
+ item.write(serverFile);
+ response.setRenderParameter("serverFileName", serverFileName);
+ logDebug(METHOD_NAME, "serverFileName : " + tempDir + PlutoAdminConstants.FS + serverFileName);
+
+ //Add to portletentityregistry.xml
+ int index = serverFileName.indexOf(".war");
+ String context = "";
+ if ( index != -1) {
+ context = serverFileName.substring(0, index);
+ } else {
+ context = serverFileName;
+ }
+ //TODO: send in boolean for existance of PER
+ //Check to see if a record exists
+ PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
+ boolean appExists = xao.applicationExists(context);
+ ArrayList argList = createDeploymentArgs(serverFileName, tempDir, request, appExists);
+ Map pmap = (HashMap) request.getPortletSession().getAttribute(PlutoAdminConstants.PORTLET_MAP_ATTR);
+ logDebug(METHOD_NAME, "pmap: " + mapToEntrySetString(pmap));
+ System.out.println("pmap: " + mapToEntrySetString(pmap));
+ String[] args = arrayListToStringArray(argList);
+ for (int i =0; i < args.length; i++) {
+ logDebug(METHOD_NAME, "args["+i+"]="+args[i]);
+ }
+ org.apache.pluto.portalImpl.Deploy.main(args);
+ if (appExists) {
+ request.getPortletSession().setAttribute(PlutoAdminConstants.MESSAGE_ATTR, new PortletMessage("Deployment of the new portlet app has been successful, but the portlet app record " + context + " already exists in portletentityregistry.xml. If you are deploying a previously deployed portlet app, caching of the old app may require that you restart Pluto to see the new changes.", PortletMessageType.INFO));
+ } else {
+ request.getPortletSession().setAttribute(PlutoAdminConstants.MESSAGE_ATTR, new PortletMessage("Deployment and addition to portletentityregistry.xml successful", PortletMessageType.SUCCESS));
+ }
+ }
+ }
+ }
+ catch (FileUploadException e){
+ String msg = "File Upload Exception: " + e.getMessage();
+ logError(METHOD_NAME, msg, e);
+ throw new PlutoAdminException(e);
+ } catch (Exception e) {
+ String msg = "Exception: " + e.getMessage();
+ logError(METHOD_NAME, msg, e);
+ throw new PlutoAdminException(e);
+ }
+ } else {
+ //set an error message
+ request.getPortletSession().setAttribute(PlutoAdminConstants.MESSAGE_ATTR, new PortletMessage("No file appears to have been selected.", PortletMessageType.ERROR));
+ }
+ logMethodEnd(METHOD_NAME, serverFileName);
+ return serverFileName;
+ }
+
+
+ private String getRootFilename(char delimiter, String pathName) {
+ int startFilenameIndex = pathName.lastIndexOf(delimiter) + 1;
+ String filename = pathName.substring(startFilenameIndex);
+ return filename;
+ }
+
+ private static String[] arrayListToStringArray(ArrayList argStringArrayList) {
+ return (String[]) argStringArrayList.toArray(new String[argStringArrayList.size()]);
+ }
+
+
+
+ private InputStream extractFile(String zipfilename, String filename) {
+ final String METHOD_NAME = "extractFile(zipfilename,filename)";
+ InputStream ins = null;
+ try {
+ ZipFile zf = new ZipFile(zipfilename);
+ if (null != zf) {
+ ZipEntry ze = zf.getEntry(filename);
+ if (null != ze) {
+ ins = zf.getInputStream(ze);
+ }
+ }
+ }
+ catch (Exception e) {
+ logError(CLASS_NAME, METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+ return ins;
+ }
+
+
+
+ //[-addToEntityReg <app-id> [<portlet-id>:<portlet-name>]+]
+ private ArrayList createDeploymentArgs(String serverFileName, String tempDir, ActionRequest request, boolean appExists) throws Exception {
+ final String METHOD_NAME = "createDeploymentArgs(serverFileName,tempDir,request)";
+ Properties props = PlutoAdminContext.getInstance().getProperties();
+ final String TOMCAT_HOME = PlutoAdminContext.getInstance().getTomcatHome();
+ final String PLUTO_CONTEXT = props.getProperty("pluto-web-context");
+ final String PORTLET_DEPLOY_DIR = props.getProperty("portlet-deploy-dir");
+ logDebug(METHOD_NAME, "Tomcat home: " + TOMCAT_HOME);
+ logDebug(METHOD_NAME, "Pluto web context: " + PLUTO_CONTEXT);
+
+ ArrayList args = new ArrayList();
+ args.add(TOMCAT_HOME + PlutoAdminConstants.FS + "webapps");
+ args.add(PLUTO_CONTEXT);
+ args.add(tempDir + PlutoAdminConstants.FS + serverFileName);
+ args.add(TOMCAT_HOME + PlutoAdminConstants.FS + PORTLET_DEPLOY_DIR);
+ String appId = PortletRegistryService.getNextAppId();
+ //check if a record in portletentityregistry exists
+ if (!appExists) {
+ args.add("-addToEntityReg");
+ args.add(appId);
+ }
+
+ //Add Map of portlet name/values to session
+ // to be used in drop downs on page layout page
+ Map pmap = new HashMap();
+ InputStream ins = extractFile(tempDir + PlutoAdminConstants.FS + serverFileName, "WEB-INF/portlet.xml");
+ if (null != ins) {
+ ArrayList names = PortletNameFinder.getPortletNames(ins);
+ for (int i = 0; i < names.size(); i++) {
+ //check if a record in portletentityregistry exists
+ if (!appExists) {
+ args.add(i+":"+names.get(i));
+ }
+ pmap.put(names.get(i), appId+"." +i);
+ }
+ ins.close();
+ } else {
+ String msg = "Input stream is null";
+ PlutoAdminException e = new PlutoAdminException(msg);
+ logError(METHOD_NAME, e);
+ throw e;
+ }
+ request.getPortletSession().setAttribute(PlutoAdminConstants.PORTLET_MAP_ATTR, pmap);
+ return args;
+ }
+
+
+ public static String mapToEntrySetString(Map inputMap) {
+ StringBuffer sb = new StringBuffer();
+ Set es = inputMap.entrySet();
+ Iterator it = es.iterator();
+ sb.append("Number of entries: " + es.size());
+ for (int i = 0; i < es.size(); i++) {
+ Map.Entry entry = (Map.Entry) it.next();
+ sb.append((String) entry.getKey().toString());
+ sb.append(entry.getValue().toString());
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Sets the page information into a PageTO object that is loaded into the
+ * session.
+ *
+ * @param req
+ */
+ public void setPage(ActionRequest req) {
+ final String METHOD_NAME = "setPage(request)";
+ logMethodStart(METHOD_NAME);
+ PageTO page = (PageTO)req.getPortletSession().getAttribute(PlutoAdminConstants.PAGE_ATTR);
+ if (page == null) {
+ page = new PageTO();
+ }
+ String title = req.getParameter("title");
+ logDebug(METHOD_NAME, "Title: " + title);
+ page.setTitle(title);
+ String desc = req.getParameter("description");
+ logDebug(METHOD_NAME, "Description: " + desc);
+ page.setDescription(desc);
+ String rows = req.getParameter("numrows");
+ logDebug(METHOD_NAME, "Row count: " + rows);
+ page.setRows(Integer.parseInt(rows));
+ String cols = req.getParameter("numcols");
+ logDebug(METHOD_NAME, "Col count: " + cols);
+ page.setCols(Integer.parseInt(cols));
+ req.getPortletSession().setAttribute(PlutoAdminConstants.PAGE_ATTR, page);
+ logDebug(METHOD_NAME, "New page: " + page);
+ logMethodEnd(METHOD_NAME);
+ }
+ public void savePageLayout(ActionRequest req) {
+ final String METHOD_NAME = "savePageLayout(request)";
+ logMethodStart(METHOD_NAME);
+ //get current page
+ PageTO page = (PageTO)req.getPortletSession().getAttribute(PlutoAdminConstants.PAGE_ATTR);
+ logDebug(METHOD_NAME, "PageTO from session: " + page);
+ List list = new ArrayList();
+ int rows = page.getRows();
+ int cols = page.getCols();
+ for (int i = 1; i <= rows ; i++) {
+ for (int j = 1; j <= cols ; j++) {
+ String portletParam = "portlet" + i + "." + j;
+ String name_val = req.getParameter(portletParam);
+ //portlet name and values are separated by an underscore
+ int underscore = name_val.lastIndexOf("_");
+ String name = name_val.substring(0, underscore);
+ String val = name_val.substring(underscore + 1);
+
+ //create a PortletTO and add it to the list
+ PortletTO nPortlet = new PortletTO();
+ nPortlet.setName(name);
+ nPortlet.setValue(val);
+ nPortlet.setRow(i);
+ nPortlet.setCol(j);
+ list.add(nPortlet);
+ }
+ }
+ page.setPortlets(list);
+ logDebug(METHOD_NAME, "Updated PageTO: " + page);
+
+ addToPageReg(page);
+ logMethodEnd(METHOD_NAME);
+ }
+
+ /**
+ * Add a new page record to the pageregistry.xml file.
+ * @param page The new page to add
+ */
+ public void addToPageReg(PageTO page) {
+ final String METHOD_NAME = "addToPageReg(PageTO)";
+ logMethodStart(METHOD_NAME);
+ RandomAccessFile ras = null;
+
+// int rows = page.getRows();
+ int cols = page.getCols();
+ String name = page.getName();
+ try {
+ //get path to pageregistry.xml
+ String pageregpath = PlutoAdminContext.getInstance().getPageRegistryPath();
+ //String pageregpath = "/pluto-1.0.1/webapps/pluto/WEB-INF/data/pageregistry.xml";
+
+ File file = new File(pageregpath);
+ ras = new RandomAccessFile(file, "rw");
+ long length = ras.length();
+ byte[] contentByte = new byte[(int) length];
+ ras.read(contentByte);
+ String contentString = new String(contentByte);
+ //Check for previous deployment in pageregistry.xml
+ String prev = "fragment name=\"" + name;
+ if (contentString.lastIndexOf(prev) != -1){
+ String errMsg = "Portlet '" + name + "' already exists in pageregistry.xml";
+ PlutoAdminException e = new PlutoAdminException(errMsg);
+ logError(METHOD_NAME, errMsg, e);
+ throw e;//throw exception here
+ }
+ //start before close of root element
+ long pos = contentString.lastIndexOf("</portal>");
+ ras.seek(pos);
+
+ //start page fragment
+ ras.writeBytes(" <fragment name=\"" + name + "\" type=\"page\" >" + PlutoAdminConstants.LS);
+ ras.writeBytes(" <navigation>" + PlutoAdminConstants.LS);
+ ras.writeBytes(" <title>" + page.getTitle());
+ ras.writeBytes("</title>" + PlutoAdminConstants.LS);
+ ras.writeBytes(" <description>" + page.getDescription());
+ ras.writeBytes("</description>" + PlutoAdminConstants.LS);
+ ras.writeBytes(" </navigation>" + PlutoAdminConstants.LS);
+
+ //iterate through portlets
+ List portlets = page.getPortlets();
+ //Sort list using Comparable implementation in PortletTO. This makes sure
+ // the items in the list are ordered by rows
+ Collections.sort(portlets);
+ Iterator iter = portlets.iterator();
+ int count = 0;
+ int currRow = 0;
+ int lastRow = 0;
+ int currCol = 0;
+ while (iter.hasNext()) {
+ count++;
+ PortletTO portlet = (PortletTO)iter.next();
+ logDebug(METHOD_NAME, "Portlet: " + portlet);
+ currRow = portlet.getRow();
+ currCol = portlet.getCol();
+ //start row fragment
+ // Add row fragment when row changes
+ if (currRow != lastRow) {
+ ras.writeBytes(" <fragment name=\"row" + currRow + "\" type=\"row\">" + PlutoAdminConstants.LS);
+ ras.writeBytes(" <fragment name=\"col" + count + "\" type=\"column\">" + PlutoAdminConstants.LS);
+ }
+
+ ras.writeBytes(" <fragment name=\"p" + count + "\" type=\"portlet\">" + PlutoAdminConstants.LS);
+ ras.writeBytes(" <property name=\"portlet\" value=\"" + portlet.getValue() + "\"/>" + PlutoAdminConstants.LS);
+ ras.writeBytes(" </fragment><!-- end of portlet frag -->" + PlutoAdminConstants.LS);
+
+ //end row fragment
+ if (cols == currCol) {
+ ras.writeBytes(" </fragment><!-- end of col frag -->" + PlutoAdminConstants.LS);
+ //end of column iteration
+ ras.writeBytes(" </fragment><!-- end of row frag -->" + PlutoAdminConstants.LS);
+ }
+ lastRow = currRow;
+ }
+
+ //end page fragment
+ ras.writeBytes(" </fragment><!-- end of 'page' frag -->" + PlutoAdminConstants.LS);
+ //add a couple of newlines to separate records
+ ras.writeBytes(PlutoAdminConstants.LS);
+ ras.writeBytes(PlutoAdminConstants.LS);
+ //replace closing root element
+ ras.writeBytes("</portal>" + PlutoAdminConstants.LS);
+
+ } catch (IOException e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ } finally {
+ if (ras != null) {
+ try {
+ ras.close();
+ } catch (IOException e) {
+ logError(METHOD_NAME, e);
+ }
+ }
+ }
+ logMethodEnd(METHOD_NAME);
+ }
+
+ public void addToPortletContexts(String context) {
+ final String METHOD_NAME = "addToPortletContexts(context)";
+ logParam(METHOD_NAME, "context", context);
+ String path = PlutoAdminContext.getInstance().getPortletContextsPath();
+ logDebug(METHOD_NAME, "portletcontexts.txt path: " + path);
+ File file = new File(path);
+ if (file.exists()) {
+// String fileContents = FileUtils.readFileToString(file, PlutoAdminConstants.ENCODING);
+ String fileContents = readFileToString(file);
+ logDebug(METHOD_NAME, "portletcontexts.txt contents: " + fileContents);
+
+ //check to see whether the context already is found in the file
+ if (fileContents.indexOf(context) == -1) {
+ logDebug(METHOD_NAME, "Writing new context");
+ StringBuffer buf = new StringBuffer(fileContents);
+ buf.append(PlutoAdminConstants.LS);
+ buf.append("/");
+ buf.append(context);
+// FileUtils.writeStringToFile(file,buf.toString(),PlutoAdminConstants.ENCODING);
+ writeStringToFile(file,buf.toString());
+ }
+ } else {
+ logWarn(METHOD_NAME, "File portletcontexts.txt cannot be found! You must be using Release Candidate 1.");
+ }
+ }
+
+
+ public boolean pageExists(String pageName) {
+ final String METHOD_NAME = "pageExists(pageName)";
+ boolean exists = true;
+ try {
+ PageRegistryXao xao = new PageRegistryXao();
+ exists = xao.pageExists(pageName);
+ } catch (Exception e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+ return exists;
+ }
+
+ public String readFileToString(File file){
+ final String METHOD_NAME = "readFileToString(path)";
+ String contents = null;
+ FileInputStream fis = null;
+ try {
+ fis = new FileInputStream(file);
+ int c;
+ char b;
+ StringBuffer sb = new StringBuffer();
+ while((c = fis.read()) != -1) {
+ b = (char)c;
+ sb.append(b);
+ }
+ contents = sb.toString().trim();
+ } catch (FileNotFoundException e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ } catch (IOException e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+ }
+ }
+ return contents;
+ }
+
+ public void writeStringToFile(File file, String contents){
+ final String METHOD_NAME = "addFileToStringToFile(contents)";
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(file);
+ byte[] bytes = contents.getBytes();
+ fos.write(bytes);
+ } catch (FileNotFoundException e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ } catch (IOException e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+ }
+ }
+ }
+
+}
Added: portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PageRegistryService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PageRegistryService.java?view=auto&rev=154581
==============================================================================
--- portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PageRegistryService.java (added)
+++ portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PageRegistryService.java Sun Feb 20 16:30:14 2005
@@ -0,0 +1,302 @@
+/*
+ * Copyright 2003,2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.portlet.admin.services;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.RenderRequest;
+
+import org.apache.pluto.portalImpl.om.page.impl.PortalImpl;
+import org.apache.pluto.portalImpl.om.page.impl.FragmentImpl;
+import org.apache.pluto.portlet.admin.BaseAdminObject;
+import org.apache.pluto.portlet.admin.PlutoAdminConstants;
+import org.apache.pluto.portlet.admin.PlutoAdminException;
+import org.apache.pluto.portlet.admin.bean.PageTO;
+import org.apache.pluto.portlet.admin.bean.PortletTO;
+
+/**
+ * Service concerned with pageregistry.xml persistence
+ *
+ *
+ * @author Craig Doremus
+ * @see org.apache.pluto.portlet.admin.controller.PageRegistryPortlet
+ *
+ */
+public class PageRegistryService extends BaseAdminObject {
+
+ private static final String CLASS_NAME = "PageRegistryService";
+
+// private List _rows = new ArrayList();
+// private int _rowIndex = 1;
+// private List _cols = new ArrayList();
+// private int _colIndex = 1;
+
+ /**
+ *
+ */
+ public PageRegistryService() {
+ super(CLASS_NAME);
+ }
+
+/*
+ public Iterator getPageRegistry(String prPath) {
+ final String METHOD_NAME = "getPageRegistry(prPath)";
+ List pages = new ArrayList();
+ PageRegistryXao xao = new PageRegistryXao();
+ List prpages = xao.getFragments(prPath);
+ Iterator iter = prpages.iterator();
+ while (iter.hasNext()) {
+ FragmentType frag = (FragmentType) iter.next();
+ //get rid of navigation fragment
+ if(!frag.getName().equals("navigation")) {
+ pages.add(frag);
+ }
+ }
+ logDebug(METHOD_NAME, "Page count: " + pages.size());
+ return pages.iterator();
+ }
+*/
+
+ public Iterator getPageRegistry() {
+ final String METHOD_NAME = "getPageRegistry()";
+ List pages = new ArrayList();
+ PortalImpl portal;
+ try {
+ org.apache.pluto.portlet.admin.model.PageRegistryXao xao = new org.apache.pluto.portlet.admin.model.PageRegistryXao();
+ portal = xao.load();
+ } catch (Exception e) {
+ PlutoAdminException pae = new PlutoAdminException(e);
+ logError(CLASS_NAME, METHOD_NAME, e);
+ throw pae;
+ }
+ Collection prpages = portal.getFragments();
+ Iterator iter = prpages.iterator();
+ while (iter.hasNext()) {
+ FragmentImpl frag = (FragmentImpl) iter.next();
+ //exclude navigation fragment
+ if(!frag.getName().equals("navigation")) {
+ //fill a PageTO
+ PageTO page = new PageTO();
+ page.setName(frag.getName());
+ //figure out number of rows and columns
+ //rows first
+ Collection rfrags = frag.getFragments();
+ page.setTitle(frag.getNavigation().getTitle());
+ page.setDescription(frag.getNavigation().getDescription());
+ int rows = rfrags.size();
+ page.setRows(rows);
+ if (rows > 0) {
+ FragmentImpl row = (FragmentImpl)rfrags.iterator().next();
+ Collection cfrags = row.getFragments();
+ FragmentImpl col = (FragmentImpl)cfrags.iterator().next();
+ int cols = col.getFragments().size();
+ page.setCols(cols);
+ }
+ pages.add(page);
+ }
+ }
+ logDebug(METHOD_NAME, "Page count: " + pages.size());
+ return pages.iterator();
+ }
+
+ /* *
+ * Get list for View page.
+ *
+ * @param prPath
+ * @return
+ public List getPageVOList(String prPath) {
+ final String METHOD_NAME = "getPageVOList(prPath)";
+ logMethodStart(METHOD_NAME);
+ List pagevos = new ArrayList();
+ Iterator iter = getPageRegistry(prPath);
+ while (iter.hasNext()) {
+ FragmentType frag = (FragmentType) iter.next();
+ pagevos.add(new PageTO(frag));
+ }
+ logMethodEnd(METHOD_NAME, "PageTO count: " + pagevos.size());
+ return pagevos;
+ }
+ */
+
+/*
+ public FragmentType getPage(String prPath, String name) {
+ FragmentType page = null;
+ Iterator iter = getPageRegistry(prPath);
+ while (iter.hasNext()) {
+ FragmentType frag = (FragmentType) iter.next();
+ //get rid of navigation fragments
+ if(frag.getName().equals(name)) {
+ page = frag;
+ break;
+ }
+ }
+ return page;
+ }
+*/
+
+/*
+ public PageTO getPageVO(String prPath, String name){
+ final String METHOD_NAME = "getPage(prPath,name)";
+ logMethodStart(METHOD_NAME);
+ PageTO page = null;
+ List pages = getPageVOList(prPath);
+ Iterator iter = pages.iterator();
+ while (iter.hasNext()) {
+ PageTO element = (PageTO) iter.next();
+ if (element.getName().equals(name)) {
+ page = element;
+ break;
+ }
+ }
+ logMethodEnd(METHOD_NAME, page);
+ return page;
+ }
+*/
+
+ public PageTO getPageVO(String name){
+ final String METHOD_NAME = "getPageVO(name)";
+ logMethodStart(METHOD_NAME);
+ PageTO page = null;
+ Iterator iter = getPageRegistry();
+ while (iter.hasNext()) {
+ PageTO element = (PageTO) iter.next();
+ if (element.getName().equals(name)) {
+ page = element;
+ break;
+ }
+ }
+ logMethodEnd(METHOD_NAME, page);
+ return page;
+ }
+
+
+/*
+ private List getPortletList(int index, PageTO page) {
+ final String METHOD_NAME = "getPortletList(index,page)";
+ logMethodStart(METHOD_NAME);
+ logParam(METHOD_NAME, "index", index);
+ logParam(METHOD_NAME, "page", page);
+ List cplets = new ArrayList();
+ List plets = page.getPortlets();
+ logDebug(METHOD_NAME, "Portlet list: " + plets);
+ Iterator iter = plets.iterator();
+ while (iter.hasNext()) {
+ PortletTO plet = (PortletTO) iter.next();
+ if (plet.getCol() == index) {
+ PropertyType prop = new PropertyTypeImpl();
+ prop.setName(plet.getName());
+ prop.setValue(plet.getValue());
+ cplets.add(prop);
+ }
+ }
+ logMethodEnd(METHOD_NAME, cplets);
+ return cplets;
+ }
+*/
+
+/*
+ private void addRow() {
+ final String METHOD_NAME = "addRow()";
+ logMethodStart(METHOD_NAME);
+ FragmentType frag = new FragmentTypeImpl();
+ frag.setTypeattr("row");
+ frag.setName("r" + _rowIndex);
+ List list = frag.getFragmentOrNavigationOrProperty();
+ list.addAll(_cols);
+ _rows.add(frag);
+ _rowIndex++;
+ logMethodEnd(METHOD_NAME);
+ }
+*/
+
+/*
+ private void addCol(PageTO page) {
+ final String METHOD_NAME = "addCol(page)";
+ logMethodStart(METHOD_NAME);
+ logParam(METHOD_NAME, "page", page);
+ FragmentType frag = new FragmentTypeImpl();
+ frag.setTypeattr("col");
+ frag.setName("c" + _colIndex);
+ List list = frag.getFragmentOrNavigationOrProperty();
+ List portlets = getPortletList(_colIndex, page);
+ list.addAll(portlets);
+ _cols.add(frag);
+ _colIndex++;
+ logMethodEnd(METHOD_NAME);
+ }
+*/
+
+ /**
+ * Gets the pages from pageregistry.xml for the View.
+ * @param prPath
+ * @param req
+ */
+ public void getAllPages(RenderRequest req) {
+ Iterator iter = getPageRegistry();
+ req.setAttribute(PlutoAdminConstants.PAGE_LIST_ATTR, iter);
+// req.getPortletSession().removeAttribute(PlutoAdminConstants.PAGE_ATTR);
+ }
+
+ public void getPage(ActionRequest req) {
+ String pageName = req.getParameter("pageName");
+ PageTO page = getPageVO(pageName);
+ req.getPortletSession().setAttribute(PlutoAdminConstants.PAGE_ATTR, page);
+ }
+
+ public void modifyPageAttributes(ActionRequest req) {
+ final String METHOD_NAME = "modifyRowsAndCols(request)";
+ logMethodStart(METHOD_NAME);
+ PageTO page = (PageTO)req.getPortletSession().getAttribute(PlutoAdminConstants.PAGE_ATTR);
+ logDebug(METHOD_NAME, "Current page: " + page);
+ String title = req.getParameter("title");
+ page.setTitle(title);
+ String description = req.getParameter("description");
+ page.setDescription(description);
+ String rows = req.getParameter("numrows");
+ page.setRows(Integer.parseInt(rows));
+ String cols = req.getParameter("numcols");
+ page.setCols(Integer.parseInt(cols));
+ logDebug(METHOD_NAME, "Updated current page: " + page);
+ req.getPortletSession().setAttribute(PlutoAdminConstants.PAGE_ATTR, page);
+ logMethodEnd(METHOD_NAME);
+ }
+
+ public Map getPortletMapForSelect(String app) {
+ Map map = new HashMap();
+ List portlets = null;
+ Iterator iter = getPageRegistry();
+ while (iter.hasNext()) {
+ PageTO page = (PageTO)iter.next();
+ if (page.getName().equalsIgnoreCase(app)) {
+ portlets = page.getPortlets();
+ break;
+ }
+ }
+ //go through portlets
+ Iterator piter = portlets.iterator();
+ while(piter.hasNext()){
+ PortletTO plet = (PortletTO)piter.next();
+ map.put(plet.getName(), plet.getValue());
+ }
+ return map;
+ }
+}
Added: portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PortletNameFinder.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PortletNameFinder.java?view=auto&rev=154581
==============================================================================
--- portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PortletNameFinder.java (added)
+++ portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PortletNameFinder.java Sun Feb 20 16:30:14 2005
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2003,2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.portlet.admin.services;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.pluto.portlet.admin.PlutoAdminConstants;
+import org.apache.pluto.portlet.admin.PlutoAdminException;
+import org.apache.pluto.portlet.admin.PlutoAdminLogger;
+
+/**
+ *
+ * Gets the portlet names from portlet.xml using SAX
+ *
+ * @author Ken Atherton
+ *
+ */
+public class PortletNameFinder {
+
+ public static final String CLASS_NAME = "PortletNameFinder";
+
+ PortletNameFinder() {
+ }
+
+
+ public static ArrayList getPortletNames(InputStream ios) throws Exception {
+ final String METHOD_NAME = "getPortletNames(InputStream)";
+ ArrayList nameList = new ArrayList();
+ boolean validation = false;
+
+ boolean ignoreWhitespace = false;
+ boolean ignoreComments = false;
+ boolean putCDATAIntoText = false;
+ boolean createEntityRefs = false;
+
+ DocumentBuilderFactory dbf =
+ DocumentBuilderFactory.newInstance();
+
+ dbf.setValidating(validation);
+ dbf.setIgnoringComments(ignoreComments);
+ dbf.setIgnoringElementContentWhitespace(ignoreWhitespace);
+ dbf.setCoalescing(putCDATAIntoText);
+ dbf.setExpandEntityReferences(!createEntityRefs);
+
+
+ DocumentBuilder db = null;
+ try {
+ db = dbf.newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ PlutoAdminLogger.logError(CLASS_NAME, METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+
+ OutputStreamWriter errorWriter =
+ new OutputStreamWriter(System.err, PlutoAdminConstants.ENCODING);
+ db.setErrorHandler(
+ new MyErrorHandler(new PrintWriter(errorWriter, true)));
+
+ Document doc = null;
+ try {
+ doc = db.parse(ios);
+ } catch (SAXException e) {
+ PlutoAdminLogger.logError(CLASS_NAME, METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ } catch (IOException e) {
+ PlutoAdminLogger.logError(CLASS_NAME, METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+
+ NodeList portletNames = doc.getElementsByTagName("portlet-name");
+ if (null != portletNames)
+ {
+ for (int i = 0; i < portletNames.getLength(); i++) {
+ if (null != portletNames.item(i).getChildNodes().item(0))
+ {
+ String portletName = portletNames.item(i).getChildNodes().item(0).getNodeValue();
+ nameList.add(portletName);
+ }
+ }
+ }
+ return nameList;
+ }
+
+
+
+
+ /**
+ *
+ * Inner class that handles errors
+ *
+ * @author Ken Atherton
+ *
+ */
+ private static class MyErrorHandler implements ErrorHandler {
+ private static final String INNER_CLASS_NAME = "MyErrorHandler";
+ PrintWriter out = null;
+ MyErrorHandler(PrintWriter p_out) {
+ out = p_out;
+ }
+
+
+ private String getParseExceptionInfo(SAXParseException e) {
+ String systemId = e.getSystemId();
+ if (systemId == null) {
+ systemId = "null";
+ }
+ String info = "URI=" + systemId +
+ " Line=" + e.getLineNumber() +
+ ": " + e.getMessage();
+ return info;
+ }
+
+
+ public void warning(SAXParseException e) throws SAXException {
+ String METHOD_NAME = "warning(e)";
+ String msg = "Warning: " + getParseExceptionInfo(e);
+ PlutoAdminLogger.logWarn(INNER_CLASS_NAME, METHOD_NAME, msg);
+ }
+
+ public void error(SAXParseException e) throws SAXException {
+ String METHOD_NAME = "error(e)";
+ String message = "Error: " + getParseExceptionInfo(e);
+ PlutoAdminLogger.logError(INNER_CLASS_NAME, METHOD_NAME, message, e);
+ throw new SAXException(message);
+ }
+
+ public void fatalError(SAXParseException e) throws SAXException {
+ String METHOD_NAME = "fatalError(e)";
+ String message = "Fatal Error: " + getParseExceptionInfo(e);
+ PlutoAdminLogger.logError(INNER_CLASS_NAME, METHOD_NAME, message, e);
+ throw new SAXException(message);
+ }
+ }
+
+
+
+}
Added: portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PortletRegistryService.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PortletRegistryService.java?view=auto&rev=154581
==============================================================================
--- portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PortletRegistryService.java (added)
+++ portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/services/PortletRegistryService.java Sun Feb 20 16:30:14 2005
@@ -0,0 +1,251 @@
+/*
+ * Copyright 2003,2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.portlet.admin.services;
+
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.PortletSession;
+import javax.portlet.RenderRequest;
+
+import org.apache.pluto.portalImpl.om.entity.impl.PortletApplicationEntityImpl;
+import org.apache.pluto.portalImpl.om.entity.impl.PortletApplicationEntityListImpl;
+import org.apache.pluto.portlet.admin.BaseAdminObject;
+import org.apache.pluto.portlet.admin.PlutoAdminConstants;
+import org.apache.pluto.portlet.admin.PlutoAdminException;
+import org.apache.pluto.portlet.admin.PlutoAdminLogger;
+import org.apache.pluto.portlet.admin.util.PortletApplicationEntityImplComparator;
+
+/**
+ * Service concerned with portletentityregistry.xml persistence
+ *
+ * @author Craig Doremus
+ * @see org.apache.pluto.portlet.admin.controller.PortletEntityRegistryPortlet
+ *
+ */
+public class PortletRegistryService extends BaseAdminObject {
+
+ private static final String CLASS_NAME = "PortletRegistryService";
+
+
+ /**
+ * Default constructor
+ */
+ public PortletRegistryService() {
+ super(CLASS_NAME);
+ }
+
+ public List getPageRegistryData(String prPath) {
+ List alist = null;
+ return alist;
+ }
+
+ /*
+ public void savePortlet(String perPath, ApplicationTypeImpl app){
+ final String METHOD_NAME = "savePortlet(perPath,app)";
+ logMethodStart(METHOD_NAME);
+ logParam(METHOD_NAME, "perPath", perPath);
+ logParam(METHOD_NAME, "app", app);
+ PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
+ xao.saveApplications(perPath,app);
+ logMethodEnd(METHOD_NAME);
+ }
+ */
+
+ public List getPortletEntityRegistry(String perPath) {
+ final String METHOD_NAME = "getPortletEntityRegistry(perPath)";
+ logMethodStart(METHOD_NAME);
+ logParam(METHOD_NAME, "perPath", perPath);
+ List alist = null;
+ /*
+ PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
+ alist = xao.getApplications(perPath);
+ Iterator iter = alist.iterator();
+ while (iter.hasNext()) {
+ ApplicationTypeImpl app = (ApplicationTypeImpl) iter.next();
+ logVar(METHOD_NAME, "appId", app.getId());
+ }
+ logMethodEnd(METHOD_NAME, alist);
+ */
+ return alist;
+ }
+
+ /*
+ public ApplicationTypeImpl getPortletEntityRegistryApp(String perPath, String appId) {
+ final String METHOD_NAME = "getPortletEntityRegistryApp(perPath, appId)";
+ logMethodStart(METHOD_NAME);
+ logParam(METHOD_NAME, "perPath", perPath);
+ logParam(METHOD_NAME, "appId", appId);
+ ApplicationTypeImpl app = null;
+ PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
+ app = xao.getApplication(perPath, appId);
+ if (app != null) {
+ logDebug(METHOD_NAME, "looked up appId=" + app.getId());
+ }
+ logMethodEnd(METHOD_NAME, app);
+ return app;
+ }
+ */
+
+ public List getPortletPreferences(String perPath, String appId, String portletId ) {
+ final String METHOD_NAME = "getPortletPreferences(perPath,appId,portletId)";
+ logMethodStart(METHOD_NAME);
+ List list = null;
+ /*
+ PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
+ list = xao.getPortletPreferencesList(perPath, appId, portletId);
+ logMethodEnd(METHOD_NAME, list);
+*/
+ return list;
+ }
+
+ public List addPortletPreference(String perPath, String appId, String portletId ) {
+ final String METHOD_NAME = "addPortletPreferences(perPath,appId,portletId)";
+ logMethodStart(METHOD_NAME);
+ List list = null;
+ /*
+ list = getPortletPreferences(perPath, appId, portletId);
+ //create a new empty preference and add it
+ PreferencesTypeImpl pref = new PreferencesTypeImpl();
+ pref.setPrefName("");
+ pref.setPrefValue("");
+ pref.setReadOnly(false);
+ list.add(pref);
+ logMethodEnd(METHOD_NAME, list);
+ */
+ return list;
+ }
+
+/*
+ public PortletTypeImpl getNewPortlet(String perPath, String appId) {
+ final String METHOD_NAME = "getNewPortlet(perPath,appId,portletId)";
+ logMethodStart(METHOD_NAME);
+ PortletTypeImpl portlet = null;
+ PortletEntityRegistryXao xao = new PortletEntityRegistryXao();
+ ApplicationTypeImpl app = xao.getApplication(perPath, appId);
+ portlet.setDefinitionId("");
+ portlet.setId("");
+ logMethodEnd(METHOD_NAME, portlet);
+ return portlet;
+ }
+*/
+
+ public static String getNextAppId() {
+ final String METHOD_NAME = "getNextAppId()";
+ PlutoAdminLogger.logMethodStart(CLASS_NAME, METHOD_NAME);
+ String appId = null;
+ Collection apps;
+ try {
+ org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
+ new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
+ apps = xao.getApplications();
+ } catch (Exception e) {
+ PlutoAdminLogger.logError(CLASS_NAME, METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+ ArrayList list = new ArrayList(apps);
+ Iterator iter = list.iterator();
+ int nNewId = 0;
+ while (iter.hasNext()) {
+ PortletApplicationEntityImpl app = (PortletApplicationEntityImpl) iter.next();
+ String currAppId = app.getCastorId();
+ int nCurrAppId = Integer.parseInt(currAppId);
+ if (nNewId <= nCurrAppId) {
+ nNewId = nCurrAppId;
+ }
+ }
+ nNewId++;
+ appId = Integer.toString(nNewId);
+ PlutoAdminLogger.logMethodEnd(CLASS_NAME, METHOD_NAME, appId);
+ return appId;
+
+ }
+
+ public void getPortletEntityRegistry(RenderRequest request) {
+ final String METHOD_NAME = "getPortletEntityRegistry(request)";
+ logMethodStart(METHOD_NAME);
+ Collection alist = null;
+ try {
+ org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
+ new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
+ PortletApplicationEntityListImpl registry = xao.load();
+ alist = registry.getCastorApplications();
+ logDebug(METHOD_NAME, "App list: " + alist);
+ } catch (Exception e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+ //sort the collection
+ ArrayList slist = new ArrayList(alist);
+ Collections.sort(slist, new PortletApplicationEntityImplComparator());
+ Iterator iter = slist.iterator();
+ request.setAttribute(PlutoAdminConstants.PER_LIST_ATTR, iter);
+ logMethodEnd(METHOD_NAME, alist);
+ }
+
+ public void getPortletEntityRegistryApp(ActionRequest request) {
+ final String METHOD_NAME = "getPortletEntityRegistryApp(request)";
+ logMethodStart(METHOD_NAME);
+ String appId = request.getParameter("appid");
+ logDebug(METHOD_NAME, "AppId selected: " + appId);
+ PortletSession session = request.getPortletSession();
+ PortletApplicationEntityImpl app;
+ try {
+ org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
+ new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
+ app = xao.getApplication(appId);
+ } catch (Exception e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+ session.setAttribute(PlutoAdminConstants.APP_ATTR, app, PortletSession.APPLICATION_SCOPE);
+ logMethodEnd(METHOD_NAME);
+ }
+
+ public void getPortletPreferences(ActionRequest request) {
+ String METHOD_NAME = "getPortletPreferences(request)";
+ logMethodStart(METHOD_NAME);
+ String appId = request.getParameter("appId");
+ logDebug(METHOD_NAME, "AppId selected: " + appId);
+ String portletId = request.getParameter("portletId");
+ logDebug(METHOD_NAME, "PortletId selected: " + portletId);
+ List prefs = null;
+ try {
+ org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao xao =
+ new org.apache.pluto.portlet.admin.model.PortletEntityRegistryXao();
+ Collection coll = xao.getPortletPreferences(appId, portletId);
+ prefs = new ArrayList(coll);
+ } catch (Exception e) {
+ logError(METHOD_NAME, e);
+ throw new PlutoAdminException(e);
+ }
+ PortletSession session = request.getPortletSession();
+ Map map = (Map)session.getAttribute(PlutoAdminConstants.PREF_LIST_ATTR);
+ if (map == null) {
+ map = new HashMap();
+ }
+ map.put(portletId, prefs);
+ session.setAttribute(PlutoAdminConstants.PREF_LIST_ATTR, map, PortletSession.APPLICATION_SCOPE);
+ logMethodEnd(METHOD_NAME);
+ }
+}
Added: portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/taglib/MessageTag.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/taglib/MessageTag.java?view=auto&rev=154581
==============================================================================
--- portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/taglib/MessageTag.java (added)
+++ portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/taglib/MessageTag.java Sun Feb 20 16:30:14 2005
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2003,2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.portlet.admin.taglib;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletSession;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.pluto.Constants;
+import org.apache.pluto.portlet.admin.PlutoAdminConstants;
+import org.apache.pluto.portlet.admin.bean.PortletMessage;
+import org.apache.pluto.portlet.admin.bean.PortletMessageType;
+
+/**
+ * Tag to print an error, info, alert, status or success message in a portlet
+ * as defined by Cascading Syle Sheet classes in Appendix PLT C of the
+ * Java Portlet Specification (JSR-168) version 1.0 (pg 116).
+ * <p>
+ * This class uses the PortletMessage and PortletMessageType classes to
+ * encapsulates message information. It also can handle a Throwable
+ * put in the session (see below), using the getMessage() for the message
+ * and printing out the stack trace in an HTML comment. All messages are
+ * wrapped in a <p> element containing a 'class' attribute with a
+ * spec-defined CSS value, which assumes these are defined in a CSS style
+ * sheet used by the JSP page. Right now this class can only handle one
+ * message per JSP page.
+ * </p>
+ * <p>
+ * There are three ways a message can be displayed using this tag:<br/>
+ * 1. Use the tag's message attribute on the JSP page to set the message
+ * as a String or expression that evaluates to a String. Optionally, you
+ * can use the messageType attribute. Valid messageType attributes
+ * are info, error, status, success and alert. The default message
+ * type is status.<br/>
+ * 2. Put a message in the portlet session encapsulated in a PortletMessage
+ * object with a PlutoAdminConstants.MESSAGE_ATTR session key. This class
+ * takes care of getting the attribute from the session, using its message and
+ * type data and removing the session attribute.<br/>
+ * 3. Put a Throwable in the portlet session with a PlutoAdminConstants.ERROR_ATTR
+ * key. This class takes care of getting the attribute from the session,
+ * using its data and removing the session attribute. Throwables are always
+ * given a messageType of error.<br/>
+ * </p>
+ *
+ * @author Craig Doremus
+ * @see org.apache.pluto.portlet.admin.bean.PortletMessage
+ * @see org.apache.pluto.portlet.admin.bean.PortletMessageType
+ * @see org.apache.pluto.portlet.admin.PlutoAdminConstants
+ */
+public class MessageTag extends TagSupport {
+
+ private String message = null;
+ private String messageType = "status";
+ /* User-defined CSS class */
+ private String cssClass = "portlet-msg-info";
+
+ /************ JSR-168 defined CSS classes for messages ************/
+ /** CSS class for Error messages. Example: Portlet not available*/
+public static final String MSG_ERROR_CSS_CLASS = "portlet-msg-error";
+ /** CSS class for Help messages, general additional information, etc. Example: Info about */
+ public static final String MSG_INFO_CSS_CLASS = "portlet-msg-info";
+ /** CSS class for Status of the current operation. Example: Progress: 80% */
+ public static final String MSG_STATUS_CSS_CLASS = "portlet-msg-status";
+ /** CSS class for Warning messages. Example: Timeout occurred, try again later */
+ public static final String MSG_ALERT_CSS_CLASS = "portlet-msg-alert";
+ /** CSS class for Verification of the successful completion of a task. Example: Operation completed successfully */
+ public static final String MSG_SUCCESS_CSS_CLASS = "portlet-msg-success";
+ /* ************************************************************* */
+
+ /**
+ * Does the work of the tag.
+ */
+ public int doStartTag() throws JspException {
+
+ PortletRequest request = (PortletRequest)pageContext.getRequest().getAttribute(Constants.PORTLET_REQUEST);
+ PortletSession session = request.getPortletSession();
+ Throwable error = (Throwable)session.getAttribute(PlutoAdminConstants.ERROR_ATTR);
+ session.removeAttribute(PlutoAdminConstants.ERROR_ATTR);
+ PortletMessage oMsg = (PortletMessage)session.getAttribute(PlutoAdminConstants.MESSAGE_ATTR);
+ session.removeAttribute(PlutoAdminConstants.MESSAGE_ATTR);
+
+ try {
+ JspWriter out = pageContext.getOut();
+ if (message != null ) {
+ if (cssClass == null) {
+ cssClass = PortletMessageType.getTypeByName(messageType).CssClass;
+ }
+ out.print(wrapHtml(message, cssClass));
+ } else if (oMsg != null ) {
+ out.print(wrapHtml(oMsg.getMessage(), oMsg.getType().CssClass));
+ } else if (error != null ) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(error.getMessage());
+ if (error.getCause() != null) {
+ sb.append("<br>Underlying Exception cause: ");
+ sb.append(error.getCause().getMessage());
+ }
+ out.print(wrapHtml(sb.toString(), MSG_ERROR_CSS_CLASS));
+ //print out the stack trace in an HTML comment
+ out.println("<!-- " + PlutoAdminConstants.LS);
+ PrintWriter writer = new PrintWriter(out, true);
+ error.printStackTrace(writer);
+ out.print(PlutoAdminConstants.LS + "-->");
+ }
+ } catch (IOException e) {
+ throw new JspTagException("Error in tag MessageTag: " + e.toString());
+ }
+ return SKIP_BODY;
+ }
+
+ private String wrapHtml(String msg, String css){
+ StringBuffer sb = new StringBuffer();
+ sb.append("<p class=\"" + css + "\">");
+ sb.append(msg);
+ sb.append("</p>");
+ return sb.toString();
+ }
+
+ /**
+ * @param message The error message
+ */
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ /**
+ * @param cssClass The cssClass to set.
+ */
+ public void setCssClass(String cssClass) {
+ this.cssClass = cssClass;
+ }
+ /**
+ * @param messageType The messageType to set.
+ */
+ public void setMessageType(String messageType) {
+ this.messageType = messageType;
+ }
+}
Added: portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/taglib/PortletSelectTag.java
URL: http://svn.apache.org/viewcvs/portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/taglib/PortletSelectTag.java?view=auto&rev=154581
==============================================================================
--- portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/taglib/PortletSelectTag.java (added)
+++ portals/pluto/trunk/portal/src/java/org/apache/pluto/portlet/admin/taglib/PortletSelectTag.java Sun Feb 20 16:30:14 2005
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2003,2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pluto.portlet.admin.taglib;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletSession;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.apache.pluto.Constants;
+import org.apache.pluto.portlet.admin.PlutoAdminConstants;
+import org.apache.pluto.portlet.admin.bean.PortletTO;
+
+/**
+ * Taglib that creates an HTML select control containing portlet
+ * names and values as defined in the <code>PortletTO</code>
+ * class.
+ *
+ * @author Craig Doremus
+ * @see org.apache.pluto.portlet.admin.bean.PortletTO
+ *
+ */
+public class PortletSelectTag extends TagSupport {
+
+ private Map portletMap = null;
+ private int row = 1;
+ private int column = 1;
+
+ public int doStartTag() throws JspException {
+ PortletRequest request = (PortletRequest)pageContext.getRequest().getAttribute(Constants.PORTLET_REQUEST);
+ PortletSession session = request.getPortletSession();
+ List portlets = (List)session.getAttribute(PlutoAdminConstants.PORTLET_APP_LIST_ATTR);
+
+ if (portletMap != null ) {
+ try {
+ JspWriter out = pageContext.getOut();
+ out.println("<select name=\"portlet" + row + "." + column + "\">");
+ Set vals = portletMap.entrySet();
+ Iterator iter = vals.iterator();
+ while (iter.hasNext()) {
+ Map.Entry item = (Map.Entry) iter.next();
+ String name = (String)item.getKey();
+ String val = (String)item.getValue();
+ out.print("<option value=\"" + name + "_" + val + "\"");
+ //find out what portlet should be the 'checked' one
+ if (portlets != null) {
+ Iterator iter2 = portlets.iterator();
+ while(iter.hasNext()) {
+ PortletTO plet = (PortletTO)iter2.next();
+ int currrow = plet.getRow();
+ int currcol = plet.getCol();
+ if (row == currrow && column == currcol) {
+ out.print(" checked ");
+ break;
+ }
+ }
+ }
+ out.print(">");
+ out.print(name);
+ out.print("</option>");
+ }
+ out.println("</select>");
+ } catch (IOException e) {
+ throw new JspTagException("Error: " + e.toString());
+ }
+ }
+ return SKIP_BODY;
+ }
+
+ /**
+ * @param portletMap The portletMap to set.
+ */
+ public void setPortletMap(Map portletMap) {
+ this.portletMap = portletMap;
+ }
+ /**
+ * @param column The column to set.
+ */
+ public void setColumn(int column) {
+ this.column = column;
+ }
+ /**
+ * @param row The row to set.
+ */
+ public void setRow(int row) {
+ this.row = row;
+ }
+}