Search in sources :

Example 1 with QName

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");
    }
}
Also used : QName(org.apache.xerces.xni.QName) XMLString(org.apache.xerces.xni.XMLString)

Example 2 with QName

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;
}
Also used : XSTypeDefinition(org.apache.xerces.xs.XSTypeDefinition) QName(org.apache.xerces.xni.QName) ArrayList(java.util.ArrayList) CMNodeFactory(org.apache.xerces.impl.xs.models.CMNodeFactory) XSCMValidator(org.apache.xerces.impl.xs.models.XSCMValidator) CMBuilder(org.apache.xerces.impl.xs.models.CMBuilder) XSElementDeclaration(org.apache.xerces.xs.XSElementDeclaration) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with QName

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);
        }
    }
}
Also used : QName(org.apache.xerces.xni.QName) XMLString(org.apache.xerces.xni.XMLString)

Aggregations

QName (org.apache.xerces.xni.QName)3 XMLString (org.apache.xerces.xni.XMLString)2 XmlTag (com.intellij.psi.xml.XmlTag)1 ArrayList (java.util.ArrayList)1 CMBuilder (org.apache.xerces.impl.xs.models.CMBuilder)1 CMNodeFactory (org.apache.xerces.impl.xs.models.CMNodeFactory)1 XSCMValidator (org.apache.xerces.impl.xs.models.XSCMValidator)1 XSElementDeclaration (org.apache.xerces.xs.XSElementDeclaration)1 XSTypeDefinition (org.apache.xerces.xs.XSTypeDefinition)1 Nullable (org.jetbrains.annotations.Nullable)1