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 at...@apache.org on 2008/10/15 02:01:11 UTC

svn commit: r704743 [6/7] - in /portals/pluto/branches/2.0-spi-refactoring: ./ pluto-container-api/src/main/java/org/apache/pluto/ pluto-container-api/src/main/java/org/apache/pluto/om/ pluto-container-api/src/main/java/org/apache/pluto/om/common/ plut...

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-descriptor-impl/src/test/java/org/apache/pluto/descriptors/services/jaxb/JaxBDescriptorServiceImplTest.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-descriptor-impl/src/test/java/org/apache/pluto/descriptors/services/jaxb/JaxBDescriptorServiceImplTest.java?rev=704743&r1=704742&r2=704743&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-descriptor-impl/src/test/java/org/apache/pluto/descriptors/services/jaxb/JaxBDescriptorServiceImplTest.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-descriptor-impl/src/test/java/org/apache/pluto/descriptors/services/jaxb/JaxBDescriptorServiceImplTest.java Tue Oct 14 17:01:07 2008
@@ -75,10 +75,8 @@
 				"<name>name</name>\n" +
 				"<value>value</value>\n" +
 				"</init-param>\n" +
-				"<expiration-cache id=\"exp1\">\n" +
-				" <expiration-time>-1</expiration-time>\n" +
-				"<scope>scope</scope>\n" +
-				"</expiration-cache>\n" +
+				"<expiration-cache>100</expiration-cache>\n" +
+				"<cache-scope>private</cache-scope>\n" +
 				" <supports id=\"sup1\">\n" +
 				"<mime-type>mime-type</mime-type>\n" +
 				"<portlet-mode>portlet-mode</portlet-mode>\n" +
@@ -197,9 +195,7 @@
 				"<name>name</name>\n" +
 				"<value>value</value>\n" +
 				"</init-param>\n" +
-				"<expiration-cache id=\"exp1\">\n" +
-				"-1" +
-				"</expiration-cache>\n" +
+				"<expiration-cache>50</expiration-cache>\n" +
 				" <supports id=\"sup1\">\n" +
 				"<mime-type>mime-type</mime-type>\n" +
 				"<portlet-mode>portlet-mode</portlet-mode>\n" +
@@ -256,7 +252,6 @@
 			      "<transport-guarantee>NONE</transport-guarantee>\n" +
 			    "</user-data-constraint>\n" +
 			  "</security-constraint>\n" +
-			  "<resource-bundle>resource-bundle</resource-bundle>\n" +
 		"" );
 
         portletNoCache.append(
@@ -322,19 +317,20 @@
 			
 			// test jsr168 compliant portlets
 			Portlet portlet168 = (Portlet)portletApp168.getPortlets().get(0);
-			assertTrue(portlet168.getExpirationCache().getExpirationTime()==-1);
+			assertTrue(portlet168.getExpirationCache()==50);
 			assertEquals(portlet168.getPortletName(),"portlet168");
 			assertEquals(portlet168.getInitParams().get(0).getParamValue(),"value");
 			assertEquals(portlet168.getSecurityRoleRefs().get(0).getRoleLink(), "role-link");
-			assertEquals(portletApp168.getCustomPortletMode().get(0).getPortletMode(), "portlet-mode");
-			assertEquals(portletApp168.getCustomWindowState().get(0).getWindowState(), "window-state");
-			assertEquals(portletApp168.getUserAttribute().get(0).getName(), "name" );
-			assertEquals(portletApp168.getSecurityConstraint().get(0).getPortletCollection().getPortletName().get(0), "portlet-name");
-			
+			assertEquals(portletApp168.getCustomPortletModes().get(0).getPortletMode(), "portlet-mode");
+			assertEquals(portletApp168.getCustomWindowStates().get(0).getWindowState(), "window-state");
+			assertEquals(portletApp168.getUserAttributes().get(0).getName(), "name" );
+			assertEquals(portletApp168.getSecurityConstraints().get(0).getPortletCollection().getPortletNames().get(0), "portlet-name");
+			assertEquals(portlet168.getExpirationCache(), 50);
 			// id (isn't supported yet)
 //			assertFalse(portletApp.getId().equals("id2"));
 //			assertTrue(portletApp.getId().equals("id1"));
 			
+			jaxb.write(portletApp168, System.out);
 			// portlet id
 			Portlet portlet286 = (Portlet)portletApp286.getPortlets().get(0);
 //			assertTrue(portlet1.getId().equals("id2"));
@@ -349,26 +345,28 @@
 			
 			assertEquals("supports size should be 3", 3, portlet286.getSupports().size());
 			
-			assertEquals(portletApp286.getCustomPortletMode().get(0).getPortletMode(), "portlet-mode");
-			assertEquals(portletApp286.getCustomWindowState().get(0).getWindowState(), "window-state");
-			assertEquals(portletApp286.getUserAttribute().get(0).getName(), "name" );
-			assertEquals(portletApp286.getSecurityConstraint().get(0).getPortletCollection().getPortletName().get(0), "portlet-name");
-			assertEquals(portletApp286.getEvents().get(0).getJavaClass(), "java-class");
+			assertEquals(portletApp286.getCustomPortletModes().get(0).getPortletMode(), "portlet-mode");
+			assertEquals(portletApp286.getCustomWindowStates().get(0).getWindowState(), "window-state");
+			assertEquals(portletApp286.getUserAttributes().get(0).getName(), "name" );
+			assertEquals(portletApp286.getSecurityConstraints().get(0).getPortletCollection().getPortletNames().get(0), "portlet-name");
+			assertEquals(portletApp286.getEventDefinitions().get(0).getValueType(), "java-class");
 //			assertEquals(portletApp286.getRender().get(0).getName(), "QName");
-			assertEquals(portletApp286.getFilter().get(0).getLifecycle().get(0), "lifecycle");
-			assertEquals(portletApp286.getFilterMapping().get(0).getPortletName().get(0), "portlet-name");
+			assertEquals(portletApp286.getFilters().get(0).getLifecycles().get(0), "lifecycle");
+			assertEquals(portletApp286.getFilterMappings().get(0).getPortletNames().get(0), "portlet-name");
 			assertEquals(portletApp286.getResourceBundle(), "resource-bundle");
 			assertEquals(portletApp286.getVersion(), "2.0");
 			
 			// test container runtime options
-			assertEquals(portletApp286.getContainerRuntimeOption().size(),1);
-			assertEquals(portletApp286.getContainerRuntimeOption().get(0).getName(),"Runtime-Option-Portlet-App");
-			assertEquals(portletApp286.getContainerRuntimeOption().get(0).getValue().get(0),"false");
-			
-			assertEquals(portlet286.getContainerRuntimeOption().size(),1);
-			assertEquals(portlet286.getContainerRuntimeOption().get(0).getName(),"Runtime-Option");
-			assertEquals(portlet286.getContainerRuntimeOption().get(0).getValue().get(0),"true");
+			assertEquals(portletApp286.getContainerRuntimeOptions().size(),1);
+			assertEquals(portletApp286.getContainerRuntimeOptions().get(0).getName(),"Runtime-Option-Portlet-App");
+			assertEquals(portletApp286.getContainerRuntimeOptions().get(0).getValues().get(0),"false");
+			
+			assertEquals(portlet286.getContainerRuntimeOptions().size(),1);
+			assertEquals(portlet286.getContainerRuntimeOptions().get(0).getName(),"Runtime-Option");
+			assertEquals(portlet286.getContainerRuntimeOptions().get(0).getValues().get(0),"true");
+            assertEquals(portlet286.getExpirationCache(), 100);
 			
+            jaxb.write(portletApp286, System.out);
 			
 		} catch (IOException e) {
 			fail("exception was thrown");
@@ -400,7 +398,7 @@
         assertEquals( 1, portletDD.getPortlets().size() );
 
         Portlet pd = (Portlet) portletDD.getPortlets().get( 0 );
-        assertNull( pd.getExpirationCache() );
+        assertEquals( pd.getExpirationCache(), 0 );
     }
 
     public void testParseNoExpirationCache286() throws IOException {
@@ -411,7 +409,7 @@
         assertEquals( 1, portletDD.getPortlets().size() );
 
         Portlet pd = (Portlet) portletDD.getPortlets().get( 0 );
-        assertNull( pd.getExpirationCache() );
+        assertEquals( pd.getExpirationCache(), 0 );
     }
 
 }

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventProviderImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventProviderImpl.java?rev=704743&r1=704742&r2=704743&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventProviderImpl.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventProviderImpl.java Tue Oct 14 17:01:07 2008
@@ -31,7 +31,6 @@
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.xml.XMLConstants;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
@@ -56,6 +55,7 @@
 import org.apache.pluto.driver.url.impl.PortalURLParserImpl;
 import org.apache.pluto.internal.impl.EventImpl;
 import org.apache.pluto.om.portlet.EventDefinition;
+import org.apache.pluto.om.portlet.EventDefinitionReference;
 import org.apache.pluto.om.portlet.Portlet;
 import org.apache.pluto.om.portlet.PortletApp;
 import org.apache.pluto.spi.EventProvider;
@@ -272,54 +272,41 @@
 				List<Portlet> portletDDs = portletAppDD.getPortlets();
 				List<QName> aliases = getAllAliases(eventName, portletAppDD);
 				for (Portlet portletDD : portletDDs) {
-					List<QName> processingEvents = portletDD
-							.getProcessingEvents();
-					if ((processingEvents != null)
-							&& processingEvents.contains(eventName)) {
-						if (portletDD.getPortletName().equals(
-								portlet.getPortletName())) {
-							resultSet.add(portlet.getId());
-						}
+					List<EventDefinitionReference> processingEvents = portletDD.getSupportedProcessingEvents();
+					if (isEventSupported(processingEvents, eventName, portletAppDD.getDefaultNamespace())) {
+                        if (portletDD.getPortletName().equals(portlet.getPortletName())) {
+                                                          resultSet.add(portlet.getId());
+                        }
 					} else {
 
 						if (processingEvents != null) {
-							for (QName name : processingEvents) {
+							for (EventDefinitionReference ref : processingEvents) {
+							    QName name = ref.getQualifiedName(portletAppDD.getDefaultNamespace());
+							    if (name == null)
+							    {
+							        continue;
+							    }
 								// add also grouped portlets, that ends with "."
 								if (name.toString().endsWith(".")
-										&& eventName.toString().startsWith(
-												name.toString())
-										&& portletDD.getPortletName().equals(
-												portlet.getPortletName())) {
+										&& eventName.toString().startsWith(name.toString())
+										&& portletDD.getPortletName().equals(portlet.getPortletName())) {
 									resultSet.add(portlet.getId());
 								}
 								// also look for alias names:
 								if (aliases != null) {
 									for (QName alias : aliases) {
-										if (alias.toString().equals(
-												name.toString())
-												&& portletDD
-														.getPortletName()
-														.equals(
-																portlet
-																		.getPortletName())) {
+										if (alias.toString().equals(name.toString())
+												&& portletDD.getPortletName().equals(portlet.getPortletName())) {
 											resultSet.add(portlet.getId());
 										}
 									}
 								}
 								// also look for default namespaced events
-								if (name.getNamespaceURI() == null
-										|| name.getNamespaceURI().equals("")) {
-									String defaultNamespace = portletAppDD
-											.getDefaultNamespace();
-									QName qname = new QName(defaultNamespace,
-											name.getLocalPart());
-									if (eventName.toString().equals(
-											qname.toString())
-											&& portletDD
-													.getPortletName()
-													.equals(
-															portlet
-																	.getPortletName())) {
+								if (name.getNamespaceURI() == null || name.getNamespaceURI().equals("")) {
+									String defaultNamespace = portletAppDD.getDefaultNamespace();
+									QName qname = new QName(defaultNamespace, name.getLocalPart());
+									if (eventName.toString().equals(qname.toString())
+											&& portletDD.getPortletName().equals(portlet.getPortletName())) {
 										resultSet.add(portlet.getId());
 									}
 								}
@@ -338,19 +325,30 @@
 		}
 		return resultList;
 	}
+	
+	private boolean isEventSupported(List<EventDefinitionReference> supportedEvents, QName eventName, String defaultNamespace)
+	{
+	    if (supportedEvents != null)
+	    {
+	        for (EventDefinitionReference ref : supportedEvents)
+	        {
+	            QName refQName = ref.getQualifiedName(defaultNamespace);
+	            if (refQName != null && refQName.equals(eventName))
+	            {
+	                return true;
+	            }
+	        }
+	    }
+	    return false;
+	}
 
 	private List<QName> getAllAliases(QName eventName, PortletApp portletAppDD) {
-		if (portletAppDD.getEvents() != null) {
+		if (portletAppDD.getEventDefinitions() != null) {
 			
-			for (EventDefinition def : portletAppDD.getEvents()){
-				if (def.getQName() != null){
-					if (def.getQName().equals(eventName))
-						return def.getAlias();
-				}
-				else{
-					QName tmp = new QName(portletAppDD.getDefaultNamespace(),def.getName());
-					if (tmp.equals(eventName))
-						return def.getAlias();
+			for (EventDefinition def : portletAppDD.getEventDefinitions()){
+			    QName defQName = def.getQualifiedName(portletAppDD.getDefaultNamespace());
+				if (defQName != null && defQName.equals(eventName)){
+						return def.getAliases();
 				}
 			}
 		}
@@ -514,22 +512,20 @@
 					.getAttribute(AttributeKeys.PORTLET_CONTAINER))
 					.getOptionalContainerServices().getPortletRegistryService();
 		}
-		List<QName> events = null;
+		List<EventDefinitionReference> events = null;
 		try {
 			events = portletRegistry.getPortlet(applicationId,
-					portletName).getPublishingEvents();
+					portletName).getSupportedPublishingEvents();
 		} catch (PortletContainerException e1) {
 			e1.printStackTrace();
 		}
 		if (events != null) {
             String defaultNamespace = portletWindow.getPortletEntity().getPortletDefinition().getApplication().getDefaultNamespace();
-            if (defaultNamespace == null) {
-                defaultNamespace = XMLConstants.NULL_NS_URI;
-            }
-            for (QName name : events) {
-                String namespaceURI = name.getNamespaceURI();
-                if (XMLConstants.NULL_NS_URI.equals(namespaceURI)) {
-                    name = new QName(defaultNamespace, name.getLocalPart());
+            for (EventDefinitionReference ref : events) {
+                QName name = ref.getQualifiedName(defaultNamespace);
+                if (name == null)
+                {
+                    continue;
                 }
                 if (qname.equals(name)) {
                     return true;
@@ -542,7 +538,7 @@
 	private boolean isValueInstanceOfDefinedClass(QName qname,
 			Serializable value) {
         PortletApp app = portletWindow.getPortletEntity().getPortletDefinition().getApplication();
-        List<EventDefinition> events = app.getEvents();
+        List<EventDefinition> events = app.getEventDefinitions();
         if (events != null) {
             
             
@@ -550,13 +546,13 @@
                 if (def.getQName() != null){
                     if (def.getQName().equals(qname))
                         return value.getClass().getName().equals(
-                                def.getJavaClass());
+                                def.getValueType());
                 }
                 else{
                     QName tmp = new QName(app.getDefaultNamespace(),def.getName());
                     if (tmp.equals(qname))
                         return value.getClass().getName().equals(
-                                def.getJavaClass());
+                                def.getValueType());
                 }
             }
         }

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/FilterChainImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/FilterChainImpl.java?rev=704743&r1=704742&r2=704743&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/FilterChainImpl.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/FilterChainImpl.java Tue Oct 14 17:01:07 2008
@@ -101,7 +101,7 @@
 			filterListIndex++;
 			try {
 				ActionFilter actionFilter = (ActionFilter) loader.loadClass(filter.getFilterClass()).newInstance();
-				FilterConfigImpl filterConfig = new FilterConfigImpl(filter.getFilterName(),filter.getInitParam(),portletContext);
+				FilterConfigImpl filterConfig = new FilterConfigImpl(filter.getFilterName(),filter.getInitParams(),portletContext);
 				actionFilter.init(filterConfig);
 				actionFilter.doFilter(request, response, this);
 				actionFilter.destroy();
@@ -124,7 +124,7 @@
 			filterListIndex++;
 			try {
 				EventFilter eventFilter = (EventFilter) loader.loadClass(filter.getFilterClass()).newInstance();
-				FilterConfigImpl filterConfig = new FilterConfigImpl(filter.getFilterName(),filter.getInitParam(),portletContext);
+				FilterConfigImpl filterConfig = new FilterConfigImpl(filter.getFilterName(),filter.getInitParams(),portletContext);
 				eventFilter.init(filterConfig);
 				eventFilter.doFilter(request, response, this);
 				eventFilter.destroy();
@@ -147,7 +147,7 @@
 			filterListIndex++;
 			try {
 				RenderFilter renderFilter = (RenderFilter) loader.loadClass(filter.getFilterClass()).newInstance();
-				FilterConfigImpl filterConfig = new FilterConfigImpl(filter.getFilterName(),filter.getInitParam(),portletContext);
+				FilterConfigImpl filterConfig = new FilterConfigImpl(filter.getFilterName(),filter.getInitParams(),portletContext);
 				renderFilter.init(filterConfig);
 				renderFilter.doFilter(request, response, this);
 				renderFilter.destroy();
@@ -170,7 +170,7 @@
 			filterListIndex++;
 			try {
 				ResourceFilter resourceFilter = (ResourceFilter) loader.loadClass(filter.getFilterClass()).newInstance();
-				FilterConfigImpl filterConfig = new FilterConfigImpl(filter.getFilterName(),filter.getInitParam(),portletContext);
+				FilterConfigImpl filterConfig = new FilterConfigImpl(filter.getFilterName(),filter.getInitParams(),portletContext);
 				resourceFilter.init(filterConfig);
 				resourceFilter.doFilter(request, response, this);
 				resourceFilter.destroy();

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/FilterManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/FilterManagerImpl.java?rev=704743&r1=704742&r2=704743&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/FilterManagerImpl.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/FilterManagerImpl.java Tue Oct 14 17:01:07 2008
@@ -57,12 +57,12 @@
 	}
 	
 	private void initFilterChain(){
-		List<FilterMapping> filterMappingList = portletApp.getFilterMapping();
+		List<FilterMapping> filterMappingList = portletApp.getFilterMappings();
 		if (filterMappingList!= null){
 			for (FilterMapping filterMapping : filterMappingList) {
 				if (isFilter(filterMapping, portletName)){
 					//the filter is specified for the portlet, check the filter for the lifecycle
-					List<Filter> filterList = portletApp.getFilter();
+					List<Filter> filterList = portletApp.getFilters();
 					for (Filter filter : filterList) {
 						//search for the filter in the filter
 						if (filter.getFilterName().equals(filterMapping.getFilterName())){
@@ -91,7 +91,7 @@
 	}
 	
 	private boolean isLifeCycle(Filter filter, String lifeCycle){
-		List <String> lifeCyclesList = filter.getLifecycle();
+		List <String> lifeCyclesList = filter.getLifecycles();
 		for (String string : lifeCyclesList) {
 			if (string.equals(lifeCycle))
 				return true;
@@ -100,7 +100,7 @@
 	}
 	
 	private boolean isFilter(FilterMapping filterMapping,String portletName){
-		List <String> portletNamesList = filterMapping.getPortletName();
+		List <String> portletNamesList = filterMapping.getPortletNames();
 		for (String portletNameFromFilterList : portletNamesList) {
 			if (portletNameFromFilterList.endsWith("*")){
 				if (portletNameFromFilterList.length()==1){

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletURLListenerImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletURLListenerImpl.java?rev=704743&r1=704742&r2=704743&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletURLListenerImpl.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletURLListenerImpl.java Tue Oct 14 17:01:07 2008
@@ -46,7 +46,7 @@
 			LOG.error(message, new IllegalArgumentException(message));
 		}
 		//this list is needed for the classnames
-		List<Listener> portletURLFilterList = portletApp.getListener();
+		List<Listener> portletURLFilterList = portletApp.getListeners();
 		//Iterate over the classnames and for each entry in the list the filter..URL is called.
 		if (portletURLFilterList != null){
 			for (Listener listener : portletURLFilterList) {

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletWindowThread.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletWindowThread.java?rev=704743&r1=704742&r2=704743&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletWindowThread.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletWindowThread.java Tue Oct 14 17:01:07 2008
@@ -107,7 +107,7 @@
 			        		EventDefinition eventDefinitionDD = getEventDefintion(event.getQName()); 
 			        		
 			        		ClassLoader loader = portletRegistry.getClassLoader(portletWindow.getPortletEntity().getPortletDefinition().getApplication().getId());
-			        		Class<? extends Serializable> clazz = loader.loadClass(eventDefinitionDD.getJavaClass()).asSubclass(Serializable.class);
+			        		Class<? extends Serializable> clazz = loader.loadClass(eventDefinitionDD.getValueType()).asSubclass(Serializable.class);
 
 			        		JAXBContext jc = JAXBContext.newInstance(clazz);
 			        		Unmarshaller unmarshaller  = jc.createUnmarshaller();
@@ -145,7 +145,7 @@
 
 	private EventDefinition getEventDefintion(QName name) throws PortletContainerException {
 		PortletApp appDD = portletWindow.getPortletEntity().getPortletDefinition().getApplication();
-		for (EventDefinition def : appDD.getEvents()){
+		for (EventDefinition def : appDD.getEventDefinitions()){
 			if (def.getQName() != null){
 				if (def.getQName().equals(name))
 					return def;

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceImpl.java?rev=704743&r1=704742&r2=704743&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceImpl.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedWindowStateServiceImpl.java Tue Oct 14 17:01:07 2008
@@ -165,7 +165,7 @@
             LOG.error( msg, e );
         }
         
-        List customWindowStates = portletAppDD.getCustomWindowState();
+        List customWindowStates = portletAppDD.getCustomWindowStates();
         if ( customWindowStates != null )
         {
             for ( Iterator i = customWindowStates.iterator(); i.hasNext(); )

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java?rev=704743&r1=704742&r2=704743&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/PortalDriverServlet.java Tue Oct 14 17:01:07 2008
@@ -216,8 +216,8 @@
 		if (parameterNames != null){
 			while(parameterNames.hasMoreElements()){
 				String parameterName = parameterNames.nextElement();
-				if (portletDD.getPublicRenderParameter() != null){
-					if (portletDD.getPublicRenderParameter().contains(parameterName)){
+				if (portletDD.getSupportedPublicRenderParameters() != null){
+					if (portletDD.getSupportedPublicRenderParameters().contains(parameterName)){
 						String value = request.getParameter(parameterName);
 						portalURL.addPublicParameterActionResourceParameter(parameterName, value);
 					}	

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/assemble/file/FileAssemblerAnt.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/assemble/file/FileAssemblerAnt.java?rev=704743&r1=704742&r2=704743&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/assemble/file/FileAssemblerAnt.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/assemble/file/FileAssemblerAnt.java Tue Oct 14 17:01:07 2008
@@ -19,36 +19,10 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Properties;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.apache.pluto.descriptors.services.PortletAppDescriptorService;
-import org.apache.pluto.descriptors.services.castor.EntityResolverImpl;
-import org.apache.pluto.descriptors.services.jaxb.PortletAppDescriptorServiceImpl;
-import org.apache.pluto.om.portlet.Portlet;
-import org.apache.pluto.om.portlet.PortletApp;
 import org.apache.pluto.util.UtilityException;
 import org.apache.pluto.util.assemble.Assembler;
 import org.apache.pluto.util.assemble.AssemblerConfig;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
+import org.apache.pluto.util.assemble.io.WebXmlStreamingAssembly;
 
 /**
  *
@@ -57,34 +31,6 @@
  * @since Nov 8, 2004
  */
 public class FileAssemblerAnt implements Assembler {
-	
-	/** The XML output properties. */
-    private static final Properties PROPERTIES = new Properties();
-    
-    /** Element tagnames that may appear before servlet elements. */
-    private static final Collection BEFORE_SERVLET_DEF = new ArrayList();
-    
-    /** Element tagnames that may appear before servlet-mapping elements. */
-    private static final Collection BEFORE_MAPPING_DEF = new ArrayList();
-
-    static {
-    	// Initialize xml output properties.
-        PROPERTIES.setProperty(OutputKeys.INDENT, "yes");
-        
-        // Initialize BEFORE_SERVLET_DEF collection.
-        BEFORE_SERVLET_DEF.add("icon");
-        BEFORE_SERVLET_DEF.add("display-name");
-        BEFORE_SERVLET_DEF.add("description");
-        BEFORE_SERVLET_DEF.add("distributable");
-        BEFORE_SERVLET_DEF.add("context-param");
-        BEFORE_SERVLET_DEF.add("filter");
-        BEFORE_SERVLET_DEF.add("filter-mapping");
-        BEFORE_SERVLET_DEF.add("listener");
-        
-        // initialize BEFORE_MAPPING_DEF collection.
-        BEFORE_MAPPING_DEF.addAll(BEFORE_SERVLET_DEF);
-        BEFORE_MAPPING_DEF.add("servlet");
-    }
     
     // Constructor -------------------------------------------------------------
     
@@ -104,176 +50,12 @@
             		config.getWebappDescriptor());
             InputStream portletXmlIn = new FileInputStream(
             		config.getPortletDescriptor());
-            Document xmlDoc = updateWebappDescriptor(webXmlIn, portletXmlIn);
-            webXmlIn.close();
             FileOutputStream webXmlOut = new FileOutputStream(
             		config.getDestination());
-            save(xmlDoc, webXmlOut);
+            WebXmlStreamingAssembly.assembleStream(webXmlIn, portletXmlIn, webXmlOut, DISPATCH_SERVLET_CLASS);
         } catch (IOException ex) {
             throw new UtilityException(ex.getMessage(), ex, null);
         }
     }
-    
-    
-    // Protected Methods -------------------------------------------------------
-    
-    /**
-     * Saves the XML document to the specified output stream.
-     * @param xmlDoc  the XML document.
-     * @param out  the output stream.
-     * @throws IOException  if an error occurs.
-     */
-    protected void save(Document xmlDoc, OutputStream out)
-    throws IOException {
-        try {
-            TransformerFactory factory = TransformerFactory.newInstance();
-            Transformer transformer = factory.newTransformer();
-            transformer.setOutputProperties(PROPERTIES);
-            transformer.transform(new DOMSource(xmlDoc),
-                                  new StreamResult(out));
-        } catch (TransformerConfigurationException ex) {
-            ex.printStackTrace();
-            throw new IOException(ex.getMessage());
-        } catch (TransformerException ex) {
-            ex.printStackTrace();
-            throw new IOException(ex.getMessage());
-        } finally {
-            out.flush();
-            out.close();
-        }
-    }
-
-
-    /**
-     * Updates the webapp descriptor by injecting portlet wrapper servlet
-     * definitions and mappings.
-     * 
-     * TODO: currently we rely specifically on the castor implementation.
-     * 
-     * @param webXmlIn  input stream to the webapp descriptor.
-     * @param portletXmlIn  input stream to the portlet app descriptor.
-     * @return the updated webapp descriptor XML document.
-     * @throws IOException
-     */
-    protected Document updateWebappDescriptor(InputStream webXmlIn,
-                                              InputStream portletXmlIn)
-    throws IOException {
-    	
-        Document webXmlDoc = parse(webXmlIn);
-        Collection servletElements = new ArrayList();
-        Collection mappingElements = new ArrayList();
-
-        PortletAppDescriptorService portletAppDescriptorService =
-            	new PortletAppDescriptorServiceImpl();
-        PortletApp portletAppDD = portletAppDescriptorService.read(portletXmlIn);
-        
-        for (Iterator it = portletAppDD.getPortlets().iterator();
-        		it.hasNext(); ) {
-            
-        	// Read portlet definition.
-        	Portlet portlet = (Portlet) it.next();
-            String name = portlet.getPortletName();
-            
-            // Create servlet definition element.
-            Element servlet = webXmlDoc.createElement("servlet");
-            Element servletName = webXmlDoc.createElement("servlet-name");
-            servletName.appendChild(webXmlDoc.createTextNode(name));
-            servlet.appendChild(servletName);
-            
-            Element servletClass = webXmlDoc.createElement("servlet-class");
-            servletClass.appendChild(webXmlDoc.createTextNode(DISPATCH_SERVLET_CLASS));
-            servlet.appendChild(servletClass);
-            
-            Element initParam = webXmlDoc.createElement("init-param");
-            Element paramName = webXmlDoc.createElement("param-name");
-            paramName.appendChild(webXmlDoc.createTextNode("portlet-name"));
-            
-            Element paramValue = webXmlDoc.createElement("param-value");
-            paramValue.appendChild(webXmlDoc.createTextNode(name));
-            
-            initParam.appendChild(paramName);
-            initParam.appendChild(paramValue);
-            servlet.appendChild(initParam);
-            
-            Element load = webXmlDoc.createElement("load-on-startup");
-            load.appendChild(webXmlDoc.createTextNode("1"));
-            servlet.appendChild(load);
-            
-            // Create servlet mapping element.
-            Element mapping = webXmlDoc.createElement("servlet-mapping");
-            servletName = webXmlDoc.createElement("servlet-name");
-            servletName.appendChild(webXmlDoc.createTextNode(name));
-            Element uri = webXmlDoc.createElement("url-pattern");
-            uri.appendChild(webXmlDoc.createTextNode("/PlutoInvoker/"+name));
-            mapping.appendChild(servletName);
-            mapping.appendChild(uri);
-            
-            // Save servlet definition and servlet mapping.
-            servletElements.add(servlet);
-            mappingElements.add(mapping);
-        }
-
-        Element webAppNode = webXmlDoc.getDocumentElement();
-        NodeList nodes = webAppNode.getChildNodes();
-        
-        // Find the first node that shouldn't be before the servlet and start
-        // appending. This is kind of ugly, but the hack works for now!
-        for (int i = 0; i < nodes.getLength(); i++) {
-            Node node = nodes.item(i);
-            if (node.getNodeType() == Node.ELEMENT_NODE) {
-                
-            	if (!BEFORE_SERVLET_DEF.contains(node.getNodeName())) {
-                	for (Iterator it = servletElements.iterator();
-                			it.hasNext(); ) {
-                        Node servlet = (Node) it.next();
-                        webAppNode.insertBefore(servlet, node);
-                        it.remove();
-                    }
-                }
-                
-                if(!BEFORE_MAPPING_DEF.contains(node.getNodeName())) {
-                	for (Iterator it = mappingElements.iterator();
-                			it.hasNext(); ) {
-                        Node mapping = (Node) it.next();
-                        webAppNode.insertBefore(mapping, node);
-                        it.remove();
-                    }
-                }
-            }
-        }
-
-        // Now, in case there are not any nodes after the servlet def!
-        for (Iterator it = servletElements.iterator(); it.hasNext(); ) {
-            webAppNode.appendChild((Node)it.next());
-        }
-        for (Iterator it = mappingElements.iterator(); it.hasNext(); ) {
-            webAppNode.appendChild((Node)it.next());
-        }
-        
-        // Return the updated web.xml document.
-        return webXmlDoc;
-    }
-    
-    /**
-     * Parses an input stream of an XML file to an XML document.
-     * @param xmlIn  the input stream of an XML file.
-     * @return the XML document.
-     * @throws IOException  if an error occurs.
-     */
-    private Document parse(InputStream xmlIn) throws IOException {
-        Document xmlDoc = null;
-        try {
-            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-            DocumentBuilder builder = factory.newDocumentBuilder();
-            builder.setEntityResolver(new EntityResolverImpl());
-            xmlDoc = builder.parse(xmlIn);
-        } catch (ParserConfigurationException ex) {
-            throw new IOException(ex.getMessage());
-        } catch (SAXException ex) {
-            throw new IOException(ex.getMessage());
-        }
-        return xmlDoc;
-    }
-    
 }
 

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/assemble/io/WebXmlStreamingAssembly.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/assemble/io/WebXmlStreamingAssembly.java?rev=704743&r1=704742&r2=704743&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/assemble/io/WebXmlStreamingAssembly.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/assemble/io/WebXmlStreamingAssembly.java Tue Oct 14 17:01:07 2008
@@ -19,89 +19,59 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.Iterator;
 
-import org.apache.pluto.descriptors.common.InitParamDD;
-import org.apache.pluto.descriptors.services.PortletAppDescriptorService;
-import org.apache.pluto.descriptors.services.WebAppDescriptorService;
-import org.apache.pluto.descriptors.services.castor.WebAppDescriptorServiceImpl;
 import org.apache.pluto.descriptors.services.jaxb.PortletAppDescriptorServiceImpl;
-import org.apache.pluto.descriptors.servlet.LoadOnStartupDD;
-import org.apache.pluto.descriptors.servlet.ServletDD;
-import org.apache.pluto.descriptors.servlet.ServletMappingDD;
-import org.apache.pluto.om.common.InitParam;
 import org.apache.pluto.om.portlet.Portlet;
 import org.apache.pluto.om.portlet.PortletApp;
-import org.apache.pluto.om.servlet.LoadOnStartup;
-import org.apache.pluto.om.servlet.Servlet;
-import org.apache.pluto.om.servlet.ServletMapping;
-import org.apache.pluto.om.servlet.WebApp;
 import org.apache.pluto.util.assemble.Assembler;
+import org.apache.pluto.util.descriptors.web.PlutoWebXmlRewriter;
 
-/** 
- * Utility class responsible for accepting web.xml and portlet.xml as InputStreams, and assembling
- * the web.xml to an OutputStream.
+/**
+ * Utility class responsible for accepting web.xml and portlet.xml as InputStreams, and assembling the web.xml to an
+ * OutputStream.
  */
-public class WebXmlStreamingAssembly {
-    
+public class WebXmlStreamingAssembly
+{
     /**
      * Assembles the web.xml represented by the <code>InputStream</code>.
      * 
-     * @param webXmlIn the unassembled web.xml file
-     * @param portletXmlIn the corresponding portlet.xml file
-     * @param assembledWebXmlOut the assembled web.xml file
-     * @param dispatchServletClass the dispatch servlet
+     * @param webXmlIn
+     *            the unassembled web.xml file
+     * @param portletXmlIn
+     *            the corresponding portlet.xml file
+     * @param assembledWebXmlOut
+     *            the assembled web.xml file
+     * @param dispatchServletClass
+     *            the dispatch servlet
      * @throws IOException
      */
-    public static void assembleStream(InputStream webXmlIn,
-                                InputStream portletXmlIn, 
-                                OutputStream assembledWebXmlOut, 
-                                String dispatchServletClass) 
-    throws IOException {
-        if (dispatchServletClass == null ||
-                dispatchServletClass.length() == 0 ||
-                dispatchServletClass.trim().length() == 0) {
+    public static void assembleStream(InputStream webXmlIn, InputStream portletXmlIn, OutputStream assembledWebXmlOut,
+                                      String dispatchServletClass) throws IOException
+    {
+        if (dispatchServletClass == null || dispatchServletClass.length() == 0 ||
+            dispatchServletClass.trim().length() == 0)
+        {
             dispatchServletClass = Assembler.DISPATCH_SERVLET_CLASS;
         }
-
-      WebAppDescriptorService descriptorSvc = new WebAppDescriptorServiceImpl();  
-      PortletAppDescriptorService portletAppDescriptorSvc = new PortletAppDescriptorServiceImpl();
-        
-        WebApp webAppDDIn = descriptorSvc.read(webXmlIn);
-        PortletApp portletAppDD = portletAppDescriptorSvc.read(portletXmlIn);
+        PlutoWebXmlRewriter webXmlRewriter = null;
+        try
+        {
+            webXmlRewriter = new PlutoWebXmlRewriter(webXmlIn);
+        }
+        catch (Exception e)
+        {
+            if (e instanceof IOException)
+            {
+                throw (IOException) e;
+            }
+            throw new IOException(e.getMessage());
+        }
+        PortletApp portletAppDD = new PortletAppDescriptorServiceImpl().read(portletXmlIn);
         portletXmlIn.close();
-
-        for (Iterator it = portletAppDD.getPortlets().iterator();
-                it.hasNext(); ) {
-
-            // Read portlet definition.
-            Portlet portlet = (Portlet) it.next();
-            String name = portlet.getPortletName();
-
-            Servlet servlet = new ServletDD();
-            servlet.setServletName(name);
-
-            servlet.setServletClass(dispatchServletClass);
-
-            InitParam initParam = new InitParamDD();
-            initParam.setParamName("portlet-name");
-            initParam.setParamValue(name);
-            servlet.getInitParams().add(initParam);
-
-            LoadOnStartup onStartup = new LoadOnStartupDD();
-            onStartup.setPriority(1);
-            servlet.setLoadOnStartup(onStartup);
-
-            ServletMapping servletMapping = new ServletMappingDD();
-            servletMapping.setServletName(name);
-            servletMapping.setUrlPattern("/PlutoInvoker/" + name);
-
-            webAppDDIn.getServlets().add(servlet);
-            webAppDDIn.getServletMappings().add(servletMapping);
-
+        for (Portlet portlet : portletAppDD.getPortlets())
+        {
+            webXmlRewriter.injectPortletServlet(dispatchServletClass, portlet.getPortletName());
         }
-
-        descriptorSvc.write(webAppDDIn, assembledWebXmlOut);
-        
+        webXmlRewriter.write(assembledWebXmlOut);
     }
 }

Added: portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/descriptors/web/PlutoWebXmlRewriter.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/descriptors/web/PlutoWebXmlRewriter.java?rev=704743&view=auto
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/descriptors/web/PlutoWebXmlRewriter.java (added)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/descriptors/web/PlutoWebXmlRewriter.java Tue Oct 14 17:01:07 2008
@@ -0,0 +1,352 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.util.descriptors.web;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * @version $Id$
+ */
+public class PlutoWebXmlRewriter
+{
+    private static final String NAMESPACE_PREFIX = "xp";
+    
+    private static final String[] ELEMENTS_BEFORE_SERVLET_23 = new String[] { "icon", "display-name", "description",
+                                                                             "distributable", "context-param",
+                                                                             "filter", "filter-mapping", "listener",
+                                                                             "servlet" };
+    private static final String[] ELEMENTS_BEFORE_SERVLET_MAPPING_23 = new String[] { "icon", "display-name",
+                                                                                     "description", "distributable",
+                                                                                     "context-param", "filter",
+                                                                                     "filter-mapping", "listener",
+                                                                                     "servlet", "servlet-mapping" };
+    private static final String[] ELEMENTS_BEFORE_SERVLET = new String[] { "description", "display-name", "icon",
+                                                                          "distributable", "context-param", "filter",
+                                                                          "filter-mapping", "listener", "servlet" };
+    private static final String[] ELEMENTS_BEFORE_SERVLET_MAPPING = new String[] { "description", "display-name",
+                                                                                  "icon", "distributable",
+                                                                                  "context-param", "filter",
+                                                                                  "filter-mapping", "listener",
+                                                                                  "servlet", "servlet-mapping" };
+    
+    private static class XPathNamespaceContext implements NamespaceContext
+    {
+        private String namespaceURI;
+        private String prefix;
+        
+        public XPathNamespaceContext(String prefix)
+        {
+            this(prefix,XMLConstants.XML_NS_URI);
+        }
+
+        public XPathNamespaceContext(String prefix, String namespaceURI)
+        {
+            this.prefix = prefix;
+            this.namespaceURI = namespaceURI;
+        }
+
+        public String getNamespaceURI(String prefix)
+        {
+            if (prefix == null)
+            {
+                throw new NullPointerException("Null prefix");
+            }
+            else if (this.prefix.equals(prefix))
+            {
+                return namespaceURI;
+            }
+            else if ("xml".equals(prefix))
+            {
+                return XMLConstants.XML_NS_URI;
+            }
+            return XMLConstants.NULL_NS_URI;
+        }
+
+        public String getPrefix(String namespaceURI)
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        @SuppressWarnings("unchecked")
+        public Iterator getPrefixes(String namespaceURI)
+        {
+            throw new UnsupportedOperationException();
+        }
+    }
+    
+    private Document descriptor;
+    private String namespace;
+    private String prefix;
+    private Element  root;
+    private XPath xpath;
+    private boolean descriptor23;
+    
+    public PlutoWebXmlRewriter(Document descriptor)
+    {
+        this.descriptor = descriptor;
+        this.root = descriptor.getDocumentElement();
+        this.namespace = root.getNamespaceURI();
+        String version = root.getAttribute("version");
+        if (version.equals(""))
+        {
+            version = "2.3";
+        }
+        try
+        {
+            // Check version is a valid number
+            Double.parseDouble(version);
+        }
+        catch(NumberFormatException e)
+        {
+            throw new RuntimeException("Unable to create Determine wew.xml version: " + version, e);
+        }
+        descriptor23 = version.equals("2.3");
+        if (!descriptor23 && version.compareTo("2.3") < 0)
+        {
+            throw new RuntimeException("Unsupported (too old?) web.xml version: "+version);
+        }        
+        xpath = XPathFactory.newInstance().newXPath();
+        if(namespace!= null && namespace.length() > 0)
+        {
+            prefix = NAMESPACE_PREFIX+":";
+            xpath.setNamespaceContext(new XPathNamespaceContext(NAMESPACE_PREFIX, namespace));
+        }
+        else
+        {
+            prefix = XMLConstants.DEFAULT_NS_PREFIX;
+            xpath.setNamespaceContext(new XPathNamespaceContext(XMLConstants.DEFAULT_NS_PREFIX));
+        }
+    }
+    
+    public PlutoWebXmlRewriter(InputStream source) throws Exception
+    {
+        this(parseXml(source));
+    }
+
+    protected static Document parseXml(InputStream source) throws Exception
+    {
+        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
+        domFactory.setNamespaceAware(true);
+        DocumentBuilder builder = domFactory.newDocumentBuilder();
+        builder.setEntityResolver(new EntityResolver()
+        {
+            public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws SAXException,
+                            java.io.IOException
+            {
+                if (systemId.equals("http://java.sun.com/dtd/web-app_2_3.dtd"))
+                {
+                    return new InputSource(getClass().getResourceAsStream("web-app_2_3.dtd"));
+                }
+                return null;
+            }
+        });
+        Document document = builder.parse(source);
+        return document;
+    }
+    
+    /**
+     * 
+     * <p>
+     * insertElementCorrectly
+     * </p>
+     * 
+     * @param root
+     *            element representing the &lt; web-app &gt;
+     * @param toInsert
+     *            element to insert into the web.xml hierarchy.
+     * @param elementsBefore
+     *            an array of web.xml elements that should be defined before the
+     *            element we want to insert. This order should be the order
+     *            defined by the web.xml's DTD or XSD type definition.
+     */
+    protected static void insertElementCorrectly( Element root, Element toInsert, String[] elementsBefore )
+    {
+        NodeList allChildren = root.getChildNodes();
+        List<String> elementsBeforeList = Arrays.asList(elementsBefore);
+        Node insertBefore = null;
+        for (int i = 0; i < allChildren.getLength(); i++)
+        {
+            Node node = allChildren.item(i);
+            if (insertBefore == null)
+            {
+                insertBefore = node;
+            }
+            if (node.getNodeType() == Node.ELEMENT_NODE)
+            {
+                if (elementsBeforeList.contains(node.getNodeName()))
+                {
+                    insertBefore = null;
+                }
+                else
+                {
+                    break;
+                }
+            }
+        }
+        if (insertBefore == null)
+        {
+            root.appendChild(toInsert);
+        }
+        else
+        {
+            root.insertBefore(toInsert, insertBefore);
+        }
+    }
+    
+    public boolean is23Descriptor()
+    {
+        return descriptor23;
+    }
+    
+    public boolean hasServlets()
+    {
+        Object result = null;
+        try
+        {
+            result = xpath.evaluate("/"+prefix+"web-app/"+prefix+"servlet", descriptor, XPathConstants.NODESET);
+        }
+        catch (XPathExpressionException e)
+        {
+            throw new RuntimeException(e);
+        }
+        return result != null ? ((NodeList)result).getLength() > 0 : false;
+    }
+    
+    public boolean hasServletMappings()
+    {
+        Object result = null;
+        try
+        {
+            result = xpath.evaluate("/"+prefix+"web-app/"+prefix+"servlet-mapping", descriptor, XPathConstants.NODESET);
+        }
+        catch (XPathExpressionException e)
+        {
+            throw new RuntimeException(e);
+        }
+        return result != null ? ((NodeList)result).getLength() > 0 : false;
+    }
+    
+    public String getServletClass(String servletName)
+    {
+        Object result = null;
+        try
+        {
+            result = xpath.evaluate("/"+prefix+"web-app/"+prefix+"servlet["+prefix+"servlet-name='"+servletName+"']/"+prefix+"servlet-class/text()", descriptor, XPathConstants.STRING);
+        }
+        catch (XPathExpressionException e)
+        {
+            throw new RuntimeException(e);
+        }
+        return result != null ? (String)result : null;
+    }
+    
+    public void injectPortletServlet(String className, String name)
+    {
+        Element servlet = descriptor.createElementNS(namespace, "servlet");
+        Element servletName = descriptor.createElementNS(namespace, "servlet-name");
+        servletName.setTextContent(name);
+        Element servletClass = descriptor.createElementNS(namespace, "servlet-class");
+        servletClass.setTextContent(className);
+        servlet.appendChild(servletName);
+        servlet.appendChild(servletClass);
+
+        Element init2Param = descriptor.createElementNS(namespace, "init-param");        
+        Element param2Name = descriptor.createElementNS(namespace, "param-name");
+        param2Name.setTextContent("portlet-name");
+        Element param2Value = descriptor.createElementNS(namespace, "param-value");
+        param2Value.setTextContent(name);
+        init2Param.appendChild(param2Name);
+        init2Param.appendChild(param2Value);        
+        servlet.appendChild(init2Param);                    
+
+        
+        Element loadOnStartup = descriptor.createElementNS(namespace, "load-on-startup");
+        loadOnStartup.setTextContent("1");
+        servlet.appendChild(loadOnStartup);        
+        
+        insertElementCorrectly(root, servlet, descriptor23 ? ELEMENTS_BEFORE_SERVLET_23 : ELEMENTS_BEFORE_SERVLET);
+        
+        Element servletMappingElement = descriptor.createElementNS(namespace, "servlet-mapping");
+        
+        Element servletMapName = descriptor.createElementNS(namespace, "servlet-name");
+        servletMapName.setTextContent(name);
+        Element servletUrlPattern = descriptor.createElementNS(namespace, "url-pattern");
+        servletUrlPattern.setTextContent("/PlutoInvoker/"+name);
+
+        servletMappingElement.appendChild(servletMapName);
+        servletMappingElement.appendChild(servletUrlPattern);
+
+        insertElementCorrectly(root, servletMappingElement, descriptor23 ? ELEMENTS_BEFORE_SERVLET_MAPPING_23 : ELEMENTS_BEFORE_SERVLET_MAPPING);        
+    }
+    
+    public void write(OutputStream dest) throws IOException
+    {
+        try
+        {
+            DOMSource domSource = new DOMSource(descriptor);
+            StreamResult streamResult = new StreamResult(dest);
+            TransformerFactory tf = TransformerFactory.newInstance();
+            Transformer transformer = tf.newTransformer();
+            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+            if (descriptor.getDoctype() != null)
+            {
+                transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, descriptor.getDoctype().getPublicId());
+                transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, descriptor.getDoctype().getSystemId());
+            }
+            transformer.setOutputProperty(OutputKeys.MEDIA_TYPE, "text/xml");
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+            transformer.transform(domSource, streamResult);
+        }
+        catch (TransformerConfigurationException e)
+        {
+            throw new IOException(e.getMessage());
+        }
+        catch (TransformerException e)
+        {
+            throw new IOException(e.getMessage());
+        }
+    }
+}

Propchange: portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/descriptors/web/PlutoWebXmlRewriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/descriptors/web/PlutoWebXmlRewriter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/pluto/branches/2.0-spi-refactoring/pluto-util/src/main/java/org/apache/pluto/util/descriptors/web/PlutoWebXmlRewriter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain