This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.jcr.contentloader-2.0.4-incubator in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git
commit e0a5ce483c1f37c0c52d20d04e64f41a6d9d9c1c Author: Bertrand Delacretaz <[email protected]> AuthorDate: Mon Mar 2 10:46:25 2009 +0000 SLING-857 - test case for XmlReader using an XSLT transform contributed by Vidar S. Ramdal, thanks! git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/bundles/jcr/contentloader@749266 13f79535-47bb-0310-9956-ffa450edef68 --- .../internal/readers/XmlReaderTest.java | 76 ++++++++++++++++++++++ src/test/resources/reader/sample.xml | 32 +++++++++ src/test/resources/reader/sample.xsl | 58 +++++++++++++++++ 3 files changed, 166 insertions(+) diff --git a/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java b/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java new file mode 100644 index 0000000..554c5ea --- /dev/null +++ b/src/test/java/org/apache/sling/jcr/contentloader/internal/readers/XmlReaderTest.java @@ -0,0 +1,76 @@ +/* + * 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.jcr.contentloader.internal.readers; + +import junit.framework.TestCase; +import org.apache.sling.jcr.contentloader.internal.ContentCreator; + +import javax.jcr.RepositoryException; +import java.io.File; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; + +/** + * Test the XmlReader with an XSLT transform + */ +public class XmlReaderTest extends TestCase { + + public void testXmlReader() throws Exception { + XmlReader reader = new XmlReader(); + File file = new File("src/test/resources/reader/sample.xml"); + final URL testdata = file.toURI().toURL(); + final MockContentCreator creator = new MockContentCreator(); + reader.parse(testdata, creator); + assertEquals("Did not create expected number of nodes", 1, creator.size()); + } + + @SuppressWarnings("serial") + private static class MockContentCreator extends ArrayList<String> implements ContentCreator { + + public MockContentCreator() { + } + + public void createNode(String name, String primaryNodeType, String[] mixinNodeTypes) throws RepositoryException { + this.add(name); + } + + public void finishNode() throws RepositoryException { + } + + public void createProperty(String name, int propertyType, String value) throws RepositoryException { + } + + public void createProperty(String name, int propertyType, String[] values) throws RepositoryException { + } + + public void createProperty(String name, Object value) throws RepositoryException { + } + + public void createProperty(String name, Object[] values) throws RepositoryException { + } + + public void createFileAndResourceNode(String name, InputStream data, String mimeType, long lastModified) throws RepositoryException { + } + + public boolean switchCurrentNode(String subPath, String newNodeType) throws RepositoryException { + return true; + } + } +} diff --git a/src/test/resources/reader/sample.xml b/src/test/resources/reader/sample.xml new file mode 100644 index 0000000..b0374d1 --- /dev/null +++ b/src/test/resources/reader/sample.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> + + +<!-- + This needs to be transformed by sample.xsl + to create valid node/propertie structures + that the standard XML importer can accept. +--> +<?xml-stylesheet type="text/xsl" href="sample.xsl"?> +<pages> + <page name="firstpage"> + <content>some text</content> + </page> +</pages> \ No newline at end of file diff --git a/src/test/resources/reader/sample.xsl b/src/test/resources/reader/sample.xsl new file mode 100644 index 0000000..e9072cc --- /dev/null +++ b/src/test/resources/reader/sample.xsl @@ -0,0 +1,58 @@ +<?xml version="1.0"?> + +<!-- + * 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. +--> + +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + + <xsl:output indent="yes" /> + + <xsl:template match="/"> + <xsl:apply-templates select="pages/page"/> + </xsl:template> + + <xsl:template match="page"> + <node> + <name><xsl:value-of select="@name"/></name> + <primaryNodeType>nt:unstructured</primaryNodeType> + <mixinNodeTypes/> + <properties> + <xsl:call-template name="property"> + <xsl:with-param name="name">content</xsl:with-param> + <xsl:with-param name="value"><xsl:value-of select="content"/></xsl:with-param> + </xsl:call-template> + <xsl:call-template name="property"> + <xsl:with-param name="name">sling:resourceType</xsl:with-param> + <xsl:with-param name="value">page</xsl:with-param> + </xsl:call-template> + </properties> + </node> + </xsl:template> + + <xsl:template name="property"> + <xsl:param name="name"/> + <xsl:param name="value"/> + <property> + <name><xsl:value-of select="$name"/></name> + <type>String</type> + <value><xsl:value-of select="$value"/></value> + </property> + </xsl:template> + +</xsl:stylesheet> \ No newline at end of file -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
