-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AMP validation features to support literal attribute value, e.g [].
- Loading branch information
Showing
9 changed files
with
337 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
core/src/test/java/com/yahoo/tagchowder/CustomHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* | ||
* ==================================================================== | ||
* Licensed 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. | ||
* ==================================================================== | ||
*/ | ||
|
||
/* | ||
* Changes to the original project are Copyright 2019 Oath Inc. | ||
*/ | ||
|
||
package com.yahoo.tagchowder; | ||
|
||
import org.xml.sax.Attributes; | ||
import org.xml.sax.SAXException; | ||
import org.xml.sax.helpers.DefaultHandler; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* A simple CustomHandler class to scan HTML doc and return the list of parsed Html tags. | ||
* | ||
* @author nhant01 | ||
*/ | ||
public class CustomHandler extends DefaultHandler { | ||
@Override | ||
public void startElement(final String uri, final String localName, | ||
final String qName, final Attributes attributes) throws SAXException { | ||
final ParsedHtmlTag parsedHtmlTag = new ParsedHtmlTag(localName, attributes); | ||
parsedHtmlTagSet.add(parsedHtmlTag); | ||
} | ||
|
||
/** | ||
* Returns the list of parsed Html tags. | ||
* @return the list parsed Html tags | ||
*/ | ||
public List<ParsedHtmlTag> getParsedHtmlTags() { | ||
return parsedHtmlTagSet; | ||
} | ||
|
||
/** Set of parsed Html tags */ | ||
private List<ParsedHtmlTag> parsedHtmlTagSet = new ArrayList<>(); | ||
} |
86 changes: 86 additions & 0 deletions
86
core/src/test/java/com/yahoo/tagchowder/ParsedHtmlTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* | ||
* ==================================================================== | ||
* Licensed 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. | ||
* ==================================================================== | ||
*/ | ||
|
||
/* | ||
* Changes to the original project are Copyright 2019 Oath Inc. | ||
*/ | ||
|
||
package com.yahoo.tagchowder; | ||
|
||
import org.xml.sax.Attributes; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* The Html ParsedHtmlTag class. | ||
* | ||
* @author nhant01 | ||
*/ | ||
public class ParsedHtmlTag { | ||
/** | ||
* Constructor. | ||
* | ||
* @param tagName the name of the underlying tag in html document. | ||
* @param attributes the attributes attached to the element. If | ||
* there are no attributes, it shall be an empty Attributes object. | ||
*/ | ||
public ParsedHtmlTag(@Nonnull final String tagName, @Nonnull final Attributes attributes) { | ||
this.tagName = tagName.toUpperCase(); | ||
this.attrs = attributes; | ||
} | ||
|
||
/** | ||
* Lower-case tag name. | ||
* @return returns a lower case tag name. | ||
*/ | ||
public String lowerName() { | ||
return this.tagName.toLowerCase(); | ||
} | ||
|
||
/** | ||
* Determine if an attribute name exists. Return true if found. | ||
* @param attrName attribute name | ||
* @return true if found. Otherwise false. | ||
*/ | ||
public boolean hasAttribute(final String attrName) { | ||
for (int i = 0; i < attrs().getLength(); i++) { | ||
if (attrs.getQName(i).equalsIgnoreCase(attrName)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Returns an array of attributes. Each attribute has two fields: name and | ||
* value. Name is always lower-case, value is the case from the original | ||
* document. Values are unescaped. | ||
* @return returns the attributes. | ||
*/ | ||
public Attributes attrs() { | ||
return this.attrs; | ||
} | ||
|
||
/** The parsed tag name. */ | ||
@Nonnull | ||
private String tagName; | ||
|
||
/** The attributes. */ | ||
@Nonnull | ||
private final Attributes attrs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.