You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2004/08/03 07:08:23 UTC
cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager FileSystemPAM.java
taylor 2004/08/02 22:08:23
Modified: portal/src/java/org/apache/jetspeed/tools/pamanager
FileSystemPAM.java
Log:
added api to register (but not deploy) a PA
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.39 +163 -1 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/FileSystemPAM.java
Index: FileSystemPAM.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/FileSystemPAM.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- FileSystemPAM.java 1 Aug 2004 15:49:18 -0000 1.38
+++ FileSystemPAM.java 3 Aug 2004 05:08:23 -0000 1.39
@@ -18,9 +18,14 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.util.Iterator;
import java.util.prefs.Preferences;
+import javax.servlet.ServletContext;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jetspeed.cache.PortletCache;
@@ -36,7 +41,11 @@
import org.apache.jetspeed.util.ArgUtil;
import org.apache.jetspeed.util.DirectoryHelper;
import org.apache.jetspeed.util.FileSystemHelper;
+import org.apache.jetspeed.util.descriptor.ExtendedPortletMetadata;
+import org.apache.jetspeed.util.descriptor.MetaDataException;
+import org.apache.jetspeed.util.descriptor.PortletApplicationDescriptor;
import org.apache.jetspeed.util.descriptor.PortletApplicationWar;
+import org.apache.jetspeed.util.descriptor.WebApplicationDescriptor;
import org.apache.pluto.om.entity.PortletEntity;
import org.apache.pluto.om.portlet.PortletDefinition;
@@ -612,6 +621,159 @@
return true;
}
+ public boolean registerPortletApplication(String portletApplicationName, String contextName, ServletContext context)
+ throws
+ RegistryException
+ {
+ MutablePortletApplication app;
+ PersistenceStore store = registry.getPersistenceStore();
+
+ try
+ {
+ app = createPortletApp(portletApplicationName, context);
+ if (app == null)
+ {
+ String msg = "Error loading portlet.xml: ";
+ log.error(msg);
+ throw new RegistryException(msg);
+ }
+
+ app.setApplicationType(MutablePortletApplication.WEBAPP);
+ //app.setChecksum(checksum);
+
+ // load the web.xml
+ log.info("Loading web.xml into memory...."
+ + portletApplicationName);
+ MutableWebApplication webapp = createWebApp(contextName, context);
+ app.setWebApplicationDefinition(webapp);
+
+ // save it to the registry
+ log.info("Saving the portlet.xml in the registry..."
+ + portletApplicationName);
+ store.getTransaction().begin();
+ registry.registerPortletApplication(app);
+ log.info("Committing registry changes..." + portletApplicationName);
+ store.getTransaction().commit();
+ }
+ catch (Exception e)
+ {
+ String msg = "Unable to register portlet application, " + portletApplicationName
+ + ", through the portlet registry: " + e.toString();
+ log.error(msg, e);
+ store.getTransaction().rollback();
+ throw new RegistryException(msg, e);
+ }
+
+ return true;
+ }
+ public MutableWebApplication createWebApp(String contextName, ServletContext context)
+ throws
+ PortletApplicationException,
+ IOException
+ {
+ MutableWebApplication webApp = null;
+ Reader webXmlReader = null;
+ InputStream is = null;
+
+ try
+ {
+ is = context.getResourceAsStream("WEB-INF/web.xml");
+ if (is == null)
+ {
+ throw new PortletApplicationException("Failed to find Web XML");
+ }
+
+ webXmlReader = new InputStreamReader(is);
+ WebApplicationDescriptor webAppDescriptor = new WebApplicationDescriptor(webXmlReader, contextName);
+ webApp = webAppDescriptor.createWebApplication();
+ return webApp;
+ }
+
+ finally
+ {
+ try
+ {
+ if (is != null)
+ {
+ is.close();
+ }
+ if (webXmlReader != null)
+ {
+ webXmlReader.close();
+ }
+ }
+ catch (IOException e1)
+ {
+ e1.printStackTrace();
+ }
+ }
+
+ }
+ public MutablePortletApplication createPortletApp(String paName, ServletContext context)
+ throws
+ PortletApplicationException,
+ IOException
+ {
+ Reader portletXmlReader = null;
+ MutablePortletApplication portletApp = null;
+ InputStream is = null;
+
+
+
+ try
+ {
+ is = context.getResourceAsStream("WEB-INF/portlet.xml");
+ if (is == null)
+ {
+ throw new PortletApplicationException("Failed to find Portlet XML");
+ }
+ portletXmlReader = new InputStreamReader(is);
+
+ PortletApplicationDescriptor paDescriptor = new PortletApplicationDescriptor(portletXmlReader, paName);
+ portletApp = paDescriptor.createPortletApplication();
+ // validate(portletApplication);
+ /*
+ Reader extMetaDataXml = null;
+ try
+ {
+ extMetaDataXml = getReader(EXTENDED_PORTLET_XML_PATH);
+ if (extMetaDataXml != null)
+ {
+ ExtendedPortletMetadata extMetaData = new ExtendedPortletMetadata(extMetaDataXml, portletApp);
+ extMetaData.load();
+ }
+ }
+ catch (IOException e)
+ {
+ log.info("Did not load exteneded metadata as it most likely does not exist. " + e.toString());
+ }
+ catch (MetaDataException e)
+ {
+ log.warn("Failed to load existing metadata. " + e.toString(), e);
+ }
+ finally
+ {
+ if (null != extMetaDataXml)
+ {
+ extMetaDataXml.close();
+ }
+ }
+*/
+ return portletApp;
+ }
+ finally
+ {
+ if (is != null)
+ {
+ is.close();
+ }
+ if (portletXmlReader != null)
+ {
+ portletXmlReader.close();
+ }
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org