sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject [sling-org-apache-sling-commons-html] branch master updated: SLING-6783 Updates for Commons HTML
Date Mon, 02 Apr 2018 09:30:39 GMT
This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-html.git


The following commit(s) were added to refs/heads/master by this push:
     new 8dca770  SLING-6783 Updates for Commons HTML
8dca770 is described below

commit 8dca770393fdd1f7134ad1abb9706eeab3c680e6
Author: Oliver Lietz <olli@apache.org>
AuthorDate: Mon Apr 2 11:30:31 2018 +0200

    SLING-6783 Updates for Commons HTML
    
    fix features/properties mess
---
 .../commons/html/internal/TagsoupHtmlParser.java     | 20 ++++++++++----------
 .../internal/TagsoupHtmlParserConfiguration.java     |  6 +++---
 .../sling/commons/html/it/TagsoupHtmlParserIT.java   | 10 +++++-----
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/main/java/org/apache/sling/commons/html/internal/TagsoupHtmlParser.java b/src/main/java/org/apache/sling/commons/html/internal/TagsoupHtmlParser.java
index 082f5b0..6b63a65 100644
--- a/src/main/java/org/apache/sling/commons/html/internal/TagsoupHtmlParser.java
+++ b/src/main/java/org/apache/sling/commons/html/internal/TagsoupHtmlParser.java
@@ -49,7 +49,7 @@ import org.xml.sax.ext.LexicalHandler;
 )
 public class TagsoupHtmlParser implements HtmlParser {
 
-    private Map<String, Boolean> properties = Collections.synchronizedMap(new LinkedHashMap<>());
+    private Map<String, Boolean> features = Collections.synchronizedMap(new LinkedHashMap<>());
 
     @Activate
     private void activate(final TagsoupHtmlParserConfiguration configuration) {
@@ -63,14 +63,14 @@ public class TagsoupHtmlParser implements HtmlParser {
 
     @Deactivate
     private void deactivate() {
-        properties.clear();
+        features.clear();
     }
 
     private void configure(final TagsoupHtmlParserConfiguration configuration) {
-        properties.clear();
-        final Map<String, String> map = PropertiesUtil.toMap(configuration.parser_properties(),
new String[]{});
+        features.clear();
+        final Map<String, String> map = PropertiesUtil.toMap(configuration.parser_features(),
new String[]{});
         for (final String key : map.keySet()) {
-            properties.put(key, Boolean.valueOf(map.get(key)));
+            features.put(key, Boolean.valueOf(map.get(key)));
         }
     }
 
@@ -79,7 +79,7 @@ public class TagsoupHtmlParser implements HtmlParser {
      */
     @Override
     public void parse(final InputStream stream, final String encoding, final ContentHandler
contentHandler) throws SAXException {
-        final Parser parser = buildParser(properties, contentHandler);
+        final Parser parser = buildParser(features, contentHandler);
         final InputSource source = new InputSource(stream);
         source.setEncoding(encoding);
         try {
@@ -101,7 +101,7 @@ public class TagsoupHtmlParser implements HtmlParser {
         source.setSystemId(systemId);
 
         try {
-            final Parser parser = buildParser(properties, builder);
+            final Parser parser = buildParser(features, builder);
             parser.parse(source);
         } catch (SAXException se) {
             if (se.getCause() instanceof IOException) {
@@ -112,14 +112,14 @@ public class TagsoupHtmlParser implements HtmlParser {
         return builder.getDocument();
     }
 
-    private Parser buildParser(final Map<String, Boolean> properties, final ContentHandler
contentHandler) throws SAXException {
+    private Parser buildParser(final Map<String, Boolean> features, final ContentHandler
contentHandler) throws SAXException {
         final Parser parser = new Parser();
         parser.setContentHandler(contentHandler);
         if (contentHandler instanceof LexicalHandler) {
             parser.setProperty("http://xml.org/sax/properties/lexical-handler", contentHandler);
         }
-        for (final String key : properties.keySet()) {
-            parser.setProperty(key, properties.get(key));
+        for (final String key : features.keySet()) {
+            parser.setFeature(key, features.get(key));
         }
         return parser;
     }
diff --git a/src/main/java/org/apache/sling/commons/html/internal/TagsoupHtmlParserConfiguration.java
b/src/main/java/org/apache/sling/commons/html/internal/TagsoupHtmlParserConfiguration.java
index 95fd232..dd1ccef 100644
--- a/src/main/java/org/apache/sling/commons/html/internal/TagsoupHtmlParserConfiguration.java
+++ b/src/main/java/org/apache/sling/commons/html/internal/TagsoupHtmlParserConfiguration.java
@@ -28,9 +28,9 @@ import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 @interface TagsoupHtmlParserConfiguration {
 
     @AttributeDefinition(
-        name = "parser properties",
-        description = "Additional properties to be applied to the underlying parser in the
format of key=[true|false]"
+        name = "parser features",
+        description = "Turn features in the underlying parser on or off by setting featureID=[true|false]"
     )
-    String[] parser_properties() default {};
+    String[] parser_features() default {};
 
 }
diff --git a/src/test/java/org/apache/sling/commons/html/it/TagsoupHtmlParserIT.java b/src/test/java/org/apache/sling/commons/html/it/TagsoupHtmlParserIT.java
index 1f4c585..095aabc 100644
--- a/src/test/java/org/apache/sling/commons/html/it/TagsoupHtmlParserIT.java
+++ b/src/test/java/org/apache/sling/commons/html/it/TagsoupHtmlParserIT.java
@@ -50,7 +50,7 @@ public class TagsoupHtmlParserIT extends HtmlTestSupport {
         return new Option[]{
             this.baseConfiguration(),
             newConfiguration("org.apache.sling.commons.html.internal.TagsoupHtmlParser")
-                .put("parser.properties", "foo=true")
+                .put("parser.features", "foo=true")
                 .asOption(),
         };
     }
@@ -61,10 +61,10 @@ public class TagsoupHtmlParserIT extends HtmlTestSupport {
     }
 
     @Test
-    public void testConfiguration() throws IllegalAccessException {
-        @SuppressWarnings("unchecked") final Map<String, Boolean> properties = (Map<String,
Boolean>) FieldUtils.readDeclaredField(htmlParser, "properties", true);
-        assertNotNull(properties);
-        final Boolean foo = properties.get("foo");
+    public void testFeaturesConfiguration() throws IllegalAccessException {
+        @SuppressWarnings("unchecked") final Map<String, Boolean> features = (Map<String,
Boolean>) FieldUtils.readDeclaredField(htmlParser, "features", true);
+        assertNotNull(features);
+        final Boolean foo = features.get("foo");
         assertTrue(foo);
     }
 

-- 
To stop receiving notification emails like this one, please contact
olli@apache.org.

Mime
View raw message