Search in sources :

Example 16 with Element

use of org.jdom2.Element in project gocd by gocd.

the class GoConfigFieldWriter method parseCollection.

@SuppressWarnings("unchecked")
private Collection parseCollection(Element e, Class<?> collectionType) {
    ConfigCollection collection = collectionType.getAnnotation(ConfigCollection.class);
    Class<?> type = collection.value();
    Object o = newInstance(collectionType);
    bombUnless(o instanceof Collection, "Must be some sort of list. Was: " + collectionType.getName());
    Collection baseCollection = (Collection) o;
    for (Element childElement : (List<Element>) e.getChildren()) {
        if (isInCollection(childElement, type)) {
            baseCollection.add(parseType(childElement, type));
        }
    }
    bombIf(baseCollection.size() < collection.minimum(), "Required at least " + collection.minimum() + " subelements to '" + e.getName() + "'. " + "Found " + baseCollection.size() + ".");
    return baseCollection;
}
Also used : Element(org.jdom2.Element) Collection(java.util.Collection) List(java.util.List)

Example 17 with Element

use of org.jdom2.Element in project gocd by gocd.

the class SvnLogXmlParser method parseLogEntry.

private Modification parseLogEntry(Element logEntry, String path) throws ParseException {
    Element logEntryPaths = logEntry.getChild("paths");
    if (logEntryPaths == null) {
        /* Path-based access control forbids us from learning
             * details of this log entry, so skip it. */
        return null;
    }
    Date modifiedTime = convertDate(logEntry.getChildText("date"));
    String author = logEntry.getChildText("author");
    String comment = logEntry.getChildText("msg");
    String revision = logEntry.getAttributeValue("revision");
    Modification modification = new Modification(author, comment, null, modifiedTime, revision);
    List paths = logEntryPaths.getChildren("path");
    for (Iterator iterator = paths.iterator(); iterator.hasNext(); ) {
        Element node = (Element) iterator.next();
        if (underPath(path, node.getText())) {
            ModifiedAction action = convertAction(node.getAttributeValue("action"));
            modification.createModifiedFile(node.getText(), null, action);
        }
    }
    return modification;
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) Element(org.jdom2.Element) Iterator(java.util.Iterator) ModifiedAction(com.thoughtworks.go.domain.materials.ModifiedAction) ArrayList(java.util.ArrayList) List(java.util.List) Date(java.util.Date)

Example 18 with Element

use of org.jdom2.Element in project gocd by gocd.

the class SvnLogXmlParser method parseDOMTree.

private List<Modification> parseDOMTree(Document document, String path) throws ParseException {
    List<Modification> modifications = new ArrayList<>();
    Element rootElement = document.getRootElement();
    List logEntries = rootElement.getChildren("logentry");
    for (Iterator iterator = logEntries.iterator(); iterator.hasNext(); ) {
        Element logEntry = (Element) iterator.next();
        Modification modification = parseLogEntry(logEntry, path);
        if (modification != null) {
            modifications.add(modification);
        }
    }
    return modifications;
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with Element

use of org.jdom2.Element in project gocd by gocd.

the class HgModificationSplitter method parseDOMTree.

private List<Modification> parseDOMTree(Document document) throws ParseException {
    List<Modification> modifications = new ArrayList<>();
    Element rootElement = document.getRootElement();
    List logEntries = rootElement.getChildren("changeset");
    for (Iterator iterator = logEntries.iterator(); iterator.hasNext(); ) {
        Element changeset = (Element) iterator.next();
        modifications.add(parseChangeset(changeset));
    }
    return modifications;
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with Element

use of org.jdom2.Element in project gocd by gocd.

the class HgModificationSplitter method parseChangeset.

private Modification parseChangeset(Element changeset) throws ParseException {
    Date modifiedTime = DateUtils.parseRFC822(changeset.getChildText("date"));
    String author = org.apache.commons.lang.StringEscapeUtils.unescapeXml(changeset.getChildText("author"));
    String comment = org.apache.commons.lang.StringEscapeUtils.unescapeXml(changeset.getChildText("desc"));
    String revision = changeset.getChildText("node");
    Modification modification = new Modification(author, comment, null, modifiedTime, revision);
    Element files = changeset.getChild("files");
    List<File> modifiedFiles = parseFiles(files, "modified");
    List<File> addedFiles = parseFiles(files, "added");
    List<File> deletedFiles = parseFiles(files, "deleted");
    modifiedFiles.removeAll(addedFiles);
    modifiedFiles.removeAll(deletedFiles);
    addModificationFiles(modification, ModifiedAction.added, addedFiles);
    addModificationFiles(modification, ModifiedAction.deleted, deletedFiles);
    addModificationFiles(modification, ModifiedAction.modified, modifiedFiles);
    return modification;
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) Element(org.jdom2.Element) File(java.io.File) Date(java.util.Date)

Aggregations

Element (org.jdom2.Element)673 Attribute (org.jdom2.Attribute)103 Document (org.jdom2.Document)64 File (java.io.File)49 ArrayList (java.util.ArrayList)36 NamedIcon (jmri.jmrit.catalog.NamedIcon)28 IOException (java.io.IOException)27 DataConversionException (org.jdom2.DataConversionException)26 JDOMException (org.jdom2.JDOMException)26 XmlFile (jmri.jmrit.XmlFile)24 Test (org.junit.Test)24 Editor (jmri.jmrit.display.Editor)22 DocType (org.jdom2.DocType)21 Turnout (jmri.Turnout)20 ProcessingInstruction (org.jdom2.ProcessingInstruction)16 Point (java.awt.Point)15 HashMap (java.util.HashMap)15 SignalHead (jmri.SignalHead)15 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)15 Dimension (java.awt.Dimension)14