nonanalou commented on code in PR #28:
URL: 
https://github.com/apache/sling-org-apache-sling-xss/pull/28#discussion_r941343800


##########
src/main/java/org/apache/sling/xss/impl/xml/Attribute.java:
##########
@@ -0,0 +1,142 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.xss.impl.xml;
+
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import 
com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+
+public class Attribute {
+
+    private String name = null;
+    private String description = null;
+    private String onInvalid = null;
+
+    @JacksonXmlElementWrapper(localName = "regexp-list")
+    private List<Regexp> regexpList = null;
+
+    @JacksonXmlElementWrapper(localName = "literal-list")
+    private List<Literal> literalList = null;
+
+    // private List<Pattern> patternList = regexpList.stream().map(regexp ->
+    // regexp.getPattern())
+    // .collect(Collectors.toList());
+
+    @JsonCreator
+    public Attribute(@JacksonXmlProperty(localName = "name", isAttribute = 
true) String name,
+            // @JacksonXmlElementWrapper(localName = "regexp-list")
+            @JacksonXmlProperty(localName = "regexp") List<Regexp> 
allowedRegexps,
+            // @JacksonXmlElementWrapper(localName = "literal-list")
+            @JacksonXmlProperty(localName = "literal") List<Literal> 
allowedValues,
+            @JacksonXmlProperty(localName = "onInvalid", isAttribute = true) 
String onInvalid,
+            @JacksonXmlProperty(localName = "description", isAttribute = true) 
String description) {
+        this.name = name;
+        this.description = description;
+        this.onInvalid = onInvalid;
+        this.regexpList = allowedRegexps;
+        this.literalList = allowedValues;
+    }
+
+    @Override
+    public String toString() {
+        return "Attribute - name: " + name + ", description " + description + 
", onInvalid " + onInvalid
+                + ", allowedRegexlist: "
+                + regexpList.size() + ", literals " + literalList;
+    }
+
+    public String getOnInvalid() {
+        if (onInvalid != null && onInvalid.length() > 0) {
+            return onInvalid;
+        } else {
+            onInvalid = "removeAttribute";
+            return onInvalid;
+        }
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public List<String> getLiterals() {
+        if (literalList != null && literalList.size() > 0) {
+            return literalList.stream().map(literal -> 
literal.getValue().toLowerCase()).collect(Collectors.toList());
+        }
+        return null;
+    }
+
+    public List<Literal> getLiteralList() {
+        return literalList;
+    }
+
+    public List<Pattern> getPatternList() {
+        return regexpList.stream().map(regexp -> regexp.getPattern())
+                .collect(Collectors.toList());
+
+    }
+
+    public List<Regexp> getRegexpList() {
+        return regexpList;
+    }
+
+    public boolean containsAllowedValue(String valueInLowerCase) {
+        List<String> literals = getLiterals();
+        return literals != null && literals.size() > 0 ? 
getLiterals().contains(valueInLowerCase) : false;
+    }
+
+    public boolean matchesAllowedExpression(String value) {
+        if (regexpList != null && regexpList.size() > 0) {

Review Comment:
   Resolved: 083ea04c66361c553d3357e9f05bdf8a43b691cc



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@sling.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to