package jetbrains.mps.util.xml; /*Generated by MPS */ import org.jdom.Element; import jetbrains.mps.internal.collections.runtime.Sequence; import java.util.Collections; import java.util.List; public class XmlUtil { private XmlUtil() { } public static void tagWithText(Element container, String tagName, String text) { Element child = new Element(tagName); child.setText(text); container.addContent(child); } public static void tagWithAttribute(Element container, String tagName, String attrName, String attrValue) { Element child = new Element(tagName); child.setAttribute(attrName, attrValue); container.addContent(child); } public static void tagWithAttributeAndText(Element container, String tagName, String attrName, String attrValue, String text) { Element child = new Element(tagName); child.setAttribute(attrName, attrValue); child.setText(text); container.addContent(child); } public static void tagWithAttributes(Element container, String tagName, String attrName, String attrValue, String attr2Name, String attr2Value) { Element child = new Element(tagName); child.setAttribute(attrName, attrValue); child.setAttribute(attr2Name, attr2Value); container.addContent(child); } public static Iterable<Element> children(Element container, String tagName) { if (container == null) { return Sequence.fromIterable(Collections.<Element>emptyList()); } return (Iterable<Element>) ((List<Element>) container.getChildren(tagName)); } public static Element first(Element container, String tagName) { if (container == null) { return null; } return Sequence.fromIterable(children(container, tagName)).first(); } public static boolean booleanWithDefault(Element element, String attrName, boolean defaultValue) { if (element == null) { return defaultValue; } String attrValue = element.getAttributeValue(attrName); return (attrValue == null ? defaultValue : Boolean.parseBoolean(attrValue)); } public static String stringWithDefault(Element element, String attrName, String defaultValue) { if (element == null) { return defaultValue; } String attrValue = element.getAttributeValue(attrName); return (attrValue == null ? defaultValue : attrValue); } }