You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2013/09/19 13:13:17 UTC
svn commit: r1524696 - in /sling/branches/tooling-ide-vlt/tooling/ide:
impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/
impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/
impl-vlt/src/org/apache/sling/...
Author: rombert
Date: Thu Sep 19 11:13:16 2013
New Revision: 1524696
URL: http://svn.apache.org/r1524696
Log:
SLING-2989 - [Tooling] integrate with vlt once available
Fix parsing of child paths when serializing the .content.xml for the
root node.
Added:
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/root-content.xml (with props)
Modified:
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java
Modified: 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=1524696&r1=1524695&r2=1524696&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java (original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandlerTest.java Thu Sep 19 11:13:16 2013
@@ -19,6 +19,7 @@ package org.apache.sling.ide.impl.vlt.se
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.array;
import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertThat;
import java.io.IOException;
@@ -44,7 +45,7 @@ public class ContentXmlHandlerTest {
@Test
public void simpleContentXml() throws ParserConfigurationException, SAXException, IOException {
- Map<String, Object> properties = parseContentXmlFile("simple-content.xml");
+ Map<String, Object> properties = parseContentXmlFile("simple-content.xml", "/").getProperties();
assertThat("properties.size", properties.size(), is(11));
@@ -62,7 +63,8 @@ public class ContentXmlHandlerTest {
}
- private Map<String, Object> parseContentXmlFile(String fileName) throws ParserConfigurationException, SAXException,
+ private ResourceProxy parseContentXmlFile(String fileName, String rootResourcePath)
+ throws ParserConfigurationException, SAXException,
IOException {
InputSource source = new InputSource(getClass().getResourceAsStream(fileName));
@@ -71,17 +73,17 @@ public class ContentXmlHandlerTest {
factory.setNamespaceAware(true);
factory.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
SAXParser parser = factory.newSAXParser();
- ContentXmlHandler handler = new ContentXmlHandler("/");
+ ContentXmlHandler handler = new ContentXmlHandler(rootResourcePath);
parser.parse(source, handler);
- return handler.getRoot().getProperties();
+ return handler.getRoot();
}
@Test
@SuppressWarnings("unchecked")
public void parseMultiValuedProperties() throws ParserConfigurationException, SAXException, IOException {
- Map<String, Object> properties = parseContentXmlFile("multivalued-properties-content.xml");
+ Map<String, Object> properties = parseContentXmlFile("multivalued-properties-content.xml", "/").getProperties();
assertThat("properties.size", properties.size(), is(7));
assertThat("properties[values]", (String[]) properties.get("values"),
@@ -101,16 +103,7 @@ public class ContentXmlHandlerTest {
@Test
public void parseFullCoverageXmlFile() throws ParserConfigurationException, SAXException, IOException {
- InputSource source = new InputSource(getClass().getResourceAsStream("full-coverage.xml"));
-
- 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("/apps/full-coverage");
- parser.parse(source, handler);
-
- ResourceProxy root = handler.getRoot();
+ ResourceProxy root = parseContentXmlFile("full-coverage.xml", "/apps/full-coverage");
assertThat("full-coverage path", root.getPath(), is("/apps/full-coverage"));
assertThat("full-coverage properties.size", root.getProperties().size(), is(3));
@@ -131,11 +124,24 @@ public class ContentXmlHandlerTest {
}
+ @Test
+ public void parseRootContentXml() throws ParserConfigurationException, SAXException, IOException {
+
+ ResourceProxy root = parseContentXmlFile("root-content.xml", "/");
+
+ assertThat("root contains /jcr:system", root.getChildren(), hasItem(path("/jcr:system")));
+ }
+
private static Matcher<Calendar> millis(long millis) {
return new CalendarTimeInMillisMatcher(millis);
}
+ private static Matcher<ResourceProxy> path(String path) {
+
+ return new ResourcePathMatcher(path);
+ }
+
static class CalendarTimeInMillisMatcher extends TypeSafeMatcher<Calendar> {
private final long timeInMillis;
@@ -155,4 +161,24 @@ public class ContentXmlHandlerTest {
}
}
+
+ static class ResourcePathMatcher extends TypeSafeMatcher<ResourceProxy> {
+
+ private final String resourcePath;
+
+ private ResourcePathMatcher(String resourcePath) {
+
+ this.resourcePath = resourcePath;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("Resource with path ").appendValue(resourcePath);
+ }
+
+ @Override
+ protected boolean matchesSafely(ResourceProxy item) {
+ return resourcePath.equals(item.getPath());
+ }
+ }
}
Added: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/root-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/root-content.xml?rev=1524696&view=auto
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/root-content.xml (added)
+++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/root-content.xml Thu Sep 19 11:13:16 2013
@@ -0,0 +1,17 @@
+<?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" xmlns:rep="internal"
+ jcr:mixinTypes="[rep:AccessControllable]"
+ jcr:primaryType="rep:root"
+ sling:resourceType="sling:redirect"
+ sling:target="/index.html">
+ <jcr:system/>
+ <rep:policy/>
+ <var/>
+ <ROOT/>
+ <index.html/>
+ <signup.html/>
+ <sling-logo.png/>
+ <sling-test/>
+ <sling.css/>
+ <libs/>
+</jcr:root>
Propchange: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/serialization/root-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/root-content.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: 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=1524696&r1=1524695&r2=1524696&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java (original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/serialization/ContentXmlHandler.java Thu Sep 19 11:13:16 2013
@@ -48,7 +48,13 @@ public class ContentXmlHandler extends D
current = root;
} else {
ResourceProxy parent = queue.peekLast();
- current = new ResourceProxy(parent.getPath() + "/" + qName);
+
+ StringBuilder path = new StringBuilder(parent.getPath());
+ if (path.charAt(path.length() - 1) != '/')
+ path.append('/');
+ path.append(qName);
+
+ current = new ResourceProxy(path.toString());
parent.addChild(current);
}