Search in sources :

Example 1 with IllegalNameException

use of org.jdom.IllegalNameException in project intellij-community by JetBrains.

the class Maven2ModelConverter method xppToElement.

private static Element xppToElement(Xpp3Dom xpp) throws RemoteException {
    Element result;
    try {
        result = new Element(xpp.getName());
    } catch (IllegalNameException e) {
        Maven2ServerGlobals.getLogger().info(e);
        return null;
    }
    Xpp3Dom[] children = xpp.getChildren();
    if (children == null || children.length == 0) {
        result.setText(xpp.getValue());
    } else {
        for (Xpp3Dom each : children) {
            Element child = xppToElement(each);
            if (child != null)
                result.addContent(child);
        }
    }
    return result;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Element(org.jdom.Element) IllegalNameException(org.jdom.IllegalNameException)

Example 2 with IllegalNameException

use of org.jdom.IllegalNameException in project che by eclipse.

the class MavenModelUtil method convertXpp.

private static Element convertXpp(Xpp3Dom xpp3Dom) {
    Element result;
    try {
        result = new Element(xpp3Dom.getName());
    } catch (IllegalNameException e) {
        return null;
    }
    Xpp3Dom[] children = xpp3Dom.getChildren();
    if (children == null || children.length == 0) {
        result.setText(xpp3Dom.getValue());
    } else {
        for (Xpp3Dom child : children) {
            Element element = convertXpp(child);
            if (element != null) {
                result.addContent(element);
            }
        }
    }
    return result;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Element(org.jdom.Element) IllegalNameException(org.jdom.IllegalNameException)

Example 3 with IllegalNameException

use of org.jdom.IllegalNameException in project intellij-community by JetBrains.

the class MavenJDOMUtil method doRead.

@Nullable
private static Element doRead(String text, final ErrorHandler handler) {
    final LinkedList<Element> stack = new LinkedList<>();
    final Element[] result = { null };
    XmlBuilderDriver driver = new XmlBuilderDriver(text);
    XmlBuilder builder = new XmlBuilder() {

        public void doctype(@Nullable CharSequence publicId, @Nullable CharSequence systemId, int startOffset, int endOffset) {
        }

        public ProcessingOrder startTag(CharSequence localName, String namespace, int startoffset, int endoffset, int headerEndOffset) {
            String name = localName.toString();
            if (StringUtil.isEmptyOrSpaces(name))
                return ProcessingOrder.TAGS;
            Element newElement;
            try {
                newElement = new Element(name);
            } catch (IllegalNameException e) {
                newElement = new Element("invalidName");
            }
            Element parent = stack.isEmpty() ? null : stack.getLast();
            if (parent == null) {
                result[0] = newElement;
            } else {
                parent.addContent(newElement);
            }
            stack.addLast(newElement);
            return ProcessingOrder.TAGS_AND_TEXTS;
        }

        public void endTag(CharSequence localName, String namespace, int startoffset, int endoffset) {
            String name = localName.toString();
            if (StringUtil.isEmptyOrSpaces(name))
                return;
            for (Iterator<Element> itr = stack.descendingIterator(); itr.hasNext(); ) {
                Element element = itr.next();
                if (element.getName().equals(name)) {
                    while (stack.removeLast() != element) {
                    }
                    break;
                }
            }
        }

        public void textElement(CharSequence text, CharSequence physical, int startoffset, int endoffset) {
            stack.getLast().addContent(JDOMUtil.legalizeText(text.toString()));
        }

        public void attribute(CharSequence name, CharSequence value, int startoffset, int endoffset) {
        }

        public void entityRef(CharSequence ref, int startOffset, int endOffset) {
        }

        public void error(String message, int startOffset, int endOffset) {
            if (handler != null)
                handler.onSyntaxError();
        }
    };
    driver.build(builder);
    return result[0];
}
Also used : XmlBuilderDriver(com.intellij.psi.impl.source.parsing.xml.XmlBuilderDriver) Element(org.jdom.Element) XmlBuilder(com.intellij.psi.impl.source.parsing.xml.XmlBuilder) IllegalNameException(org.jdom.IllegalNameException) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with IllegalNameException

use of org.jdom.IllegalNameException in project intellij-community by JetBrains.

the class MavenModelConverter method xppToElement.

private static Element xppToElement(Xpp3Dom xpp) throws RemoteException {
    Element result;
    try {
        result = new Element(xpp.getName());
    } catch (IllegalNameException e) {
        Maven3ServerGlobals.getLogger().info(e);
        return null;
    }
    Xpp3Dom[] children = xpp.getChildren();
    if (children == null || children.length == 0) {
        result.setText(xpp.getValue());
    } else {
        for (Xpp3Dom each : children) {
            Element child = xppToElement(each);
            if (child != null)
                result.addContent(child);
        }
    }
    return result;
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Element(org.jdom.Element) IllegalNameException(org.jdom.IllegalNameException)

Aggregations

Element (org.jdom.Element)4 IllegalNameException (org.jdom.IllegalNameException)4 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)3 XmlBuilder (com.intellij.psi.impl.source.parsing.xml.XmlBuilder)1 XmlBuilderDriver (com.intellij.psi.impl.source.parsing.xml.XmlBuilderDriver)1 Nullable (org.jetbrains.annotations.Nullable)1