Search in sources :

Example 26 with Attribute

use of org.jdom.Attribute in project vcell by virtualcell.

the class BiomodelsDB_TestSuite method writeSupportedModelsReport.

public static Document writeSupportedModelsReport(File supportInfoDir, File saveSupportedXMLPathname) throws Exception {
    if (!supportInfoDir.isDirectory()) {
        throw new IllegalArgumentException("File " + supportInfoDir.getAbsolutePath() + " must be a directory.");
    }
    File[] xmlReportFiles = supportInfoDir.listFiles(new FileFilter() {

        public boolean accept(File pathname) {
            if (pathname.isFile()) {
                if (pathname.getName().endsWith("_report.xml")) {
                    return true;
                }
            }
            return false;
        }
    });
    Document supportedDocument = new Document(new Element("Supported_BioModelsNet"));
    List<Element> supportedElements = new ArrayList<Element>();
    for (int i = 0; i < xmlReportFiles.length; i++) {
        byte[] xmlBytes = new byte[(int) xmlReportFiles[i].length()];
        FileInputStream fis = new FileInputStream(xmlReportFiles[i]);
        BufferedInputStream bis = new BufferedInputStream(fis);
        DataInputStream dis = new DataInputStream(bis);
        dis.readFully(xmlBytes);
        dis.close();
        Document document = XmlUtil.stringToXML(new String(xmlBytes), null);
        Element bioModelElement = document.getRootElement().getChild(BioModelsNetPanel.BIOMODELINFO_ELEMENT_NAME);
        Attribute supportedAttribute = bioModelElement.getAttribute(BioModelsNetPanel.SUPPORTED_ATTRIBUTE_NAME);
        if (supportedAttribute.getBooleanValue()) {
            Element newBioModelElement = new Element(BioModelsNetPanel.BIOMODELINFO_ELEMENT_NAME);
            @SuppressWarnings("unchecked") List<Attribute> attrList = bioModelElement.getAttributes();
            Iterator<Attribute> iterAttr = attrList.iterator();
            while (iterAttr.hasNext()) {
                newBioModelElement.setAttribute((Attribute) iterAttr.next().clone());
            }
            supportedElements.add(newBioModelElement);
        }
    }
    // Collections.sort(supportedElements, new ElementComparer());
    Element root = supportedDocument.getRootElement();
    for (Element e : supportedElements) {
        root.addContent(e);
    }
    if (saveSupportedXMLPathname != null) {
        try (FileWriter fw = new FileWriter(saveSupportedXMLPathname.getAbsolutePath())) {
            Format format = Format.getPrettyFormat();
            XMLOutputter out = new XMLOutputter(format);
            out.output(supportedDocument, fw);
        }
    }
    return supportedDocument;
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Attribute(org.jdom.Attribute) Element(org.jdom.Element) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) Document(org.jdom.Document) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) Format(org.jdom.output.Format) BufferedInputStream(java.io.BufferedInputStream) FileFilter(java.io.FileFilter) File(java.io.File)

Example 27 with Attribute

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

the class JdomUtil method getHash.

private static int getHash(int hash, Element element) {
    hash = sumHash(hash, element.getName());
    for (Object object : element.getAttributes()) {
        Attribute attribute = (Attribute) object;
        hash = sumHash(hash, attribute.getName());
        hash = sumHash(hash, attribute.getValue());
    }
    for (Object o : element.getContent()) {
        if (o instanceof Element) {
            hash = getHash(hash, (Element) o);
        } else if (o instanceof Text) {
            String text = ((Text) o).getText();
            if (!isNullOrWhitespace(text)) {
                hash = sumHash(hash, text);
            }
        }
    }
    return hash;
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element) Text(org.jdom.Text)

Example 28 with Attribute

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

the class LwXmlReader method getColorDescriptor.

public static ColorDescriptor getColorDescriptor(final Element element) throws Exception {
    Attribute attr = element.getAttribute(UIFormXmlConstants.ATTRIBUTE_COLOR);
    if (attr != null) {
        return new ColorDescriptor(new Color(attr.getIntValue()));
    }
    String swingColor = element.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_SWING_COLOR);
    if (swingColor != null) {
        return ColorDescriptor.fromSwingColor(swingColor);
    }
    String systemColor = element.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_SYSTEM_COLOR);
    if (systemColor != null) {
        return ColorDescriptor.fromSystemColor(systemColor);
    }
    String awtColor = element.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_AWT_COLOR);
    if (awtColor != null) {
        return ColorDescriptor.fromAWTColor(awtColor);
    }
    return new ColorDescriptor(null);
}
Also used : Attribute(org.jdom.Attribute)

Example 29 with Attribute

use of org.jdom.Attribute in project freud by LMAX-Exchange.

the class MethodCallJdom method getMethodName.

@SuppressWarnings("unchecked")
public String getMethodName() {
    if (methodName == null) {
        final Attribute idAttr = methodCallElement.getAttribute(JdomTreeAdaptor.ID_ATTR);
        if (idAttr != null) {
            methodName = idAttr.getValue();
            instanceReferences = EMPTY_ARRAY;
        } else {
            JXPathContext context = JXPathContext.newContext(methodCallElement);
            final List<Element> identElementList = context.selectNodes("//" + JavaSourceTokenType.IDENT.getName());
            Collections.sort(identElementList, JdomTreePositionComparator.getInstance());
            final int methodNameIndex = identElementList.size() - 1;
            methodName = identElementList.get(methodNameIndex).getText();
            instanceReferences = new String[methodNameIndex];
            for (int i = 0, size = instanceReferences.length; i < size; i++) {
                instanceReferences[i] = identElementList.get(i).getText();
            }
        }
    }
    return methodName;
}
Also used : JXPathContext(org.apache.commons.jxpath.JXPathContext) Attribute(org.jdom.Attribute) Element(org.jdom.Element)

Example 30 with Attribute

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

the class FlexCompilerConfigFileUtilBase method makeLibrariesMergedIntoCode.

private static void makeLibrariesMergedIntoCode(final Element rootElement, final boolean externalLibs, final boolean includedLibs) {
    final Namespace namespace = rootElement.getNamespace();
    final Collection<String> paths = removeLibs(rootElement, externalLibs, includedLibs);
    if (!paths.isEmpty()) {
        final Element compilerElement = rootElement.getChild(COMPILER, namespace);
        Element libraryPathElement = compilerElement.getChild(LIBRARY_PATH, namespace);
        if (libraryPathElement == null) {
            libraryPathElement = new Element(LIBRARY_PATH, namespace);
            libraryPathElement.setAttribute(new Attribute(APPEND, "true"));
            compilerElement.addContent(libraryPathElement);
        }
        for (final String path : paths) {
            final Element pathElement = new Element(PATH_ELEMENT, namespace);
            pathElement.addContent(path);
            libraryPathElement.addContent(pathElement);
        }
    }
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element) Namespace(org.jdom.Namespace)

Aggregations

Attribute (org.jdom.Attribute)57 Element (org.jdom.Element)40 ArrayList (java.util.ArrayList)10 DataConversionException (org.jdom.DataConversionException)7 Iterator (java.util.Iterator)4 List (java.util.List)4 Document (org.jdom.Document)4 Namespace (org.jdom.Namespace)3 SAXBuilder (org.jdom.input.SAXBuilder)3 NotNull (org.jetbrains.annotations.NotNull)3 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 PathMacrosImpl (com.intellij.application.options.PathMacrosImpl)2 PathMacroFilter (com.intellij.openapi.application.PathMacroFilter)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Content (org.jdom.Content)2 Text (org.jdom.Text)2 BioPaxObject (org.vcell.pathway.BioPaxObject)2 RdfObjectProxy (org.vcell.pathway.persistence.BiopaxProxy.RdfObjectProxy)2 JDOMTreeWalker (cbit.util.xml.JDOMTreeWalker)1