Search in sources :

Example 1 with Attribute

use of org.jdom.Attribute in project libresonic by Libresonic.

the class JAXBWriter method getRESTProtocolVersion.

private String getRESTProtocolVersion() throws Exception {
    InputStream in = null;
    try {
        in = StringUtil.class.getResourceAsStream("/libresonic-rest-api.xsd");
        Document document = new SAXBuilder().build(in);
        Attribute version = document.getRootElement().getAttribute("version");
        return version.getValue();
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Attribute(org.jdom.Attribute) InputStream(java.io.InputStream) StringUtil(org.libresonic.player.util.StringUtil) Document(org.jdom.Document)

Example 2 with Attribute

use of org.jdom.Attribute in project OpenClinica by OpenClinica.

the class RepeatManager method addChildRepeatAttributes.

/*
     * Add the attributes to an HTML tag that provide the template for other
     * repeating form elements. This method adds the required attributes to the
     * repeater parameter than returns the changed element.
     */
public Element addChildRepeatAttributes(Element repeater, String parentId, Integer itemId, String forcedInputNameIndex) {
    // The code needs a input name prefix that is unique for every table
    // to make sure that the input name is unique for every form field
    StringBuilder nameVal = new StringBuilder(parentId);
    if (forcedInputNameIndex == null || forcedInputNameIndex.length() < 1) {
        nameVal.append("_[").append(parentId).append("]input");
    } else {
        nameVal.append("_[").append(forcedInputNameIndex).append("]input");
    }
    // so that the input elements will have unique IDs
    if (itemId == 0) {
        Random rand = new Random();
        itemId = rand.nextInt(100000) + 1;
    }
    nameVal.append(itemId);
    // if the element does not have an input "name" attribute, then create a
    // new one; otherwise
    // remove and edit the existing one to add this required repeat
    // information.
    // The child elements have names of input, select, or textarea
    List<Element> inputs = repeater.getChildren("input");
    if (inputs.isEmpty()) {
        inputs = repeater.getChildren("select");
    }
    if (inputs.isEmpty()) {
        inputs = repeater.getChildren("textarea");
    }
    for (Element input : inputs) {
        // do not include input type="hidden"
        boolean isHidden;
        Attribute attribute = input.getAttribute("type");
        if (attribute == null || attribute.getValue() == null || !attribute.getValue().equalsIgnoreCase("hidden")) {
            if (input.getAttribute("name") != null) {
                input.removeAttribute("name");
            }
        } else {
            continue;
        }
        // the input Element has to use the id of its "repeat parent"
        // element
        input.setAttribute("name", nameVal.toString());
    }
    return repeater;
}
Also used : Random(java.util.Random) Attribute(org.jdom.Attribute) Element(org.jdom.Element)

Example 3 with Attribute

use of org.jdom.Attribute in project intellij-plugins by StepicOrg.

the class StudySerializationUtils method convertToXStreamStyle.

private static void convertToXStreamStyle(List<Element> elements) {
    elements.forEach(element -> {
        if (element.getName().equals(OPTION)) {
            Attribute nameAttr = element.getAttribute(NAME);
            if (nameAttr != null) {
                String name = nameAttr.getValue();
                element.setName(nameAttr.getValue());
                element.removeAttribute(nameAttr);
                if (name.equals(DATA)) {
                    Element parent = element.getParentElement();
                    String dataClass = null;
                    switch(parent.getName()) {
                        case COURSE_NODE_CLASS:
                            dataClass = COURSE_CLASS;
                            break;
                        case SECTION_NODE_CLASS:
                            dataClass = SECTION_CLASS;
                            break;
                        case LESSON_NODE_CLASS:
                            dataClass = COMPOUND_UNIT_LESSON_CLASS;
                            break;
                        case STEP_NODE_CLASS:
                            dataClass = STEP_CLASS;
                            break;
                    }
                    if (dataClass != null) {
                        element.setAttribute("class", dataClass);
                    }
                }
            }
            Attribute valueAttr = element.getAttribute(VALUE);
            if (valueAttr != null) {
                element.setText(valueAttr.getValue());
                element.removeAttribute(valueAttr);
                if (nameAttr == null) {
                    element.setName("string");
                }
            } else {
                List<Element> children = element.getChildren();
                if (!children.isEmpty()) {
                    Element child = children.get(0);
                    removeChild(element, child);
                    element.addContent(child.cloneContent());
                }
            }
        } else if (element.getName().equals(ENTRY)) {
            Attribute keyAttr = element.getAttribute(KEY);
            if (keyAttr == null) {
                return;
            }
            addAttributeAsChild(element, keyAttr);
            Attribute valueAttr = element.getAttribute(VALUE);
            if (valueAttr != null) {
                addAttributeAsChild(element, valueAttr);
            } else {
                Element value = element.getChild(VALUE);
                if (value != null) {
                    element.removeChild(value.getName());
                    element.addContent(value.cloneContent());
                }
            }
        }
        convertToXStreamStyle(element.getChildren());
    });
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element)

Example 4 with Attribute

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

the class MetaManager method loadProperties.

protected void loadProperties(MetaModel meta, Element properties) throws Exception {
    Attribute inplace = properties.getAttribute("inplace");
    if (inplace != null) {
        meta.setInplaceProperties(StringUtil.split(inplace.getValue(), " "));
    }
    Attribute top = properties.getAttribute("top");
    if (top != null) {
        meta.setTopProperties(StringUtil.split(top.getValue(), " "));
    }
    Attribute normal = properties.getAttribute("normal");
    if (normal != null) {
        meta.setNormalProperties(StringUtil.split(normal.getValue(), " "));
    }
    Attribute important = properties.getAttribute("important");
    if (important != null) {
        meta.setImportantProperties(StringUtil.split(important.getValue(), " "));
    }
    Attribute expert = properties.getAttribute("expert");
    if (expert != null) {
        meta.setExpertProperties(StringUtil.split(expert.getValue(), " "));
    }
    Attribute deprecated = properties.getAttribute("deprecated");
    if (deprecated != null) {
        meta.setDeprecatedProperties(StringUtil.split(deprecated.getValue(), " "));
    }
}
Also used : Attribute(org.jdom.Attribute)

Example 5 with Attribute

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

the class SaveFormAsTemplateHandler method getTemplateText.

@Override
public String getTemplateText(final PsiFile file, final String fileText, final String nameWithoutExtension) {
    if (StdFileTypes.GUI_DESIGNER_FORM.equals(file.getFileType())) {
        LwRootContainer rootContainer = null;
        try {
            rootContainer = Utils.getRootContainer(fileText, null);
        } catch (Exception ignored) {
        }
        if (rootContainer != null && rootContainer.getClassToBind() != null) {
            try {
                Element document = JdomKt.loadElement(fileText);
                Attribute attribute = document.getAttribute(UIFormXmlConstants.ATTRIBUTE_BIND_TO_CLASS);
                attribute.detach();
                return JDOMUtil.write(document, CodeStyleSettingsManager.getSettings(file.getProject()).getLineSeparator());
            } catch (Exception ignored) {
            }
        }
    }
    return null;
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element) LwRootContainer(com.intellij.uiDesigner.lw.LwRootContainer)

Aggregations

Attribute (org.jdom.Attribute)40 Element (org.jdom.Element)30 DataConversionException (org.jdom.DataConversionException)6 ArrayList (java.util.ArrayList)4 Document (org.jdom.Document)3 SAXBuilder (org.jdom.input.SAXBuilder)3 NotNull (org.jetbrains.annotations.NotNull)3 PathMacrosImpl (com.intellij.application.options.PathMacrosImpl)2 PathMacroFilter (com.intellij.openapi.application.PathMacroFilter)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 EntityResolver (org.xml.sax.EntityResolver)2 AbstractColorsScheme (com.intellij.openapi.editor.colors.impl.AbstractColorsScheme)1 DefaultColorsScheme (com.intellij.openapi.editor.colors.impl.DefaultColorsScheme)1 SchemeImportException (com.intellij.openapi.options.SchemeImportException)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1 ReplacementVariableDefinition (com.intellij.structuralsearch.ReplacementVariableDefinition)1 LwRootContainer (com.intellij.uiDesigner.lw.LwRootContainer)1 THashSet (gnu.trove.THashSet)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1