use of org.apache.xerces.xni.QName in project zm-mailbox by Zimbra.
the class DefangFilter method fixATag.
/**
* make sure all <a> tags have a target="_blank" attribute set.
* @param attributes
*/
private void fixATag(XMLAttributes attributes) {
// BEGIN: bug 7927
int index = attributes.getIndex("href");
if (// links that don't have a href don't need target="_blank"
index == -1)
return;
String href = attributes.getValue(index);
if (// LOCAL links don't need target="_blank"
href.indexOf('#') == 0)
return;
// END: bug 7927
index = attributes.getIndex("target");
if (index != -1) {
attributes.setValue(index, "_blank");
} else {
attributes.addAttribute(new QName("", "target", "target", null), "CDATA", "_blank");
}
}
use of org.apache.xerces.xni.QName in project intellij-community by JetBrains.
the class XsContentDFA method getElementDeclaration.
@Nullable
private static XSElementDeclaration getElementDeclaration(XmlTag tag, XSModel xsModel) {
List<XmlTag> ancestors = new ArrayList<>();
for (XmlTag t = tag; t != null; t = t.getParentTag()) {
ancestors.add(t);
}
Collections.reverse(ancestors);
XSElementDeclaration declaration = null;
SubstitutionGroupHandler fSubGroupHandler = new SubstitutionGroupHandler(new MyXSElementDeclHelper());
CMBuilder cmBuilder = new CMBuilder(new CMNodeFactory());
for (XmlTag ancestor : ancestors) {
if (declaration == null) {
declaration = xsModel.getElementDeclaration(ancestor.getLocalName(), ancestor.getNamespace());
if (declaration == null)
return null;
else
continue;
}
XSTypeDefinition typeDefinition = declaration.getTypeDefinition();
if (!(typeDefinition instanceof XSComplexTypeDecl)) {
return null;
}
XSCMValidator model = ((XSComplexTypeDecl) typeDefinition).getContentModel(cmBuilder);
int[] ints = model.startContentModel();
for (XmlTag subTag : ancestor.getParentTag().getSubTags()) {
QName qName = createQName(subTag);
Object o = model.oneTransition(qName, ints, fSubGroupHandler);
if (subTag == ancestor) {
if (o instanceof XSElementDecl) {
declaration = (XSElementDecl) o;
break;
} else
return null;
}
}
}
return declaration;
}
use of org.apache.xerces.xni.QName in project zm-mailbox by Zimbra.
the class DefangFilter method neuterTag.
/**
* @param attributes
*/
private void neuterTag(XMLAttributes attributes, String aName, String prefix) {
String df_aName = prefix + aName;
int dfIndex = attributes.getIndex(df_aName);
int index = attributes.getIndex(aName);
if (index != -1) {
String aValue = attributes.getValue(index);
if (dfIndex != -1) {
attributes.setValue(dfIndex, aValue);
} else {
attributes.addAttribute(new QName("", df_aName, df_aName, null), "CDATA", aValue);
}
attributes.removeAttributeAt(index);
// remove dups if there are multiple src attributes
index = attributes.getIndex(aName);
while (index != -1) {
attributes.removeAttributeAt(index);
index = attributes.getIndex(aName);
}
}
}
Aggregations