Author: rombert Date: Mon Sep 9 14:44:09 2013 New Revision: 1521146 URL: http://svn.apache.org/r1521146 Log: SLING-2989 - [Tooling] integrate with vlt once available
Implement serialization of Java primitive types from .content.xml files into the repository. Not yet implemented: Name, Path, Reference and WeakReference. Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml (with props) sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java (with props) sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/multiple-properties-connect.xml (with props) sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/name-content.xml (with props) sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/path-content.xml (with props) sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/reference-content.xml (with props) sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/simple-content.xml (with props) sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java (with props) Removed: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContextXmlHandler.java Modified: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/META-INF/MANIFEST.MF sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java sling/branches/tooling-ide-vlt/tooling/ide/pom.xml sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml?rev=1521146&view=auto ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml (added) +++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml Mon Sep 9 14:44:09 2013 @@ -0,0 +1,64 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.sling.ide</groupId> + <artifactId>reactor</artifactId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <artifactId>org.apache.sling.ide.impl-vlt-test</artifactId> + <name>Sling IDE Tools: FileVault Implementation Tests</name> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-core</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-all</artifactId> + <version>1.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.sling.ide</groupId> + <artifactId>org.apache.sling.ide.impl-vlt</artifactId> + <version>${project.version}</version> + <type>eclipse-plugin</type> + </dependency> + <!-- + we need to pull in all transitive dependencies of the impl-vlt + bundle, since they are not exposed by Tycho(?) + --> + <dependency> + <groupId>org.apache.jackrabbit</groupId> + <artifactId>jackrabbit-jcr-commons</artifactId> + <version>${jackrabbit.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <!-- Tycho targets 1.6 by default, so we need that as well --> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + </plugins> + </build> + + <properties> + <jackrabbit.version>2.4.0</jackrabbit.version> + </properties> +</project> Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java?rev=1521146&view=auto ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java (added) +++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java Mon Sep 9 14:44:09 2013 @@ -0,0 +1,102 @@ +/* + * 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.sling.ide.impl.vlt.serialization; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.Calendar; +import java.util.Map; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.junit.Ignore; +import org.junit.Test; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +public class ContentXmlHandlerTest { + + @Test + public void simpleContentXml() throws ParserConfigurationException, SAXException, IOException { + + Map<String, Object> properties = parseContentXmlFile("simple-content.xml"); + + assertThat("properties.size", properties.size(), is(7)); + + assertThat("properties[jcr:primaryType]", properties, hasEntry("jcr:primaryType", (Object) "sling:Folder")); + assertThat("properties[jcr:title]", properties, hasEntry("jcr:title", (Object) "Application folder")); + assertThat("properties[indexed]", properties, hasEntry("indexed", (Object) Boolean.TRUE)); + assertThat("properties[indexRatio]", properties, hasEntry("indexRatio", (Object) Double.valueOf(2.54))); + assertThat("properties[indexDuration]", properties, hasEntry("indexDuration", (Object) BigDecimal.valueOf(500))); + assertThat("properties[lastIndexTime]", properties, hasEntry(is("lastIndexTime"), notNullValue())); + assertThat("properties[lastIndexId]", properties, + hasEntry("lastIndexId", (Object) Long.valueOf(7293120000000l))); + + Calendar lastIndexTime = (Calendar) properties.get("lastIndexTime"); + assertThat(lastIndexTime.getTimeInMillis(), is(1378292400000l)); + + } + + private Map<String, Object> parseContentXmlFile(String fileName) throws ParserConfigurationException, SAXException, + IOException { + + InputSource source = new InputSource(getClass().getResourceAsStream(fileName)); + + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setFeature("http://xml.org/sax/features/namespace-prefixes", false); + SAXParser parser = factory.newSAXParser(); + ContentXmlHandler handler = new ContentXmlHandler(); + parser.parse(source, handler); + + return handler.getProperties(); + } + + @Test + @Ignore("Not implemented") + public void parseNameProperty() throws ParserConfigurationException, SAXException, IOException { + + Map<String, Object> properties = parseContentXmlFile("name-content.xml"); + + assertThat("properties.size", properties.size(), is(2)); + } + + @Test + @Ignore("Not implemented") + public void parsePathProperty() throws ParserConfigurationException, SAXException, IOException { + + Map<String, Object> properties = parseContentXmlFile("path-content.xml"); + + assertThat("properties.size", properties.size(), is(2)); + } + + @Test + @Ignore("Not implemented") + public void parseReferenceProperties() throws ParserConfigurationException, SAXException, IOException { + + Map<String, Object> properties = parseContentXmlFile("reference-content.xml"); + + assertThat("properties.size", properties.size(), is(3)); + } +} Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/multiple-properties-connect.xml URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/multiple-properties-connect.xml?rev=1521146&view=auto ============================================================================== (empty) Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/multiple-properties-connect.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/multiple-properties-connect.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/name-content.xml URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/name-content.xml?rev=1521146&view=auto ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/name-content.xml (added) +++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/name-content.xml Mon Sep 9 14:44:09 2013 @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" + jcr:primaryType="nt:unstructured" + linkedName="{Name}name-value"/> \ No newline at end of file Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/name-content.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/name-content.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/path-content.xml URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/path-content.xml?rev=1521146&view=auto ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/path-content.xml (added) +++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/path-content.xml Mon Sep 9 14:44:09 2013 @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" + jcr:primaryType="nt:unstructured" + replacementPath="{Path}/libs"/> \ No newline at end of file Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/path-content.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/path-content.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/reference-content.xml URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/reference-content.xml?rev=1521146&view=auto ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/reference-content.xml (added) +++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/reference-content.xml Mon Sep 9 14:44:09 2013 @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" + jcr:primaryType="nt:unstructured" + replacementReference="{Reference}16cf9306-3d0a-4906-b49d-9ed34e2d3d1e" + replacementWeakReference="{WeakReference}16cf9306-3d0a-4906-b49d-9ed34e2d3d1e"/> \ No newline at end of file Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/reference-content.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/reference-content.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/simple-content.xml URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/simple-content.xml?rev=1521146&view=auto ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/simple-content.xml (added) +++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/simple-content.xml Mon Sep 9 14:44:09 2013 @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" + jcr:primaryType="sling:Folder" + jcr:title="Application folder" + indexDuration="{Decimal}500" + indexed="{Boolean}true" + indexRatio="{Double}2.54" + lastIndexId="{Long}7293120000000" + lastIndexTime="{Date}2013-09-04T14:00:00.000+03:00"/> \ No newline at end of file Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/simple-content.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/simple-content.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Modified: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/META-INF/MANIFEST.MF URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/META-INF/MANIFEST.MF?rev=1521146&r1=1521145&r2=1521146&view=diff ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/META-INF/MANIFEST.MF (original) +++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/META-INF/MANIFEST.MF Mon Sep 9 14:44:09 2013 @@ -8,14 +8,15 @@ Require-Bundle: org.eclipse.equinox.ds;b org.eclipse.osgi.services;bundle-version="3.2.100" Import-Package: javax.jcr, javax.jcr.nodetype, + org.apache.jackrabbit.util, org.apache.jackrabbit.vault.fs, org.apache.jackrabbit.vault.fs.api, org.apache.jackrabbit.vault.fs.config, org.apache.jackrabbit.vault.fs.impl, org.apache.jackrabbit.vault.fs.impl.io, org.apache.jackrabbit.vault.util, + org.apache.sling.ide.filter, org.apache.sling.ide.serialization, org.apache.sling.ide.transport, - org.apache.sling.ide.filter, org.osgi.service.event;version="1.3.0" Service-Component: OSGI-INF/*.xml Modified: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java?rev=1521146&r1=1521145&r2=1521146&view=diff ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java (original) +++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/UpdateNodePropertiesCommand.java Mon Sep 9 14:44:09 2013 @@ -17,12 +17,13 @@ package org.apache.sling.ide.impl.vlt; import java.io.IOException; +import java.math.BigDecimal; +import java.util.Calendar; import java.util.Map; import javax.jcr.Credentials; import javax.jcr.Node; import javax.jcr.Property; -import javax.jcr.PropertyType; import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; @@ -37,7 +38,7 @@ public class UpdateNodePropertiesCommand public UpdateNodePropertiesCommand(Repository jcrRepo, Credentials credentials, FileInfo fileInfo, Map<String, Object> serializationData) { - // intention since the fileInfo refers to the .content.xml file ( TODO - should we change that )? + // intentional since the fileInfo refers to the .content.xml file ( TODO - should we change that )? super(jcrRepo, credentials, PathUtil.makePath(fileInfo.getRelativeLocation(), "")); this.serializationData = serializationData; @@ -48,6 +49,8 @@ public class UpdateNodePropertiesCommand Node node = session.getNode(getPath()); + // TODO - review for completeness and filevault compatibility + // TODO - multi-valued properties for (Map.Entry<String, Object> entry : serializationData.entrySet()) { if (node.hasProperty(entry.getKey())) { @@ -57,12 +60,26 @@ public class UpdateNodePropertiesCommand continue; } - if (prop.getType() != PropertyType.STRING) - throw new UnsupportedOperationException("Unable to set value of property '" + prop.getName() - + "' since its type is '" + prop.getType() + "'"); - } + if (entry.getValue() instanceof String) { + node.setProperty(entry.getKey(), (String) entry.getValue()); + } else if (entry.getValue() instanceof Boolean) { + node.setProperty(entry.getKey(), (Boolean) entry.getValue()); + } else if (entry.getValue() instanceof Calendar) { + node.setProperty(entry.getKey(), (Calendar) entry.getValue()); + } else if (entry.getValue() instanceof Double) { + node.setProperty(entry.getKey(), (Double) entry.getValue()); + } else if (entry.getValue() instanceof BigDecimal) { + node.setProperty(entry.getKey(), (BigDecimal) entry.getValue()); + } else if (entry.getValue() instanceof Double) { + node.setProperty(entry.getKey(), (Double) entry.getValue()); + } else if (entry.getValue() instanceof Long) { + node.setProperty(entry.getKey(), (Long) entry.getValue()); + } else { + throw new IllegalArgumentException("Unable to handle value of type '" + + entry.getValue().getClass().getName() + "' for property '" + entry.getKey() + "'"); + } - node.setProperty(entry.getKey(), entry.getValue().toString()); + } } return null; Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java?rev=1521146&view=auto ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java (added) +++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java Mon Sep 9 14:44:09 2013 @@ -0,0 +1,116 @@ +/* + * 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.sling.ide.impl.vlt.serialization; + +import java.math.BigDecimal; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +import org.apache.jackrabbit.util.ISO8601; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +// TODO - worth investigating whether we can properly use org.apache.jackrabbit.vault.util.DocViewProperty instead +public class ContentXmlHandler extends DefaultHandler { + + private final Map<String, Object> properties = new HashMap<String, Object>(); + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + if (!qName.equals("jcr:root")) { + return; + } + + for (int i = 0; i < attributes.getLength(); i++) { + + String attributeQName = attributes.getQName(i); + String value = attributes.getValue(i); + Object typedValue = TypeHint.parsePossiblyTypedValue(value); + + properties.put(attributeQName, typedValue); + } + } + + public Map<String, Object> getProperties() { + return properties; + } + + // TODO - validate that this is comprehensive + static enum TypeHint { + BOOLEAN("Boolean") { + @Override + Object parseValue(String rawValue) { + return Boolean.valueOf(rawValue); + } + }, + DATE("Date") { + @Override + Object parseValue(String rawValue) { + return ISO8601.parse(rawValue); + } + }, + DOUBLE("Double") { + @Override + Object parseValue(String rawValue) { + return Double.parseDouble(rawValue); + } + }, + LONG("Long") { + @Override + Object parseValue(String rawValue) { + return Long.valueOf(rawValue); + } + }, + DECIMAL("Decimal") { + @Override + Object parseValue(String rawValue) { + return new BigDecimal(rawValue); + } + }; + + static Object parsePossiblyTypedValue(String value) { + + if (value.charAt(0) != '{') { + return value; + } + + int hintEnd = value.indexOf('}'); + + String rawHint = value.substring(1, hintEnd); + + for (TypeHint hint : EnumSet.allOf(TypeHint.class)) { + if (hint.rawHint.equals(rawHint)) { + return hint.parseValue(value.substring(hintEnd + 1)); + } + } + + throw new IllegalArgumentException("Unknown typeHint value '" + rawHint + "'"); + } + + private final String rawHint; + + private TypeHint(String rawHint) { + + this.rawHint = rawHint; + } + + abstract Object parseValue(String rawValue); + + } +} Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java?rev=1521146&r1=1521145&r2=1521146&view=diff ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java (original) +++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/VltSerializationManager.java Mon Sep 9 14:44:09 2013 @@ -135,7 +135,7 @@ public class VltSerializationManager imp factory.setNamespaceAware(true); factory.setFeature("http://xml.org/sax/features/namespace-prefixes", false); SAXParser parser = factory.newSAXParser(); - ContextXmlHandler handler = new ContextXmlHandler(); + ContentXmlHandler handler = new ContentXmlHandler(); parser.parse(source, handler); return handler.getProperties(); Modified: sling/branches/tooling-ide-vlt/tooling/ide/pom.xml URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/pom.xml?rev=1521146&r1=1521145&r2=1521146&view=diff ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/pom.xml (original) +++ sling/branches/tooling-ide-vlt/tooling/ide/pom.xml Mon Sep 9 14:44:09 2013 @@ -15,6 +15,7 @@ <module>impl-resource-test</module> <module>vlt-wrapper</module> <module>impl-vlt</module> + <module>impl-vlt-test</module> <module>eclipse-core</module> <module>eclipse-ui</module> <module>feature</module> Modified: sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF URL: http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF?rev=1521146&r1=1521145&r2=1521146&view=diff ============================================================================== --- sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF (original) +++ sling/branches/tooling-ide-vlt/tooling/ide/vlt-wrapper/META-INF/MANIFEST.MF Mon Sep 9 14:44:09 2013 @@ -17,6 +17,7 @@ Bundle-ClassPath: ., lib/jackrabbit-webdav-2.4.0.jar Export-Package: javax.jcr, javax.jcr.nodetype, + org.apache.jackrabbit.util, org.apache.jackrabbit.vault.davex, org.apache.jackrabbit.vault.fs, org.apache.jackrabbit.vault.fs.api,