SLING-8570 - Extract a generic Content Parser API from org.apache.sling.jcr.contentparser with pluggable implementations
* minor code cleanup
diff --git a/src/main/java/org/apache/sling/contentparser/testutils/mapsupport/ContentElement.java b/src/main/java/org/apache/sling/contentparser/testutils/mapsupport/ContentElement.java
index d5bb5ab..0a47845 100644
--- a/src/main/java/org/apache/sling/contentparser/testutils/mapsupport/ContentElement.java
+++ b/src/main/java/org/apache/sling/contentparser/testutils/mapsupport/ContentElement.java
@@ -72,8 +72,8 @@
* @return child or {@code null} if no child was found for the specified {@code path}
*/
public ContentElement getChild(String path) {
- String name = StringUtils.substringBefore(path, "/");
- ContentElement child = children.get(name);
+ String childName = StringUtils.substringBefore(path, "/");
+ ContentElement child = children.get(childName);
if (child == null) {
return null;
}
diff --git a/src/main/java/org/apache/sling/contentparser/testutils/mapsupport/ContentElementHandler.java b/src/main/java/org/apache/sling/contentparser/testutils/mapsupport/ContentElementHandler.java
index 0714ae7..b2de181 100644
--- a/src/main/java/org/apache/sling/contentparser/testutils/mapsupport/ContentElementHandler.java
+++ b/src/main/java/org/apache/sling/contentparser/testutils/mapsupport/ContentElementHandler.java
@@ -31,7 +31,7 @@
public final class ContentElementHandler implements ContentHandler {
private ContentElement root;
- private Pattern PATH_PATTERN = Pattern.compile("^((/[^/]+)*)(/([^/]+))$");
+ private static final Pattern PATH_PATTERN = Pattern.compile("^((/[^/]+)*)(/([^/]+))$");
@Override
public void resource(String path, Map<String, Object> properties) {
@@ -40,11 +40,11 @@
}
else {
if (root == null) {
- throw new RuntimeException("Root resource not set.");
+ throw new ContentElementHandlerException("Root resource not set.");
}
Matcher matcher = PATH_PATTERN.matcher(path);
if (!matcher.matches()) {
- throw new RuntimeException("Unexpected path:" + path);
+ throw new ContentElementHandlerException("Unexpected path:" + path);
}
String relativeParentPath = StringUtils.stripStart(matcher.group(1), "/");
String name = matcher.group(4);
@@ -56,7 +56,7 @@
parent = root.getChild(relativeParentPath);
}
if (parent == null) {
- throw new RuntimeException("Parent '" + relativeParentPath + "' does not exist.");
+ throw new ContentElementHandlerException("Parent '" + relativeParentPath + "' does not exist.");
}
parent.getChildren().put(name, new ContentElement(name, properties));
}
diff --git a/src/main/java/org/apache/sling/contentparser/testutils/mapsupport/ContentElementHandlerException.java b/src/main/java/org/apache/sling/contentparser/testutils/mapsupport/ContentElementHandlerException.java
new file mode 100644
index 0000000..7f1dd71
--- /dev/null
+++ b/src/main/java/org/apache/sling/contentparser/testutils/mapsupport/ContentElementHandlerException.java
@@ -0,0 +1,49 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.testutils.mapsupport;
+
+/**
+ * {@code RuntimeException} that's thrown by the {@link ContentElementHandler} when building {@link ContentElement}s.
+ */
+public class ContentElementHandlerException extends RuntimeException {
+
+ public ContentElementHandlerException() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ContentElementHandlerException(String message) {
+ super(message);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ContentElementHandlerException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ContentElementHandlerException(Throwable cause) {
+ super(cause);
+ }
+}