Author: julien_viet
Date: 2010-02-23 11:55:05 -0500 (Tue, 23 Feb 2010)
New Revision: 1824
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/DocumentSource.java
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/ResourceEntityResolver.java
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/ValidationReporter.java
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/XMLValidator.java
portal/trunk/component/portal/src/main/java/gatein_resources_1_0.xsd
Removed:
portal/trunk/component/portal/src/main/java/gatein_resources_1_0.xsd
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/SkinConfigParser.java
portal/trunk/examples/extension/war/src/main/webapp/WEB-INF/gatein-resources.xml
portal/trunk/examples/portal/war/src/main/webapp/WEB-INF/gatein-resources.xml
portal/trunk/pom.xml
portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/gatein-resources.xml
portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/gatein-resources.xml
portal/trunk/portlet/web/src/main/webapp/WEB-INF/gatein-resources.xml
portal/trunk/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml
portal/trunk/web/portal/src/main/webapp/WEB-INF/gatein-resources.xml
Log:
GTNPORTAL-735 : Validates gatein-resources files using the 1.0 Schema
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/DocumentSource.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/DocumentSource.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/DocumentSource.java 2010-02-23
16:55:05 UTC (rev 1824)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.commons.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public abstract class DocumentSource
+{
+
+ /** Some kind of identifier for error reporting. */
+ private String identifier;
+
+ private DocumentSource(String identifier)
+ {
+ if (identifier == null)
+ {
+ throw new NullPointerException("An identifier must be provided");
+ }
+ this.identifier = identifier;
+ }
+
+ public String getIdentifier()
+ {
+ return identifier;
+ }
+
+ public abstract InputStream getStream() throws IOException;
+
+ public static DocumentSource create(String identifier, final InputStream in)
+ {
+ return new DocumentSource(identifier)
+ {
+ @Override
+ public InputStream getStream() throws IOException
+ {
+ return in;
+ }
+ };
+ }
+
+ public static DocumentSource create(final URL url)
+ {
+ return new DocumentSource(url.toString())
+ {
+ @Override
+ public InputStream getStream() throws IOException
+ {
+ return url.openStream();
+ }
+ };
+ }
+
+}
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/ResourceEntityResolver.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/ResourceEntityResolver.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/ResourceEntityResolver.java 2010-02-23
16:55:05 UTC (rev 1824)
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.commons.xml;
+
+import org.exoplatform.commons.utils.IOUtil;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class ResourceEntityResolver implements EntityResolver
+{
+
+ /** . */
+ private final Map<String, String> systemIdToResourcePath;
+
+ /** . */
+ private final ConcurrentMap<String, byte[]> systemIdToSource;
+
+ /** . */
+ private final ClassLoader loader;
+
+ public ResourceEntityResolver(Class clazz, String systemId, String resourcePath)
+ {
+ this(clazz.getClassLoader(), Collections.singletonMap(systemId, resourcePath));
+ }
+
+ public ResourceEntityResolver(ClassLoader loader, String systemId, String
resourcePath)
+ {
+ this(loader, Collections.singletonMap(systemId, resourcePath));
+ }
+
+ public ResourceEntityResolver(Class clazz, Map<String, String>
systemIdToResourcePath)
+ {
+ this(clazz.getClassLoader(), systemIdToResourcePath);
+ }
+
+ public ResourceEntityResolver(ClassLoader loader, Map<String, String>
systemIdToResourcePath)
+ {
+ if (loader == null)
+ {
+ throw new NullPointerException();
+ }
+ if (systemIdToResourcePath == null)
+ {
+ throw new NullPointerException();
+ }
+
+ // Defensive copy
+ this.systemIdToResourcePath = new HashMap<String,
String>(systemIdToResourcePath);
+ this.systemIdToSource = new ConcurrentHashMap<String, byte[]>();
+ this.loader = loader;
+ }
+
+ public InputSource resolveEntity(String publicId, String systemId) throws
SAXException, IOException
+ {
+ if (systemId != null)
+ {
+ byte[] data = systemIdToSource.get(systemId);
+
+ //
+ if (data == null)
+ {
+ String path = systemIdToResourcePath.get(systemId);
+ if (path != null)
+ {
+ InputStream in = loader.getResourceAsStream(path);
+ if (in != null)
+ {
+ data = IOUtil.getStreamContentAsBytes(in);
+ }
+ }
+
+ // Black list it, we won't find it
+ if (data == null)
+ {
+ data = new byte[0];
+ }
+
+ // Put in cache
+ systemIdToSource.put(systemId, data);
+
+ // Some basic prevention against stupid use of this class that could cause
OOME
+ if (systemIdToSource.size() > 1000)
+ {
+ systemIdToSource.clear();
+ }
+ }
+
+ //
+ if (data != null && data.length > 0)
+ {
+ return new InputSource(new ByteArrayInputStream(data));
+ }
+ }
+
+ //
+ return null;
+ }
+}
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/ValidationReporter.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/ValidationReporter.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/ValidationReporter.java 2010-02-23
16:55:05 UTC (rev 1824)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.commons.xml;
+
+import org.gatein.common.logging.Logger;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class ValidationReporter implements ErrorHandler
+{
+
+ /** . */
+ private final String identifier;
+
+ /** . */
+ private boolean valid;
+
+ /** . */
+ private Logger log;
+
+ public ValidationReporter(Logger log, String identifier)
+ {
+ this.identifier = identifier;
+ this.log = log;
+ this.valid = true;
+ }
+
+ public boolean isValid()
+ {
+ return valid;
+ }
+
+ public void warning(SAXParseException exception) throws SAXException
+ {
+ log.warn(exception.getMessage(), exception);
+ }
+
+ public void error(SAXParseException exception) throws SAXException
+ {
+ log.error("Error in document " + identifier + " at (" +
exception.getLineNumber() + "," + exception.getColumnNumber()
+ + ") :" + exception.getMessage());
+ valid = false;
+ }
+
+ public void fatalError(SAXParseException exception) throws SAXException
+ {
+ log.error("Fatal error in document " + identifier + " at (" +
exception.getLineNumber() + "," + exception.getColumnNumber()
+ + ") :" + exception.getMessage());
+ valid = false;
+ }
+}
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/XMLValidator.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/XMLValidator.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/xml/XMLValidator.java 2010-02-23
16:55:05 UTC (rev 1824)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.commons.xml;
+
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class XMLValidator
+{
+
+ /** . */
+ private final String[] schemas;
+
+ /** . */
+ private final ResourceEntityResolver resolver;
+
+ /** . */
+ private final Logger log = LoggerFactory.getLogger(XMLValidator.class);
+
+ public XMLValidator(Class clazz, String systemId, String resourcePath)
+ {
+ schemas = new String[]{systemId};
+ resolver = new ResourceEntityResolver(clazz, systemId, resourcePath);
+ }
+
+ public String getSystemId()
+ {
+ return schemas[0];
+ }
+
+ /**
+ * Parse and validate the specified resource.
+ *
+ * @param source the source to validate
+ * @return the document when it is valid or null
+ * @throws java.io.IOException any IOException thrown by using the provided URL
+ * @throws NullPointerException if the provided URL is null
+ */
+ public Document validate(DocumentSource source) throws NullPointerException,
IOException
+ {
+ if (source == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schema...;,
"http://www.w3.org/2001/XMLSchema");
+
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schema...;,
schemas);
+ factory.setNamespaceAware(true);
+ factory.setValidating(true);
+
+ //
+ try
+ {
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ ValidationReporter reporter = new ValidationReporter(log,
source.getIdentifier());
+ builder.setErrorHandler(reporter);
+ builder.setEntityResolver(resolver);
+ return builder.parse(source.getStream());
+ }
+ catch (ParserConfigurationException e)
+ {
+ log.error("Got a parser configuration exception when doing XSD
validation");
+ return null;
+ }
+ catch (SAXException e)
+ {
+ log.error("Got a sax exception when doing XSD validation");
+ return null;
+ }
+ }
+
+}
Deleted: portal/trunk/component/portal/src/main/java/gatein_resources_1_0.xsd
===================================================================
--- portal/trunk/component/portal/src/main/java/gatein_resources_1_0.xsd 2010-02-23
16:34:27 UTC (rev 1823)
+++ portal/trunk/component/portal/src/main/java/gatein_resources_1_0.xsd 2010-02-23
16:55:05 UTC (rev 1824)
@@ -1,117 +0,0 @@
-<?xml version="1.0"?>
-<!--
-
- Copyright (C) 2009 eXo Platform SAS.
-
- This is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of
- the License, or (at your option) any later version.
-
- This software is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this software; if not, write to the Free
- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-
--->
-
-<xs:schema
-
targetNamespace="http://www.gatein.org/xml/ns/gatein_resources_1_0.x...
-
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd"
-
xmlns:xs="http://www.w3.org/2001/XMLSchema"
- elementFormDefault="qualified"
- attributeFormDefault="unqualified"
- version="1.0">
-
- <!-- The root element type that contains the various resource declarations -->
- <xs:element name="gatein-resources">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="portal-skin" type="portal-skin" />
- <xs:element name="portlet-skin" type="portlet-skin" />
- <xs:element name="window-style" type="window-style" />
- <xs:element name="javascript" type="javascript" />
- <xs:element name="resource-bundle" type="resource-bundle"
/>
- </xs:choice>
- </xs:complexType>
- </xs:element>
-
- <!-- Declares a portal skin resource -->
- <xs:complexType name="portal-skin">
- <xs:sequence>
- <xs:element name="skin-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
- <xs:element name="css-path" type="xs:string"
minOccurs="1" maxOccurs="1"/>
- <xs:element name="overwrite" type="xs:string"
minOccurs="0" maxOccurs="1"/>
- </xs:sequence>
- </xs:complexType>
-
- <!-- Declares a portlet skin resource -->
- <xs:complexType name="portlet-skin">
- <xs:sequence>
- <!-- The portlet application name -->
- <xs:element name="application-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
-
- <!-- The portlet name -->
- <xs:element name="portlet-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
-
- <!-- The name of the skin to load -->
- <xs:element name="skin-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
-
- <!-- The css path of the skin relative to the application context -->
- <xs:element name="css-path" type="xs:string"
minOccurs="1" maxOccurs="1"/>
-
- <!-- Overwrite -->
- <xs:element name="overwrite" type="xs:string"
minOccurs="0" maxOccurs="1"/>
- </xs:sequence>
- </xs:complexType>
-
- <!-- Declares a window style -->
- <xs:complexType name="window-style" mixed="true">
- <xs:sequence>
-
- <!-- The window style name -->
- <xs:element name="style-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
-
- <!-- The window style theme -->
- <xs:element name="style-theme" type="style-theme"
minOccurs="0" maxOccurs="unbounded"/>
- </xs:sequence>
- </xs:complexType>
-
- <!-- The window style theme -->
- <xs:complexType name="style-theme">
- <xs:sequence>
- <!-- The theme name -->
- <xs:element name="theme-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
- </xs:sequence>
- </xs:complexType>
-
- <!-- Declares a javascript resource -->
- <xs:complexType name="javascript">
- <xs:sequence>
- <xs:element name="param" type="param" minOccurs="0"
maxOccurs="unbounded"/>
- </xs:sequence>
- </xs:complexType>
-
- <xs:complexType name="param">
- <xs:sequence>
- <!-- The javascript module -->
- <xs:element name="js-module" type="xs:string"
minOccurs="1" maxOccurs="1"/>
-
- <!-- The javascript path -->
- <xs:element name="js-path" type="xs:string"
minOccurs="1" maxOccurs="1"/>
-
- <!-- The javascript priority -->
- <xs:element name="js-priority" type="xs:string"
minOccurs="0" maxOccurs="1"/>
- </xs:sequence>
- </xs:complexType>
-
- <!-- Declares a resource bundle -->
- <xs:complexType name="resource-bundle">
- </xs:complexType>
-
-</xs:schema>
\ No newline at end of file
Added: portal/trunk/component/portal/src/main/java/gatein_resources_1_0.xsd
===================================================================
--- portal/trunk/component/portal/src/main/java/gatein_resources_1_0.xsd
(rev 0)
+++ portal/trunk/component/portal/src/main/java/gatein_resources_1_0.xsd 2010-02-23
16:55:05 UTC (rev 1824)
@@ -0,0 +1,117 @@
+<?xml version="1.0"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+
+<xs:schema
+
targetNamespace="http://www.gatein.org/xml/ns/gatein_resources_1_0.x...
+
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd"
+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ version="1.0">
+
+ <!-- The root element type that contains the various resource declarations -->
+ <xs:element name="gatein-resources">
+ <xs:complexType>
+ <xs:choice minOccurs="0" maxOccurs="unbounded">
+ <xs:element name="portal-skin" type="portal-skin" />
+ <xs:element name="portlet-skin" type="portlet-skin" />
+ <xs:element name="window-style" type="window-style" />
+ <xs:element name="javascript" type="javascript" />
+ <xs:element name="resource-bundle" type="resource-bundle"
/>
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
+
+ <!-- Declares a portal skin resource -->
+ <xs:complexType name="portal-skin">
+ <xs:sequence>
+ <xs:element name="skin-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+ <xs:element name="css-path" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+ <xs:element name="overwrite" type="xs:string"
minOccurs="0" maxOccurs="1"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <!-- Declares a portlet skin resource -->
+ <xs:complexType name="portlet-skin">
+ <xs:sequence>
+ <!-- The portlet application name -->
+ <xs:element name="application-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+
+ <!-- The portlet name -->
+ <xs:element name="portlet-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+
+ <!-- The name of the skin to load -->
+ <xs:element name="skin-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+
+ <!-- The css path of the skin relative to the application context -->
+ <xs:element name="css-path" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+
+ <!-- Overwrite -->
+ <xs:element name="overwrite" type="xs:string"
minOccurs="0" maxOccurs="1"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <!-- Declares a window style -->
+ <xs:complexType name="window-style" mixed="true">
+ <xs:sequence>
+
+ <!-- The window style name -->
+ <xs:element name="style-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+
+ <!-- The window style theme -->
+ <xs:element name="style-theme" type="style-theme"
minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <!-- The window style theme -->
+ <xs:complexType name="style-theme">
+ <xs:sequence>
+ <!-- The theme name -->
+ <xs:element name="theme-name" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <!-- Declares a javascript resource -->
+ <xs:complexType name="javascript">
+ <xs:sequence>
+ <xs:element name="param" type="param" minOccurs="0"
maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="param">
+ <xs:sequence>
+ <!-- The javascript module -->
+ <xs:element name="js-module" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+
+ <!-- The javascript path -->
+ <xs:element name="js-path" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+
+ <!-- The javascript priority -->
+ <xs:element name="js-priority" type="xs:string"
minOccurs="0" maxOccurs="1"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <!-- Declares a resource bundle -->
+ <xs:complexType name="resource-bundle">
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java 2010-02-23
16:34:27 UTC (rev 1823)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java 2010-02-23
16:55:05 UTC (rev 1824)
@@ -19,16 +19,17 @@
package org.exoplatform.portal.resource;
+import org.exoplatform.commons.xml.DocumentSource;
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
import org.exoplatform.portal.resource.config.xml.SkinConfigParser;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
import org.gatein.wci.WebAppEvent;
import org.gatein.wci.WebAppLifeCycleEvent;
-import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import javax.servlet.ServletContext;
@@ -43,12 +44,15 @@
public class GateInSkinConfigDeployer extends AbstractResourceHandler
{
+ /** . */
+ private static final Logger log =
LoggerFactory.getLogger(GateInSkinConfigDeployer.class);
+
+ /** . */
private final SkinService skinService;
+ /** . */
private static final String GATEIN_CONFIG_RESOURCE =
"/WEB-INF/gatein-resources.xml";
- private static Log LOG = ExoLogger.getExoLogger(GateInSkinConfigDeployer.class);
-
/**
* The name of the portal container
*/
@@ -96,7 +100,7 @@
}
catch (Exception ex)
{
- LOG.error("An error occurs while registering '" +
GATEIN_CONFIG_RESOURCE + "' from the context '"
+ log.error("An error occurs while registering '" +
GATEIN_CONFIG_RESOURCE + "' from the context '"
+ (scontext == null ? "unknown" :
scontext.getServletContextName()) + "'", ex);
}
}
@@ -105,30 +109,23 @@
private void register(ServletContext scontext, PortalContainer container)
{
- InputStream is = null;
+ URL url;
try
{
- is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
- SkinConfigParser.processConfigResource(is, skinService, scontext);
+ url = scontext.getResource(GATEIN_CONFIG_RESOURCE);
+ if (url != null)
+ {
+ SkinConfigParser.processConfigResource(DocumentSource.create(url),
skinService, scontext);
+ }
+ else
+ {
+ log.debug("No " + GATEIN_CONFIG_RESOURCE + " found in web
application " + scontext.getContextPath());
+ }
}
catch (Exception ex)
{
- LOG.error("An error occurs while registering '" +
GATEIN_CONFIG_RESOURCE + "' from the context '"
+ log.error("An error occurs while registering '" +
GATEIN_CONFIG_RESOURCE + "' from the context '"
+ (scontext == null ? "unknown" : scontext.getServletContextName())
+ "'", ex);
}
- finally
- {
- if (is != null)
- {
- try
- {
- is.close();
- }
- catch (IOException e)
- {
- // ignore me
- }
- }
- }
}
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/SkinConfigParser.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/SkinConfigParser.java 2010-02-23
16:34:27 UTC (rev 1823)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/config/xml/SkinConfigParser.java 2010-02-23
16:55:05 UTC (rev 1824)
@@ -19,6 +19,8 @@
package org.exoplatform.portal.resource.config.xml;
+import org.exoplatform.commons.xml.DocumentSource;
+import org.exoplatform.commons.xml.XMLValidator;
import org.exoplatform.portal.resource.SkinService;
import org.exoplatform.portal.resource.config.tasks.AbstractSkinTask;
import org.exoplatform.web.resource.config.xml.GateinResource;
@@ -26,15 +28,12 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
/**
*
@@ -47,6 +46,18 @@
public class SkinConfigParser
{
+ /** . */
+ public static final String GATEIN_RESOURCES_1_0_SYSTEM_ID =
"http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd";
+
+ /** . */
+ private static final String GATEIN_RESOURCE_1_0_XSD_PATH =
"gatein_resources_1_0.xsd";
+
+ /** . */
+ private static final XMLValidator VALIDATOR = new XMLValidator(
+ SkinConfigParser.class,
+ GATEIN_RESOURCES_1_0_SYSTEM_ID,
+ GATEIN_RESOURCE_1_0_XSD_PATH);
+
private final static Map<String, AbstractTaskXMLBinding> allBindings = new
HashMap<String, AbstractTaskXMLBinding>();
static
@@ -56,9 +67,9 @@
allBindings.put(GateinResource.WINDOW_STYLE_TAG, new
AbstractTaskXMLBinding.ThemeTaskXMLBinding());
}
- public static void processConfigResource(InputStream is, SkinService skinService,
ServletContext scontext)
+ public static void processConfigResource(DocumentSource source, SkinService
skinService, ServletContext scontext)
{
- List<AbstractSkinTask> allTasks = fetchTasks(is);
+ List<AbstractSkinTask> allTasks = fetchTasks(source);
if (allTasks != null)
{
for (AbstractSkinTask task : allTasks)
@@ -68,12 +79,11 @@
}
}
- private static List<AbstractSkinTask> fetchTasks(InputStream is)
+ private static List<AbstractSkinTask> fetchTasks(DocumentSource source)
{
try
{
- DocumentBuilder docBuilder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document document = docBuilder.parse(is);
+ Document document = VALIDATOR.validate(source);
return fetchTasksFromXMLConfig(document);
}
catch (Exception ex)
@@ -94,12 +104,6 @@
return tasks;
}
- /**
- *
- * @param tagName
- * @param rootElement
- * @param tasks
- */
private static void fetchTasksByTagName(String tagName, Element rootElement,
List<AbstractSkinTask> tasks)
{
AbstractTaskXMLBinding binding = allBindings.get(tagName);
Modified:
portal/trunk/examples/extension/war/src/main/webapp/WEB-INF/gatein-resources.xml
===================================================================
---
portal/trunk/examples/extension/war/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:34:27 UTC (rev 1823)
+++
portal/trunk/examples/extension/war/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:55:05 UTC (rev 1824)
@@ -21,7 +21,7 @@
-->
<gatein-resources
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
+
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd"
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd">
<portlet-skin>
Modified: portal/trunk/examples/portal/war/src/main/webapp/WEB-INF/gatein-resources.xml
===================================================================
---
portal/trunk/examples/portal/war/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:34:27 UTC (rev 1823)
+++
portal/trunk/examples/portal/war/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:55:05 UTC (rev 1824)
@@ -22,7 +22,7 @@
<gatein-resources
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
+
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd"
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd">
<portlet-skin>
Modified: portal/trunk/pom.xml
===================================================================
--- portal/trunk/pom.xml 2010-02-23 16:34:27 UTC (rev 1823)
+++ portal/trunk/pom.xml 2010-02-23 16:55:05 UTC (rev 1824)
@@ -495,6 +495,7 @@
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
+ <include>**/*.xsd</include>
</includes>
</resource>
</resources>
Modified: portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/gatein-resources.xml
===================================================================
--- portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:34:27 UTC (rev 1823)
+++ portal/trunk/portlet/dashboard/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:55:05 UTC (rev 1824)
@@ -22,7 +22,7 @@
<gatein-resources
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
+
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd"
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd">
<!-- GadgetPortlet skins -->
Modified: portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/gatein-resources.xml
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:34:27 UTC (rev 1823)
+++ portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:55:05 UTC (rev 1824)
@@ -22,7 +22,7 @@
<gatein-resources
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
+
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd"
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd">
Modified: portal/trunk/portlet/web/src/main/webapp/WEB-INF/gatein-resources.xml
===================================================================
--- portal/trunk/portlet/web/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:34:27 UTC (rev 1823)
+++ portal/trunk/portlet/web/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:55:05 UTC (rev 1824)
@@ -22,7 +22,7 @@
<gatein-resources
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
+
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd"
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd">
<!-- BannerPortlet skins -->
Modified: portal/trunk/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml
===================================================================
--- portal/trunk/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:34:27 UTC (rev 1823)
+++ portal/trunk/web/eXoResources/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:55:05 UTC (rev 1824)
@@ -19,7 +19,10 @@
02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-->
-<gatein-resources
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd">
+<gatein-resources
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd"
+
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd">
<portal-skin>
<skin-name>Default</skin-name>
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/gatein-resources.xml
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:34:27 UTC (rev 1823)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/gatein-resources.xml 2010-02-23
16:55:05 UTC (rev 1824)
@@ -22,7 +22,7 @@
<gatein-resources
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
+
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_resources_1_...
http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd"
xmlns="http://www.gatein.org/xml/ns/gatein_resources_1_0.xsd">
<portlet-skin>