weaver 2003/10/17 13:01:38
Modified: portal/src/java/org/apache/jetspeed/tools/pamanager
PortletDescriptorUtilities.java
Log:
replaced Castor login with commons digester
Revision Changes Path
1.2 +126 -25
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/PortletDescriptorUtilities.java
Index: PortletDescriptorUtilities.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/PortletDescriptorUtilities.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PortletDescriptorUtilities.java 28 Jul 2003 23:47:53 -0000 1.1
+++ PortletDescriptorUtilities.java 17 Oct 2003 20:01:38 -0000 1.2
@@ -53,21 +53,30 @@
*/
package org.apache.jetspeed.tools.pamanager;
-import java.io.FileReader;
import java.io.File;
+import java.io.FileReader;
import java.util.Iterator;
-import org.exolab.castor.mapping.Mapping;
-import org.exolab.castor.xml.Unmarshaller;
-import org.xml.sax.InputSource;
+import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jetspeed.Jetspeed;
import org.apache.jetspeed.PortalContext;
-
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
-import org.apache.pluto.om.portlet.PortletDefinitionList;
+import org.apache.jetspeed.om.impl.DescriptionImpl;
+import org.apache.jetspeed.om.impl.DisplayNameImpl;
+import org.apache.jetspeed.om.impl.LanguageImpl;
+import org.apache.jetspeed.om.impl.PortletInitParameterImpl;
+import org.apache.jetspeed.om.impl.SecurityRoleRefImpl;
+import org.apache.jetspeed.om.portlet.impl.ContentTypeImpl;
+import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl;
+import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
+import org.apache.jetspeed.om.preference.impl.DefaultPreferenceImpl;
import
org.apache.jetspeed.tools.castor.om.common.portlet.PortletDefinitionDescriptor;
+import org.apache.pluto.om.portlet.PortletDefinitionList;
+import org.exolab.castor.mapping.Mapping;
+import org.exolab.castor.xml.Unmarshaller;
+import org.xml.sax.InputSource;
/**
* Utilities for manipulating the Portlet.xml deployment descriptor
@@ -80,12 +89,12 @@
public class PortletDescriptorUtilities
{
protected final static Log log =
LogFactory.getLog(PortletDescriptorUtilities.class);
-
+
public static final String XML_MAPPING_FILE =
"deployment.descriptor.mapping.xml";
-
+
/**
* Load a portlet.xml file into a Portlet Application tree
- *
+ * @deprecated use loadPortletDescriptor
* @param pathPortletXML The path to the portlet.xml file
* @return Application The Java object tree representing portlet.xml
*/
@@ -94,14 +103,13 @@
{
try
{
- Mapping mapping = loadMapping();
+ Mapping mapping = loadMapping();
java.io.FileReader reader = new java.io.FileReader(pathPortletXML);
-
+
Unmarshaller unmarshaller = new Unmarshaller(mapping);
-
- MutablePortletApplication app =
- (MutablePortletApplication) unmarshaller.unmarshal(reader);
-
+
+ MutablePortletApplication app = (MutablePortletApplication)
unmarshaller.unmarshal(reader);
+
// Post-Processing of the tree before it gets saved to the database
// 1) Set the URL for the application
@@ -110,7 +118,7 @@
// 2) The app ID in the portlet.xml is optional. Set it to the
// application Name if it was not defined
-
+
app.setName(appName);
// More post-processing comes here
@@ -119,10 +127,10 @@
int count = 0;
while (it.hasNext())
{
- PortletDefinitionDescriptor portlet =
(PortletDefinitionDescriptor)it.next();
+ PortletDefinitionDescriptor portlet = (PortletDefinitionDescriptor)
it.next();
portlet.postLoad(null);
}
-
+
return app;
}
catch (Throwable t)
@@ -132,21 +140,20 @@
throw new PortletApplicationException(msg, t);
}
}
-
+
/**
* Loads the Castor XML Mapping file from the configuration directory
* with instructions for mapping portlet.xml to Portlet Application tree
*
* @return Mapping The Castor mapping directives
*/
- private static Mapping loadMapping()
- throws Exception
+ private static Mapping loadMapping() throws Exception
{
Mapping mapping = null;
PortalContext pc = Jetspeed.getContext();
String mappingFile = pc.getConfigurationProperty(XML_MAPPING_FILE);
String realPath = Jetspeed.getRealPath(mappingFile);
-
+
File map = new File(realPath);
if (map.exists() && map.isFile() && map.canRead())
{
@@ -160,7 +167,101 @@
String msg = "Mapping not found or not a file or unreadable: " +
mappingFile;
throw new PortletApplicationException(msg);
}
-
- return mapping;
+
+ return mapping;
}
+
+ /**
+ * Load a portlet.xml file into a Portlet Application tree
+ *
+ * @param pathPortletXML The path to the portlet.xml file
+ * @return Application The Java object tree representing portlet.xml
+ */
+ public static MutablePortletApplication loadPortletDescriptor(String
pathPortletXML, String appName)
+ throws PortletApplicationException
+ {
+ try
+ {
+
+ FileReader reader = new java.io.FileReader(pathPortletXML);
+
+ // TODO move config to digester-rules.xml. Example:
http://www.onjava.com/pub/a/onjava/2002/10/23/digester.html?page=3
+ Digester digester = new Digester();
+ digester.setValidating(false);
+ digester.addObjectCreate("portlet-app",
PortletApplicationDefinitionImpl.class);
+ digester.addSetProperties("portlet-app", "id", "applicationIdentifier");
+
+ digester.addObjectCreate("portlet-app/portlet",
PortletDefinitionImpl.class);
+ digester.addSetProperties("portlet-app/portlet", "id",
"portletIdentifier");
+ digester.addBeanPropertySetter("portlet-app/portlet/portlet-name",
"name");
+ digester.addBeanPropertySetter("portlet-app/portlet/portlet-class",
"className");
+ digester.addBeanPropertySetter("portlet-app/portlet/expiration-cache",
"expirationCache");
+ digester.addSetNext("portlet-app/portlet", "addPortletDefinition");
+
+ digester.addObjectCreate("portlet-app/portlet/display-name",
DisplayNameImpl.class);
+ digester.addSetProperties("portlet-app/portlet/display-name", "lang",
"language");
+ digester.addBeanPropertySetter("portlet-app/portlet/display-name",
"displayName");
+ digester.addSetNext("portlet-app/portlet/display-name",
"addDisplayName");
+
+ digester.addObjectCreate("portlet-app/portlet/description",
DescriptionImpl.class);
+ digester.addSetProperties("portlet-app/portlet/description", "lang",
"language");
+ digester.addBeanPropertySetter("portlet-app/portlet/description",
"description");
+ digester.addSetNext("portlet-app/portlet/description",
"addDescription");
+
+ digester.addObjectCreate("portlet-app/portlet/init-param",
PortletInitParameterImpl.class);
+ digester.addBeanPropertySetter("portlet-app/portlet/init-param/name",
"name");
+ digester.addBeanPropertySetter("portlet-app/portlet/init-param/value",
"value");
+ digester.addSetNext("portlet-app/portlet/init-param",
"addInitParameter");
+
+ digester.addObjectCreate("portlet-app/portlet/init-param/description",
DescriptionImpl.class);
+ digester.addSetProperties("portlet-app/portlet/init-param/description",
"lang", "language");
+
digester.addBeanPropertySetter("portlet-app/portlet/init-param/description",
"description");
+ digester.addSetNext("portlet-app/portlet/init-param/description",
"addDescription");
+
+ digester.addObjectCreate("portlet-app/portlet/supports",
ContentTypeImpl.class);
+
digester.addBeanPropertySetter("portlet-app/portlet/supports/mime-type",
"contentType");
+ digester.addCallMethod("portlet-app/portlet/supports/portlet-mode",
"addPortletMode", 0);
+ digester.addSetNext("portlet-app/portlet/supports", "addContentType");
+
+ digester.addObjectCreate("portlet-app/portlet/portlet-info",
LanguageImpl.class);
+
digester.addBeanPropertySetter("portlet-app/portlet/portlet-info/title", "title");
+
digester.addBeanPropertySetter("portlet-app/portlet/portlet-info/short-title",
"shortTitle");
+ digester.addCallMethod("portlet-app/portlet/portlet-info/keywords",
"setKeywords", 0, new Class[]{String.class});
+ digester.addSetNext("portlet-app/portlet/portlet-info", "addLanguage");
+
+
digester.addObjectCreate("portlet-app/portlet/portlet-preferences/preference",
DefaultPreferenceImpl.class);
+
digester.addBeanPropertySetter("portlet-app/portlet/portlet-preferences/preference/name",
"name");
+
digester.addCallMethod("portlet-app/portlet/portlet-preferences/preference/value",
"addValue", 0);
+ digester.addCallMethod(
+ "portlet-app/portlet/portlet-preferences/preference/read-only",
+ "setReadOnly",
+ 0,
+ new Class[] { Boolean.class });
+
digester.addSetNext("portlet-app/portlet/portlet-preferences/preference",
"addPreference");
+
+ digester.addObjectCreate("portlet-app/portlet/security-role-ref",
SecurityRoleRefImpl.class);
+
digester.addBeanPropertySetter("portlet-app/portlet/security-role-ref/role-name",
"roleName");
+
digester.addBeanPropertySetter("portlet-app/portlet/security-role-ref/role-link",
"roleLink");
+ digester.addSetNext("portlet-app/portlet/security-role-ref",
"addSecurityRoleRef");
+
+
digester.addObjectCreate("portlet-app/portlet/security-role-ref/description",
DescriptionImpl.class);
+
digester.addSetProperties("portlet-app/portlet/security-role-ref/description", "lang",
"language");
+
digester.addBeanPropertySetter("portlet-app/portlet/security-role-ref/description",
"description");
+
digester.addSetNext("portlet-app/portlet/security-role-ref/description",
"addDescription");
+
+ // PortletApplicationDefinitionImpl pd =
(PortletApplicationDefinitionImpl) beanReader.parse(reader);
+ PortletApplicationDefinitionImpl pd =
(PortletApplicationDefinitionImpl) digester.parse(reader);
+
+ pd.setName(appName);
+ return pd;
+
+ }
+ catch (Throwable t)
+ {
+ String msg = "Could not unmarshal: " + pathPortletXML;
+ log.error(msg, t);
+ throw new PortletApplicationException(msg, t);
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]