use of nu.validator.xml.AttributesImpl in project validator by validator.
the class DataAttributeDroppingContentHandlerWrapper method filterAttributes.
private Attributes filterAttributes(Attributes attributes) throws SAXException {
int len = attributes.getLength();
for (int i = 0; i < len; i++) {
String local = attributes.getLocalName(i);
if (local.length() > 5 && local.startsWith("data-") && attributes.getURI(i) == "") {
if (errorHandler != null) {
checkDataName(local);
}
AttributesImpl attributesImpl = new AttributesImpl();
for (int j = 0; j < i; j++) {
attributesImpl.addAttribute(attributes.getURI(j), attributes.getLocalName(j), attributes.getQName(j), attributes.getType(j), attributes.getValue(j));
}
for (int k = i + 1; k < len; k++) {
String uri = attributes.getURI(k);
local = attributes.getLocalName(k);
if (local.length() > 5 && local.startsWith("data-") && "" == uri) {
checkDataName(local);
} else {
attributesImpl.addAttribute(uri, local, attributes.getQName(k), attributes.getType(k), attributes.getValue(k));
}
}
return attributesImpl;
}
}
return attributes;
}
use of nu.validator.xml.AttributesImpl in project validator by validator.
the class MessageEmitterAdapter method addHyperlink.
private void addHyperlink(XhtmlSaxEmitter xhtmlSaxEmitter, String text, String href) throws SAXException {
AttributesImpl attributesImpl = new AttributesImpl();
attributesImpl.addAttribute("href", href);
xhtmlSaxEmitter.startElement("a", attributesImpl);
addText(xhtmlSaxEmitter, text);
xhtmlSaxEmitter.endElement("a");
}
use of nu.validator.xml.AttributesImpl in project validator by validator.
the class Html5AttributeDatatypeBuilder method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
switch(state) {
case AWAITING_WIKI_BODY:
if ("wiki-body".equals(atts.getValue("", "id"))) {
state = State.AWAITING_H3;
}
return;
case AWAITING_H3:
if ("h3" == localName && NS == uri) {
depth = 0;
state = State.IN_HEADLINE;
}
return;
case IN_HEADLINE:
stringBuilder.setLength(0);
depth++;
return;
case AWAITING_P:
if (NS == uri && "p" == localName) {
treeBuilder.startElement(NS, "dd", "dd", EmptyAttributes.EMPTY_ATTRIBUTES);
state = State.IN_P;
} else {
state = State.AWAITING_H3;
}
return;
case IN_P:
depth++;
String href = null;
if (NS == uri && "a" == localName && ((href = atts.getValue("", "href")) != null)) {
AttributesImpl ai = new AttributesImpl();
ai.addAttribute("href", href);
treeBuilder.startElement(uri, localName, qName, ai);
} else {
treeBuilder.startElement(uri, localName, qName, EmptyAttributes.EMPTY_ATTRIBUTES);
}
}
}
use of nu.validator.xml.AttributesImpl in project validator by validator.
the class ImageReportAdviceBuilder method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
switch(state) {
case AWAITING_H2:
if ("h2" == localName && NS == uri) {
depth = 0;
state = State.AWAITING_HEADLINE;
}
return;
case AWAITING_HEADLINE:
if (depth == 0 && "span" == localName && NS == uri && "mw-headline".equals(atts.getValue("", "class"))) {
state = State.IN_HEADLINE;
} else {
depth++;
}
return;
case IN_HEADLINE:
depth++;
return;
case AWAITING_H2_END:
depth++;
return;
case IN_PROSE:
String href = null;
if (NS == uri && "a" == localName) {
if ((href = atts.getValue("", "href")) != null) {
AttributesImpl ai = new AttributesImpl();
ai.addAttribute("href", href);
depth++;
treeBuilder.startElement(uri, localName, qName, ai);
}
} else if (NS == uri && "div" == localName && ("printfooter".equals(atts.getValue("", "class")))) {
fragments.add((DocumentFragment) treeBuilder.getRoot());
treeBuilder = null;
state = State.AWAITING_H2;
} else if (depth == 0 && "h2" == localName && NS == uri) {
fragments.add((DocumentFragment) treeBuilder.getRoot());
treeBuilder = null;
depth = 0;
state = State.AWAITING_HEADLINE;
} else {
depth++;
treeBuilder.startElement(uri, localName, qName, EmptyAttributes.EMPTY_ATTRIBUTES);
}
}
}
use of nu.validator.xml.AttributesImpl in project validator by validator.
the class XmlLangAttributeDroppingContentHandlerWrapper method filterAttributes.
private Attributes filterAttributes(Attributes attributes) throws SAXException {
int len = attributes.getLength();
String langValue = null;
for (int i = 0; i < len; i++) {
String local = attributes.getLocalName(i);
String uri = attributes.getURI(i);
if (local == "lang" && uri == "http://www.w3.org/XML/1998/namespace") {
langValue = attributes.getValue(i);
} else if (local == "xml:lang" && uri == "") {
String xmlLangValue = attributes.getValue(i);
AttributesImpl attributesImpl = new AttributesImpl();
for (int j = 0; j < i; j++) {
attributesImpl.addAttribute(attributes.getURI(j), attributes.getLocalName(j), attributes.getQName(j), attributes.getType(j), attributes.getValue(j));
}
for (int k = i + 1; k < len; k++) {
uri = attributes.getURI(k);
local = attributes.getLocalName(k);
if (local == "lang" && uri == "http://www.w3.org/XML/1998/namespace") {
langValue = attributes.getValue(k);
}
attributesImpl.addAttribute(uri, local, attributes.getQName(k), attributes.getType(k), attributes.getValue(k));
}
if (errorHandler != null && !equalsIgnoreAsciiCase(xmlLangValue, langValue)) {
errorHandler.error(new SAXParseException("When the attribute \u201Cxml:lang\u201D in no namespace is specified, the element must also have the attribute \u201Clang\u201D present with the same value.", locator));
}
return attributesImpl;
}
}
return attributes;
}
Aggregations