\o/
On Thu, Feb 24, 2011 at 5:08 PM, tmortagne <[email protected]> wrote: > Author: tmortagne > Date: 2011-02-24 17:08:47 +0100 (Thu, 24 Feb 2011) > New Revision: 34917 > > Added: > > contrib/sandbox/xwiki-extension-handler-xar/src/test/resources/repository/local/page.xml > Removed: > > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/ClassHandler.java > > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/ObjectHandler.java > Modified: > > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/DocumentImporterHandler.java > > contrib/sandbox/xwiki-extension-handler-xar/src/test/java/org/xwiki/extension/xar/XarExtensionHandlerTest.java > > contrib/sandbox/xwiki-extension-handler-xar/src/test/resources/repository/local/test-1.0.xar > > contrib/sandbox/xwiki-extension-handler-xar/src/test/resources/repository/local/test-2.0.xar > Log: > XWIKI-5557: Add extension manager xar handler > Yea ! first fully implemented version with install/commit/upgrade support (ok > "upgrade" is maybe a lot to say ;)) > > Deleted: > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/ClassHandler.java > =================================================================== > --- > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/ClassHandler.java > 2011-02-24 15:58:04 UTC (rev 34916) > +++ > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/ClassHandler.java > 2011-02-24 16:08:47 UTC (rev 34917) > @@ -1,37 +0,0 @@ > -/* > - * See the NOTICE file distributed with this work for additional > - * information regarding copyright ownership. > - * > - * 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.xwiki.extension.xar.internal.handler.packager.xml; > - > -import org.xwiki.component.manager.ComponentManager; > - > -import com.xpn.xwiki.objects.classes.BaseClass; > - > -public class ClassHandler extends AbstractHandler > -{ > - public ClassHandler(ComponentManager componentManager, BaseClass xclass) > - { > - super(componentManager, xclass); > - } > - > - public BaseClass getObject() > - { > - return (BaseClass) getCurrentBean(); > - } > -} > > Modified: > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/DocumentImporterHandler.java > =================================================================== > --- > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/DocumentImporterHandler.java > 2011-02-24 15:58:04 UTC (rev 34916) > +++ > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/DocumentImporterHandler.java > 2011-02-24 16:08:47 UTC (rev 34917) > @@ -19,6 +19,7 @@ > */ > package org.xwiki.extension.xar.internal.handler.packager.xml; > > +import org.dom4j.io.SAXContentHandler; > import org.xml.sax.Attributes; > import org.xml.sax.SAXException; > import org.xwiki.component.manager.ComponentLookupException; > @@ -26,7 +27,9 @@ > import org.xwiki.model.reference.DocumentReference; > > import com.xpn.xwiki.XWikiContext; > +import com.xpn.xwiki.XWikiException; > import com.xpn.xwiki.doc.XWikiDocument; > +import com.xpn.xwiki.objects.BaseObject; > > public class DocumentImporterHandler extends AbstractHandler > { > @@ -34,6 +37,11 @@ > > private boolean needSave = true; > > + /** > + * Avoid create a new SAXContentHandler for each object/class when the > same can be used for all. > + */ > + public SAXContentHandler domBuilder = new SAXContentHandler(); > + > public DocumentImporterHandler(ComponentManager componentManager) > { > super(componentManager); > @@ -43,6 +51,7 @@ > } catch (ComponentLookupException e) { > setCurrentBean(new XWikiDocument()); > } > + > // skip useless known elements > this.skippedElements.add("version"); > this.skippedElements.add("minorEdit"); > @@ -99,10 +108,9 @@ > { > if (qName.equals("attachment")) { > setCurrentHandler(new AttachmentHandler(getComponentManager())); > - } else if (qName.equals("object")) { > - setCurrentHandler(new ObjectHandler(getComponentManager())); > - } else if (qName.equals("class")) { > - setCurrentHandler(new ClassHandler(getComponentManager(), > getDocument().getXClass())); > + } else if (qName.equals("class") || qName.equals("object")) { > + this.domBuilder.startDocument(); > + setCurrentHandler(this.domBuilder); > } else { > super.startElementInternal(uri, localName, qName, attributes); > } > @@ -120,14 +128,25 @@ > > getDocument().getAttachmentList().add(handler.getAttachment()); > > - // TODO: add attachment to documentxwikidoc > + // TODO: add attachment to document > saveDocument("Import: add attachment"); > } else if (qName.equals("object")) { > - ObjectHandler handler = (ObjectHandler) getCurrentHandler(); > - getDocument().addXObject(handler.getObject()); > + try { > + BaseObject baseObject = new BaseObject(); > + > baseObject.fromXML(this.domBuilder.getDocument().getRootElement()); > + getDocument().setXObject(baseObject.getNumber(), baseObject); > + } catch (XWikiException e) { > + throw new SAXException("Failed to parse object", e); > + } > > this.needSave = true; > } else if (qName.equals("class")) { > + try { > + > getDocument().getXClass().fromXML(this.domBuilder.getDocument().getRootElement()); > + } catch (XWikiException e) { > + throw new SAXException("Failed to parse object", e); > + } > + > this.needSave = true; > } else { > super.endElementInternal(uri, localName, qName); > > Deleted: > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/ObjectHandler.java > =================================================================== > --- > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/ObjectHandler.java > 2011-02-24 15:58:04 UTC (rev 34916) > +++ > contrib/sandbox/xwiki-extension-handler-xar/src/main/java/org/xwiki/extension/xar/internal/handler/packager/xml/ObjectHandler.java > 2011-02-24 16:08:47 UTC (rev 34917) > @@ -1,37 +0,0 @@ > -/* > - * See the NOTICE file distributed with this work for additional > - * information regarding copyright ownership. > - * > - * 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.xwiki.extension.xar.internal.handler.packager.xml; > - > -import org.xwiki.component.manager.ComponentManager; > - > -import com.xpn.xwiki.objects.BaseObject; > - > -public class ObjectHandler extends AbstractHandler > -{ > - public ObjectHandler(ComponentManager componentManager) > - { > - super(componentManager, new BaseObject()); > - } > - > - public BaseObject getObject() > - { > - return (BaseObject) getCurrentBean(); > - } > -} > > Modified: > contrib/sandbox/xwiki-extension-handler-xar/src/test/java/org/xwiki/extension/xar/XarExtensionHandlerTest.java > =================================================================== > --- > contrib/sandbox/xwiki-extension-handler-xar/src/test/java/org/xwiki/extension/xar/XarExtensionHandlerTest.java > 2011-02-24 15:58:04 UTC (rev 34916) > +++ > contrib/sandbox/xwiki-extension-handler-xar/src/test/java/org/xwiki/extension/xar/XarExtensionHandlerTest.java > 2011-02-24 16:08:47 UTC (rev 34917) > @@ -40,6 +40,9 @@ > import com.xpn.xwiki.XWiki; > import com.xpn.xwiki.XWikiContext; > import com.xpn.xwiki.doc.XWikiDocument; > +import com.xpn.xwiki.objects.BaseObject; > +import com.xpn.xwiki.objects.classes.BaseClass; > +import com.xpn.xwiki.objects.classes.NumberClass; > import com.xpn.xwiki.test.AbstractBridgedComponentTestCase; > > public class XarExtensionHandlerTest extends AbstractBridgedComponentTestCase > @@ -147,6 +150,11 @@ > Assert.assertEquals("Wrong content", "content", > document.getContent()); > Assert.assertEquals("Wrong author", "XWiki.author", > document.getAuthor()); > Assert.assertEquals("Wrong versions", "1.1", document.getVersion()); > + > + BaseClass baseClass = document.getXClass(); > + Assert.assertNotNull(baseClass.getField("property")); > + Assert.assertEquals("property", > baseClass.getField("property").getName()); > + Assert.assertSame(NumberClass.class, > baseClass.getField("property").getClass()); > } > > @Test > @@ -173,6 +181,11 @@ > Assert.assertEquals("Wrong content", "content 2", > document.getContent()); > Assert.assertEquals("Wrong author", "XWiki.author", > document.getAuthor()); > Assert.assertEquals("Wrong versions", "2.1", document.getVersion()); > + > + BaseClass baseClass = document.getXClass(); > + Assert.assertNotNull(baseClass.getField("property")); > + Assert.assertEquals("property", > baseClass.getField("property").getName()); > + Assert.assertSame(NumberClass.class, > baseClass.getField("property").getClass()); > } > > @Test > > Added: > contrib/sandbox/xwiki-extension-handler-xar/src/test/resources/repository/local/page.xml > =================================================================== > --- > contrib/sandbox/xwiki-extension-handler-xar/src/test/resources/repository/local/page.xml > (rev 0) > +++ > contrib/sandbox/xwiki-extension-handler-xar/src/test/resources/repository/local/page.xml > 2011-02-24 16:08:47 UTC (rev 34917) > @@ -0,0 +1,166 @@ > +<?xml version="1.0" encoding="UTF-8"?> > +<xwikidoc> > +<web>space</web> > +<name>page</name> > +<language></language> > +<defaultLanguage>en</defaultLanguage> > +<translation>0</translation> > +<parent></parent> > +<creator>XWiki.creator</creator> > +<author>XWiki.author</author> > +<customClass></customClass> > +<contentAuthor>XWiki.contentAuthor</contentAuthor> > +<creationDate>1297952360000</creationDate> > +<date>1297952371000</date> > +<contentUpdateDate>1297952371000</contentUpdateDate> > +<version>1.1</version> > +<title></title> > +<template></template> > +<defaultTemplate></defaultTemplate> > +<validationScript></validationScript> > +<comment></comment> > +<minorEdit>false</minorEdit> > +<syntaxId>xwiki/2.0</syntaxId> > +<hidden>false</hidden> > +<class> > +<name>space.page</name> > +<customClass></customClass> > +<customMapping></customMapping> > +<defaultViewSheet></defaultViewSheet> > +<defaultEditSheet></defaultEditSheet> > +<defaultWeb></defaultWeb> > +<nameField></nameField> > +<validationScript></validationScript> > +<property> > +<disabled>0</disabled> > +<name>property</name> > +<number>1</number> > +<numberType>long</numberType> > +<prettyName>property</prettyName> > +<size>30</size> > +<unmodifiable>0</unmodifiable> > +<classType>com.xpn.xwiki.objects.classes.NumberClass</classType> > +</property> > +</class> > +<object> > +<class> > +<name>XWiki.StyleSheetExtension</name> > +<customClass></customClass> > +<customMapping></customMapping> > +<defaultViewSheet></defaultViewSheet> > +<defaultEditSheet></defaultEditSheet> > +<defaultWeb></defaultWeb> > +<nameField></nameField> > +<validationScript></validationScript> > +<cache> > +<cache>0</cache> > +<disabled>0</disabled> > +<displayType>select</displayType> > +<multiSelect>0</multiSelect> > +<name>cache</name> > +<number>5</number> > +<prettyName>Caching policy</prettyName> > +<relationalStorage>0</relationalStorage> > +<separator> </separator> > +<separators> ,|</separators> > +<size>1</size> > +<unmodifiable>0</unmodifiable> > +<values>long|short|default|forbid</values> > +<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType> > +</cache> > +<code> > +<disabled>0</disabled> > +<name>code</name> > +<number>2</number> > +<prettyName>Code</prettyName> > +<rows>20</rows> > +<size>50</size> > +<unmodifiable>0</unmodifiable> > +<classType>com.xpn.xwiki.objects.classes.TextAreaClass</classType> > +</code> > +<name> > +<disabled>0</disabled> > +<name>name</name> > +<number>1</number> > +<prettyName>Name</prettyName> > +<size>30</size> > +<unmodifiable>0</unmodifiable> > +<classType>com.xpn.xwiki.objects.classes.StringClass</classType> > +</name> > +<parse> > +<disabled>0</disabled> > +<displayFormType>select</displayFormType> > +<displayType>yesno</displayType> > +<name>parse</name> > +<number>4</number> > +<prettyName>Parse content</prettyName> > +<unmodifiable>0</unmodifiable> > +<classType>com.xpn.xwiki.objects.classes.BooleanClass</classType> > +</parse> > +<use> > +<cache>0</cache> > +<disabled>0</disabled> > +<displayType>select</displayType> > +<multiSelect>0</multiSelect> > +<name>use</name> > +<number>3</number> > +<prettyName>Use this extension</prettyName> > +<relationalStorage>0</relationalStorage> > +<separator> </separator> > +<separators> ,|</separators> > +<size>1</size> > +<unmodifiable>0</unmodifiable> > +<values>onDemand=On demand|always=Always</values> > +<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType> > +</use> > +</class> > +<name>space.page</name> > +<number>0</number> > +<className>XWiki.StyleSheetExtension</className> > +<guid>8eaeac52-e2f2-47b2-87e1-bc6909597b39</guid> > +<property> > +<cache>long</cache> > +</property> > +<property> > +<code>some code</code> > +</property> > +<property> > +<name>name</name> > +</property> > +<property> > +<parse></parse> > +</property> > +<property> > +<use>onDemand</use> > +</property> > +</object> > +<object> > +<class> > +<name>space.page</name> > +<customClass></customClass> > +<customMapping></customMapping> > +<defaultViewSheet></defaultViewSheet> > +<defaultEditSheet></defaultEditSheet> > +<defaultWeb></defaultWeb> > +<nameField></nameField> > +<validationScript></validationScript> > +<property> > +<disabled>0</disabled> > +<name>property</name> > +<number>1</number> > +<numberType>long</numberType> > +<prettyName>property</prettyName> > +<size>30</size> > +<unmodifiable>0</unmodifiable> > +<classType>com.xpn.xwiki.objects.classes.NumberClass</classType> > +</property> > +</class> > +<name>space.page</name> > +<number>0</number> > +<className>space.page</className> > +<guid>e2167721-2a64-430c-9520-bac1c0ee68cb</guid> > +<property> > +<property>12</property> > +</property> > +</object> > +<content>content</content></xwikidoc> > > > Property changes on: > contrib/sandbox/xwiki-extension-handler-xar/src/test/resources/repository/local/page.xml > ___________________________________________________________________ > Added: svn:mime-type > + text/plain > Added: svn:eol-style > + native > > Modified: > contrib/sandbox/xwiki-extension-handler-xar/src/test/resources/repository/local/test-1.0.xar > =================================================================== > (Binary files differ) > > Modified: > contrib/sandbox/xwiki-extension-handler-xar/src/test/resources/repository/local/test-2.0.xar > =================================================================== > (Binary files differ) > > _______________________________________________ > notifications mailing list > [email protected] > http://lists.xwiki.org/mailman/listinfo/notifications > _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

