Search in sources :

Example 1 with TagScanner

use of org.eclipse.wst.xml.core.internal.commentelement.util.TagScanner in project webtools.sourceediting by eclipse.

the class BasicCommentElementHandler method createElement.

public Element createElement(Document document, String data, boolean isJSPTag) {
    Element element = null;
    String str = data.trim();
    CommentElementFactory factory = new CommentElementFactory(document, isJSPTag, this);
    if (str.charAt(0) == '/') {
        // end tag
        // skip '/'
        TagScanner scanner = new TagScanner(str, 1);
        String name = scanner.nextName();
        if (name.equals(elementName)) {
            element = factory.create(name, CommentElementFactory.IS_END);
        }
    } else {
        // start tag
        TagScanner scanner = new TagScanner(str, 0);
        String name = scanner.nextName();
        if (name.equals(elementName)) {
            element = factory.create(name, (isEmpty) ? CommentElementFactory.IS_EMPTY : CommentElementFactory.IS_START);
            // set attributes
            String attrName = scanner.nextName();
            while (attrName != null) {
                String attrValue = scanner.nextValue();
                Attr attr = document.createAttribute(attrName);
                if (attr != null) {
                    if (attrValue != null)
                        ((IDOMAttr) attr).setValueSource(attrValue);
                    element.setAttributeNode(attr);
                }
                attrName = scanner.nextName();
            }
        }
    }
    return element;
}
Also used : CommentElementFactory(org.eclipse.wst.xml.core.internal.commentelement.util.CommentElementFactory) Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) TagScanner(org.eclipse.wst.xml.core.internal.commentelement.util.TagScanner) IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) Attr(org.w3c.dom.Attr)

Example 2 with TagScanner

use of org.eclipse.wst.xml.core.internal.commentelement.util.TagScanner in project webtools.sourceediting by eclipse.

the class CommentElementHandlerForFoo method createElement.

public Element createElement(Document document, String data, boolean isJSPTag) {
    TagScanner scanner = new TagScanner(data, 1);
    String name = scanner.nextName();
    if (name == null) {
        return null;
    }
    StringBuffer buffer = new StringBuffer(name.length() + 4);
    buffer.append(PREFIX);
    buffer.append(':');
    buffer.append(name);
    String tagName = buffer.toString();
    CommentElementFactory factory = new CommentElementFactory(document, isJSPTag, this);
    Element element = factory.create(tagName, CommentElementFactory.IS_START);
    // set attributes
    String attrName = scanner.nextName();
    while (attrName != null) {
        String attrValue = scanner.nextValue();
        Attr attr = document.createAttribute(attrName);
        if (attr != null) {
            if (attrValue != null)
                attr.setValue(attrValue);
            element.setAttributeNode(attr);
        }
        attrName = scanner.nextName();
    }
    return element;
}
Also used : CommentElementFactory(org.eclipse.wst.xml.core.internal.commentelement.util.CommentElementFactory) Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) TagScanner(org.eclipse.wst.xml.core.internal.commentelement.util.TagScanner) Attr(org.w3c.dom.Attr)

Example 3 with TagScanner

use of org.eclipse.wst.xml.core.internal.commentelement.util.TagScanner in project webtools.sourceediting by eclipse.

the class CommentElementHandlerForSSI method createElement.

public Element createElement(Document document, String data, boolean isJSPTag) {
    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
    if (modelQuery == null) {
        return null;
    }
    CMDocument cm = modelQuery.getCorrespondingCMDocument(document);
    if (cm == null) {
        return null;
    }
    CMNamedNodeMap map = cm.getElements();
    if (map == null) {
        return null;
    }
    TagScanner scanner = new TagScanner(data, 1);
    String name = scanner.nextName();
    if (name == null) {
        return null;
    }
    StringBuffer buffer = new StringBuffer(name.length() + 4);
    buffer.append(SSI_PREFIX);
    buffer.append(':');
    buffer.append(name);
    String tagName = buffer.toString();
    // check if valid (defined) SSI tag or not
    if (map.getNamedItem(tagName) == null) {
        return null;
    }
    CommentElementFactory factory = new CommentElementFactory(document, isJSPTag, this);
    Element element = factory.create(tagName, CommentElementFactory.IS_START);
    // set attributes
    String attrName = scanner.nextName();
    while (attrName != null) {
        String attrValue = scanner.nextValue();
        Attr attr = document.createAttribute(attrName);
        if (attr != null) {
            if (attrValue != null)
                attr.setValue(attrValue);
            element.setAttributeNode(attr);
        }
        attrName = scanner.nextName();
    }
    return element;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CommentElementFactory(org.eclipse.wst.xml.core.internal.commentelement.util.CommentElementFactory) Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) TagScanner(org.eclipse.wst.xml.core.internal.commentelement.util.TagScanner) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) Attr(org.w3c.dom.Attr)

Aggregations

CommentElementFactory (org.eclipse.wst.xml.core.internal.commentelement.util.CommentElementFactory)3 TagScanner (org.eclipse.wst.xml.core.internal.commentelement.util.TagScanner)3 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)3 Attr (org.w3c.dom.Attr)3 Element (org.w3c.dom.Element)3 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)1 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)1 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)1 IDOMAttr (org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)1