Author: julien_viet
Date: 2010-02-25 04:25:19 -0500 (Thu, 25 Feb 2010)
New Revision: 1860
Added:
portal/trunk/component/application-registry/src/main/java/gadgets_1_0.xsd
Modified:
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetDeployer.java
portal/trunk/gadgets/eXoGadgets/src/main/webapp/WEB-INF/gadget.xml
Log:
let's be crazy and use a schema for gadget deployment
Added: portal/trunk/component/application-registry/src/main/java/gadgets_1_0.xsd
===================================================================
--- portal/trunk/component/application-registry/src/main/java/gadgets_1_0.xsd
(rev 0)
+++ portal/trunk/component/application-registry/src/main/java/gadgets_1_0.xsd 2010-02-25
09:25:19 UTC (rev 1860)
@@ -0,0 +1,46 @@
+<?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/gadgets_1_0"
+
xmlns="http://www.gatein.org/xml/ns/gadgets_1_0"
+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ version="1.0">
+
+ <xs:element name="gadgets" type="gadgets"/>
+
+ <xs:complexType name="gadgets">
+ <xs:sequence minOccurs="0" maxOccurs="unbounded">
+ <xs:element name="gadget" type="gadget"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:complexType name="gadget">
+ <xs:sequence>
+ <xs:choice>
+ <xs:element name="path" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+ <xs:element name="url" type="xs:string"
minOccurs="1" maxOccurs="1"/>
+ </xs:choice>
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:string"/>
+ </xs:complexType>
+</xs:schema>
\ No newline at end of file
Modified:
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetDeployer.java
===================================================================
---
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetDeployer.java 2010-02-25
08:45:38 UTC (rev 1859)
+++
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/gadget/GadgetDeployer.java 2010-02-25
09:25:19 UTC (rev 1860)
@@ -21,6 +21,8 @@
import org.exoplatform.application.gadget.impl.GadgetRegistryServiceImpl;
import org.exoplatform.commons.chromattic.ChromatticLifeCycle;
import org.exoplatform.commons.chromattic.SessionContext;
+import org.exoplatform.commons.xml.DocumentSource;
+import org.exoplatform.commons.xml.XMLValidator;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.RootContainer;
@@ -52,6 +54,9 @@
{
/** . */
+ private static final XMLValidator validator = new XMLValidator(GadgetDeployer.class,
"http://www.gatein.org/xml/ns/gadgets_1_0", "gadgets_1_0.xsd");
+
+ /** . */
private final Logger log = LoggerFactory.getLogger(GadgetDeployer.class);
/** . */
@@ -112,12 +117,9 @@
{
ChromatticLifeCycle lifeCycle = gadgetRegistryService.getChromatticLifeCycle();
lifeCycle.openContext();
- InputStream in;
try
{
- in = gadgetsURL.openStream();
- DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document docXML = db.parse(in);
+ Document docXML = validator.validate(DocumentSource.create(gadgetsURL));
NodeList nodeList = docXML.getElementsByTagName("gadget");
for (int i = 0; i < nodeList.getLength(); i++)
{
Modified: portal/trunk/gadgets/eXoGadgets/src/main/webapp/WEB-INF/gadget.xml
===================================================================
--- portal/trunk/gadgets/eXoGadgets/src/main/webapp/WEB-INF/gadget.xml 2010-02-25 08:45:38
UTC (rev 1859)
+++ portal/trunk/gadgets/eXoGadgets/src/main/webapp/WEB-INF/gadget.xml 2010-02-25 09:25:19
UTC (rev 1860)
@@ -20,7 +20,11 @@
-->
-<gadgets>
+<gadgets
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_0
http://www.gatein.org/xml/ns/gadgets_1_0"
+
xmlns="http://www.gatein.org/xml/ns/gadgets_1_0">
+
<gadget name="Todo">
<path>/gadgets/Todo/Todo.xml</path>
</gadget>