Search in sources :

Example 51 with Attribute

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

the class XmlElementComparator method compare.

/**
 * compare method comment.
 */
public int compare(Element o1, Element o2) {
    if (o1 == null || o2 == null) {
        throw new IllegalArgumentException("Cannot compare against null's!");
    }
    // compare their names
    if (!diffTree.getMangledName(o1).equalsIgnoreCase(diffTree.getMangledName(o2))) {
        this.status = this.DIFNAMETAG;
        return java.lang.Integer.MIN_VALUE;
    }
    // compare their attributes
    List baselist = o1.getAttributes();
    List modifiedlist = o2.getAttributes();
    if (baselist.size() != modifiedlist.size()) {
        this.status = this.DIFATTRIBUTES;
        return -1;
    }
    Iterator baseiterator = baselist.iterator();
    Iterator moditerator = modifiedlist.iterator();
    // 
    if (o1.getName().equals(cbit.vcell.xml.XMLTags.VersionTag) && diffTree.isIgnoringVersionInfo()) {
        return 0;
    }
    while (baseiterator.hasNext() && moditerator.hasNext()) {
        if (compare((Attribute) (baseiterator.next()), (Attribute) (moditerator.next())) != 0) {
            this.status = this.DIFATTRIBUTES;
            return -1;
        }
    }
    // compare their subelements
    List list1 = o1.getChildren();
    List list2 = o2.getChildren();
    if (list1.size() != list2.size()) {
        this.status = this.DIFSUBELEMENTS;
        return (list1.size() - list2.size());
    }
    int i = 0;
    int differences = 0;
    while (i < list1.size()) {
        if (compare(list1.get(i), list2.get(i)) != 0) {
            differences++;
        }
        i++;
    }
    if (differences != 0) {
        this.status = this.DIFSUBELEMENTS;
        return differences;
    }
    // compare content
    if (!o1.getText().equalsIgnoreCase(o2.getText())) {
        // compare their content
        this.status = this.DIFCONTENT;
        return o1.getText().compareTo(o2.getText());
    }
    return 0;
}
Also used : Attribute(org.jdom.Attribute) Iterator(java.util.Iterator) List(java.util.List)

Example 52 with Attribute

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

the class CellQuanVCTranslator method fixMathMLBug.

// temporary method.
private void fixMathMLBug(Element math) {
    ArrayList<Element> l = new ArrayList<Element>();
    @SuppressWarnings("unchecked") Iterator<Element> walker = new JDOMTreeWalker(math, new ContentFilter(ContentFilter.ELEMENT));
    while (walker.hasNext()) l.add(walker.next());
    Element temp;
    for (int i = 0; i < l.size(); i++) {
        temp = l.get(i);
        if (temp.getName().equals(MathMLTags.CONSTANT)) {
            @SuppressWarnings("unchecked") ArrayList<Attribute> atts = new ArrayList<Attribute>(temp.getAttributes());
            org.jdom.Attribute att;
            for (int j = 0; j < atts.size(); j++) {
                att = atts.get(j);
                temp.removeAttribute(att.getName(), mathns);
            }
            temp.removeNamespaceDeclaration(mathns);
        }
    }
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element) ArrayList(java.util.ArrayList) Attribute(org.jdom.Attribute) ContentFilter(org.jdom.filter.ContentFilter) JDOMTreeWalker(cbit.util.xml.JDOMTreeWalker)

Example 53 with Attribute

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

the class PathwayReaderBiopax3 method addAttributes.

private void addAttributes(BioPaxObject bioPaxObject, Element element) {
    int count = 0;
    for (Object attr : element.getAttributes()) {
        Attribute attribute = (Attribute) attr;
        if (attribute.getName().equals("ID")) {
            if (bioPaxObject instanceof RdfObjectProxy) {
                showUnexpected(attribute);
            } else {
                String uri = context.unAbbreviateURI(element, attribute.getValue());
                bioPaxObject.setID(uri);
                count++;
            }
        } else if (attribute.getName().equals("resource")) {
            if (bioPaxObject instanceof RdfObjectProxy) {
                String uri = context.unRelativizeURI(element, attribute.getValue());
                bioPaxObject.setID(uri);
                count++;
            } else {
                showUnexpected(attribute);
            }
        } else if (attribute.getName().equals("about")) {
            if (bioPaxObject instanceof RdfObjectProxy) {
                // TODO: can this ever happen?
                String uri = context.unRelativizeURI(element, attribute.getValue());
                bioPaxObject.setID(uri);
                count++;
            } else {
                String uri = context.unRelativizeURI(element, attribute.getValue());
                bioPaxObject.setID(uri);
                count++;
            }
        } else if (attribute.getName().equals("nodeID")) {
            if (bioPaxObject instanceof RdfObjectProxy) {
                // TODO: can this ever happen?
                ((RdfObjectProxy) bioPaxObject).setID(attribute.getValue());
                count++;
            } else {
                bioPaxObject.setID(attribute.getValue());
                count++;
            }
        } else {
            showUnexpected(attribute);
        }
    }
    if (count < 1) {
        System.out.println(element + " has neither ID nor resource attributes.");
    }
    if (count > 1) {
        System.out.println(element + " has multiple ID and/or resource attributes.");
    }
}
Also used : Attribute(org.jdom.Attribute) GroupObject(org.vcell.pathway.GroupObject) BioPaxObject(org.vcell.pathway.BioPaxObject) RdfObjectProxy(org.vcell.pathway.persistence.BiopaxProxy.RdfObjectProxy)

Example 54 with Attribute

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

the class PathwayReader method addContentControl.

private boolean addContentControl(Control control, Element element, Element childElement) {
    if (addContentInteraction(control, element, childElement)) {
        return true;
    }
    /**
     * InteractionImpl controlledInteraction
     * Pathway controlledPathway
     * String controlType
     * ArrayList<Pathway> pathwayControllers
     * ArrayList<PhysicalEntity> physicalControllers
     */
    if (childElement.getName().equals("CONTROLLER")) {
        Element physicalEntityParticipantElement = childElement.getChild("physicalEntityParticipant", bp);
        if (physicalEntityParticipantElement != null) {
            Element physicalEntityPropertyElement = physicalEntityParticipantElement.getChild("PHYSICAL-ENTITY", bp);
            if (physicalEntityPropertyElement != null) {
                if (physicalEntityPropertyElement.getChildren().size() == 0) {
                    PhysicalEntityProxy physicalEntityProxy = new PhysicalEntityProxy();
                    addAttributes(physicalEntityProxy, physicalEntityPropertyElement);
                    pathwayModel.add(physicalEntityProxy);
                    control.addPhysicalController(physicalEntityProxy);
                    return true;
                }
            }
        }
        Element sequenceParticipantElement = childElement.getChild("sequenceParticipant", bp);
        if (sequenceParticipantElement != null) {
            Element physicalEntityPropertyElement = sequenceParticipantElement.getChild("PHYSICAL-ENTITY", bp);
            if (physicalEntityPropertyElement != null) {
                if (physicalEntityPropertyElement.getChildren().size() == 0) {
                    PhysicalEntityProxy physicalEntityProxy = new PhysicalEntityProxy();
                    addAttributes(physicalEntityProxy, physicalEntityPropertyElement);
                    pathwayModel.add(physicalEntityProxy);
                    control.addPhysicalController(physicalEntityProxy);
                    return true;
                }
            }
        }
        // }
        return false;
    // // is it a pathway controller?
    // control.getPathwayControllers().add(addPathway(childElement));
    } else if (childElement.getName().equals("CONTROLLED")) {
        Attribute resourceAttribute = childElement.getAttribute("resource", rdf);
        if (resourceAttribute != null) {
            InteractionOrPathwayProxy controlledEntityProxy = new InteractionOrPathwayProxy();
            control.setControlledInteraction(controlledEntityProxy);
            pathwayModel.add(controlledEntityProxy);
            String uri = context.unRelativizeURI(childElement, resourceAttribute.getValue());
            controlledEntityProxy.setID(uri);
            return true;
        }
        return false;
    } else if (childElement.getName().equals("CONTROL-TYPE")) {
        control.setControlType(childElement.getTextTrim());
        return true;
    } else {
        return false;
    }
}
Also used : Attribute(org.jdom.Attribute) Element(org.jdom.Element) PhysicalEntityProxy(org.vcell.pathway.persistence.BiopaxProxy.PhysicalEntityProxy) InteractionOrPathwayProxy(org.vcell.pathway.persistence.BiopaxProxy.InteractionOrPathwayProxy)

Example 55 with Attribute

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

the class PathwayReader method addAttributes.

private void addAttributes(BioPaxObject bioPaxObject, Element element) {
    for (Object attr : element.getAttributes()) {
        Attribute attribute = (Attribute) attr;
        if (attribute.getName().equals("ID")) {
            if (bioPaxObject instanceof RdfObjectProxy) {
                showUnexpected(attribute, bioPaxObject);
            } else {
                String uri = context.unAbbreviateURI(element, attribute.getValue());
                bioPaxObject.setID(uri);
            }
        } else if (attribute.getName().equals("resource")) {
            if (bioPaxObject instanceof RdfObjectProxy) {
                String uri = context.unRelativizeURI(element, attribute.getValue());
                bioPaxObject.setID(uri);
            } else {
                showUnexpected(attribute, bioPaxObject);
            }
        } else {
            showUnexpected(attribute, bioPaxObject);
        }
    }
}
Also used : Attribute(org.jdom.Attribute) BioPaxObject(org.vcell.pathway.BioPaxObject) RdfObjectProxy(org.vcell.pathway.persistence.BiopaxProxy.RdfObjectProxy)

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