This is an automated email from the ASF dual-hosted git repository. sseifert pushed a commit to branch feature/SLING-12281-parent-60 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-contentparser-xml-jcr.git
commit b5fa9d4c55520af38179731a48397c05e8113ec1 Author: Stefan Seifert <stefanseif...@users.noreply.github.com> AuthorDate: Tue Apr 9 10:33:50 2024 +0200 SLING-12281 apply spotless code formatting --- pom.xml | 32 +++++----- .../xml/jcr/internal/JCRXMLContentParser.java | 56 ++++++++--------- .../xml/jcr/internal/JcrXmlValueConverter.java | 43 ++++++------- .../xml/jcr/internal/JCRXMLContentParserTest.java | 72 ++++++++++++---------- .../xml/jcr/internal/JcrXmlValueConverterTest.java | 70 +++++++++++---------- 5 files changed, 138 insertions(+), 135 deletions(-) diff --git a/pom.xml b/pom.xml index 328b9bd..ead730c 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="ISO-8859-1"?> +<?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 @@ -30,29 +30,15 @@ <version>2.0.1-SNAPSHOT</version> <name>Apache Sling Content Parser for Jackrabbit FileVault XML</name> - <description> - Apache Sling Content Parser for resource trees stored in JackRabbit FileVault XML files - </description> + <description>Apache Sling Content Parser for resource trees stored in JackRabbit FileVault XML files</description> <scm> <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-contentparser-xml-jcr.git</connection> <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-contentparser-xml-jcr.git</developerConnection> - <url>https://github.com/apache/sling-org-apache-sling-contentparser-xml-jcr.git</url> <tag>HEAD</tag> + <url>https://github.com/apache/sling-org-apache-sling-contentparser-xml-jcr.git</url> </scm> - <build> - <plugins> - <plugin> - <groupId>biz.aQute.bnd</groupId> - <artifactId>bnd-baseline-maven-plugin</artifactId> - <configuration> - <failOnMissing>false</failOnMissing> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> <dependency> <groupId>org.apache.sling</groupId> @@ -95,4 +81,16 @@ <scope>test</scope> </dependency> </dependencies> + + <build> + <plugins> + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-baseline-maven-plugin</artifactId> + <configuration> + <failOnMissing>false</failOnMissing> + </configuration> + </plugin> + </plugins> + </build> </project> diff --git a/src/main/java/org/apache/sling/contentparser/xml/jcr/internal/JCRXMLContentParser.java b/src/main/java/org/apache/sling/contentparser/xml/jcr/internal/JCRXMLContentParser.java index 2204a29..eb30c8a 100644 --- a/src/main/java/org/apache/sling/contentparser/xml/jcr/internal/JCRXMLContentParser.java +++ b/src/main/java/org/apache/sling/contentparser/xml/jcr/internal/JCRXMLContentParser.java @@ -1,23 +1,27 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.contentparser.xml.jcr.internal; +import javax.xml.XMLConstants; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + import java.io.IOException; import java.io.InputStream; import java.util.ArrayDeque; @@ -27,10 +31,6 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import javax.xml.XMLConstants; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - import org.apache.jackrabbit.JcrConstants; import org.apache.jackrabbit.util.ISO9075; import org.apache.sling.contentparser.api.ContentHandler; @@ -43,10 +43,7 @@ import org.xml.sax.helpers.DefaultHandler; @Component( service = ContentParser.class, - property = { - ContentParser.SERVICE_PROPERTY_CONTENT_TYPE + "=jcr-xml" - } -) + property = {ContentParser.SERVICE_PROPERTY_CONTENT_TYPE + "=jcr-xml"}) public final class JCRXMLContentParser implements ContentParser { private final SAXParserFactory saxParserFactory; @@ -134,8 +131,8 @@ public final class JCRXMLContentParser implements ContentParser { // get properties Map<String, Object> properties = new HashMap<>(); for (int i = 0; i < attributes.getLength(); i++) { - String propertyName = removePrefixFromPropertyName(parserOptions.getRemovePropertyNamePrefixes(), - decodeName(attributes.getQName(i))); + String propertyName = removePrefixFromPropertyName( + parserOptions.getRemovePropertyNamePrefixes(), decodeName(attributes.getQName(i))); if (!parserOptions.getIgnorePropertyNames().contains(propertyName)) { Object value = JcrXmlValueConverter.parseValue(propertyName, attributes.getValue(i)); if (value != null) { @@ -178,7 +175,6 @@ public final class JCRXMLContentParser implements ContentParser { } else { return isIgnoredPath(path); } - } private String removePrefixFromPropertyName(Set<String> prefixes, String propertyName) { @@ -189,7 +185,5 @@ public final class JCRXMLContentParser implements ContentParser { } return propertyName; } - } - } diff --git a/src/main/java/org/apache/sling/contentparser/xml/jcr/internal/JcrXmlValueConverter.java b/src/main/java/org/apache/sling/contentparser/xml/jcr/internal/JcrXmlValueConverter.java index 8d1695c..9b74a49 100644 --- a/src/main/java/org/apache/sling/contentparser/xml/jcr/internal/JcrXmlValueConverter.java +++ b/src/main/java/org/apache/sling/contentparser/xml/jcr/internal/JcrXmlValueConverter.java @@ -1,23 +1,25 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.contentparser.xml.jcr.internal; +import javax.jcr.PropertyType; + import java.lang.reflect.Array; import java.math.BigDecimal; import java.net.URI; @@ -25,8 +27,6 @@ import java.net.URISyntaxException; import java.util.Calendar; import java.util.UUID; -import javax.jcr.PropertyType; - import org.apache.jackrabbit.util.ISO8601; import org.apache.jackrabbit.vault.util.DocViewProperty; @@ -105,7 +105,6 @@ class JcrXmlValueConverter { return null; default: throw new IllegalArgumentException("Unexpected type: " + PropertyType.nameFromValue(type)); - } } @@ -142,8 +141,6 @@ class JcrXmlValueConverter { return null; default: throw new IllegalArgumentException("Unexpected type: " + PropertyType.nameFromValue(type)); - } } - } diff --git a/src/test/java/org/apache/sling/contentparser/xml/jcr/internal/JCRXMLContentParserTest.java b/src/test/java/org/apache/sling/contentparser/xml/jcr/internal/JCRXMLContentParserTest.java index 19707f5..699a0b9 100644 --- a/src/test/java/org/apache/sling/contentparser/xml/jcr/internal/JCRXMLContentParserTest.java +++ b/src/test/java/org/apache/sling/contentparser/xml/jcr/internal/JCRXMLContentParserTest.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.contentparser.xml.jcr.internal; import java.io.File; @@ -62,7 +62,7 @@ public class JCRXMLContentParserTest { assertEquals("app:PageContent", child.getProperties().get("jcr:primaryType")); } - @Test(expected= IOException.class) + @Test(expected = IOException.class) public void testParseInvalidJcrXml() throws Exception { file = new File("src/test/resources/invalid-test/invalid.jcr.xml"); parse(underTest, file); @@ -73,17 +73,17 @@ public class JCRXMLContentParserTest { ContentElement content = parse(underTest, file); ContentElement child = content.getChild("jcr:content"); assertNotNull("Expected child at jcr:content", child); - Map<String,Object> props = child.getProperties(); - + Map<String, Object> props = child.getProperties(); + assertEquals("en", props.get("jcr:title")); assertEquals(true, props.get("includeAside")); assertEquals(1234567890123L, props.get("longProp")); assertEquals(new BigDecimal("1.2345"), props.get("decimalProp")); - - assertArrayEquals(new String[] { "aa", "bb", "cc" }, (String[])props.get("stringPropMulti")); - assertArrayEquals(new Long[] { 1234567890123L, 55L }, (Long[])props.get("longPropMulti")); - - Calendar calendar = (Calendar)props.get("dateProp"); + + assertArrayEquals(new String[] {"aa", "bb", "cc"}, (String[]) props.get("stringPropMulti")); + assertArrayEquals(new Long[] {1234567890123L, 55L}, (Long[]) props.get("longPropMulti")); + + Calendar calendar = (Calendar) props.get("dateProp"); calendar.setTimeZone(TimeZone.getTimeZone("GMT+2")); assertEquals(2014, calendar.get(Calendar.YEAR)); assertEquals(9, calendar.get(Calendar.MONTH) + 1); @@ -102,15 +102,20 @@ public class JCRXMLContentParserTest { @Test public void testIgnoreResourcesProperties() throws Exception { - ContentElement content = parse(underTest, - new ParserOptions().ignoreResourceNames(Collections.unmodifiableSet(new HashSet<>(Arrays.asList("teaserbar", "aside")))) - .ignorePropertyNames(Collections.unmodifiableSet(new HashSet<>(Arrays.asList("longProp", "jcr:title")))), file); + ContentElement content = parse( + underTest, + new ParserOptions() + .ignoreResourceNames( + Collections.unmodifiableSet(new HashSet<>(Arrays.asList("teaserbar", "aside")))) + .ignorePropertyNames( + Collections.unmodifiableSet(new HashSet<>(Arrays.asList("longProp", "jcr:title")))), + file); ContentElement child = content.getChild("jcr:content"); assertNotNull("Expected child at jcr:content", child); assertEquals("HOME", child.getProperties().get("navTitle")); assertNull(child.getProperties().get("jcr:title")); assertNull(child.getProperties().get("longProp")); - + assertNull(child.getChildren().get("teaserbar")); assertNull(child.getChildren().get("aside")); assertNotNull(child.getChildren().get("content")); @@ -120,11 +125,13 @@ public class JCRXMLContentParserTest { public void testGetChild() throws Exception { ContentElement content = parse(underTest, file); assertNull(content.getName()); - + ContentElement deepChild = content.getChild("jcr:content/teaserbar/teaserbaritem"); assertNotNull("Expected child at jcr:content/teaserbar/teaserbaritem", deepChild); assertEquals("teaserbaritem", deepChild.getName()); - assertEquals("samples/sample-app/components/content/teaserbar/teaserbarItem", deepChild.getProperties().get("sling:resourceType")); + assertEquals( + "samples/sample-app/components/content/teaserbar/teaserbarItem", + deepChild.getProperties().get("sling:resourceType")); ContentElement invalidChild = content.getChild("non/existing/path"); assertNull(invalidChild); @@ -142,5 +149,4 @@ public class JCRXMLContentParserTest { assertEquals("test", child.getProperties().get("teaserbaritem")); assertNotNull(child.getChildren().get("teaserbaritem")); } - } diff --git a/src/test/java/org/apache/sling/contentparser/xml/jcr/internal/JcrXmlValueConverterTest.java b/src/test/java/org/apache/sling/contentparser/xml/jcr/internal/JcrXmlValueConverterTest.java index f33b13c..49eb48a 100644 --- a/src/test/java/org/apache/sling/contentparser/xml/jcr/internal/JcrXmlValueConverterTest.java +++ b/src/test/java/org/apache/sling/contentparser/xml/jcr/internal/JcrXmlValueConverterTest.java @@ -1,21 +1,21 @@ -/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~ 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. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ +/* + * 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.contentparser.xml.jcr.internal; import java.math.BigDecimal; @@ -31,7 +31,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; public class JcrXmlValueConverterTest { - + private static final String NAME = "prop1"; @Test @@ -56,9 +56,15 @@ public class JcrXmlValueConverterTest { @Test public void testStringArray() { - assertArrayEquals(new Object[] { "myString1", "myString2" }, (Object[]) parseValue(NAME, "[myString1,myString2]")); - assertArrayEquals(new Object[] { "myString1,[]\\äöü߀", "myString2", "myString3 [ ] { } \\ ,", "", "[myString5]", "{myString6}" }, - (Object[]) parseValue(NAME, "[myString1\\,[]\\\\äöü߀,myString2,myString3 [ ] { } \\\\ \\,,,[myString5],{myString6}]")); + assertArrayEquals( + new Object[] {"myString1", "myString2"}, (Object[]) parseValue(NAME, "[myString1,myString2]")); + assertArrayEquals( + new Object[] { + "myString1,[]\\äöü߀", "myString2", "myString3 [ ] { } \\ ,", "", "[myString5]", "{myString6}" + }, + (Object[]) parseValue( + NAME, + "[myString1\\,[]\\\\äöü߀,myString2,myString3 [ ] { } \\\\ \\,,,[myString5],{myString6}]")); } @Test @@ -69,7 +75,7 @@ public class JcrXmlValueConverterTest { @Test public void testBooleanArray() { - assertArrayEquals(new Object[] { true, false }, (Object[]) parseValue(NAME, "{Boolean}[true,false]")); + assertArrayEquals(new Object[] {true, false}, (Object[]) parseValue(NAME, "{Boolean}[true,false]")); } @Test @@ -80,8 +86,9 @@ public class JcrXmlValueConverterTest { @Test public void testLongArray() { - assertArrayEquals(new Object[] { 1L, 2L }, (Object[]) parseValue(NAME, "{Long}[1,2]")); - assertArrayEquals(new Object[] { 10000000000L, 20000000000L }, (Object[]) parseValue(NAME, "{Long}[10000000000,20000000000]")); + assertArrayEquals(new Object[] {1L, 2L}, (Object[]) parseValue(NAME, "{Long}[1,2]")); + assertArrayEquals(new Object[] {10000000000L, 20000000000L}, (Object[]) + parseValue(NAME, "{Long}[10000000000,20000000000]")); } @Test @@ -91,12 +98,13 @@ public class JcrXmlValueConverterTest { @Test public void testDoubleArray() { - assertArrayEquals(new Object[] { new BigDecimal("1.234"), new BigDecimal("2.345") }, (Object[]) parseValue(NAME, "{Decimal}[1.234,2.345]")); + assertArrayEquals(new Object[] {new BigDecimal("1.234"), new BigDecimal("2.345")}, (Object[]) + parseValue(NAME, "{Decimal}[1.234,2.345]")); } @Test public void testCalendar() { - Calendar value = (Calendar)parseValue(NAME, "{Date}2010-09-05T15:10:20.000Z"); + Calendar value = (Calendar) parseValue(NAME, "{Date}2010-09-05T15:10:20.000Z"); assertEquals(2010, value.get(Calendar.YEAR)); assertEquals(8, value.get(Calendar.MONTH)); assertEquals(5, value.get(Calendar.DAY_OF_MONTH)); @@ -104,20 +112,20 @@ public class JcrXmlValueConverterTest { @Test public void testStringArrayRepPrivileges() { - assertArrayEquals(new Object[] { "rep:write", "crx:replicate", "jcr:read" }, (Object[]) parseValue(NAME, "{Name}[rep:write,crx:replicate,jcr:read]")); + assertArrayEquals(new Object[] {"rep:write", "crx:replicate", "jcr:read"}, (Object[]) + parseValue(NAME, "{Name}[rep:write,crx:replicate,jcr:read]")); } @Test public void testReference() { UUID uuid = UUID.randomUUID(); - UUID value = (UUID)parseValue(NAME, "{Reference}" + uuid.toString()); + UUID value = (UUID) parseValue(NAME, "{Reference}" + uuid.toString()); assertEquals(uuid, value); } @Test public void testURI() { - URI value = (URI)parseValue(NAME, "{URI}http://www.jodelkaiser.de/"); + URI value = (URI) parseValue(NAME, "{URI}http://www.jodelkaiser.de/"); assertEquals("http://www.jodelkaiser.de/", value.toString()); } - }