Search in sources :

Example 21 with Element

use of org.omegat.filters3.Element in project gocd by gocd.

the class StageCctrayPresentationModelTest method shouldGetGoodCctrayXml.

@Test
public void shouldGetGoodCctrayXml() throws Exception {
    Element root = new Element("Projects");
    cctrayXmlPresenter.toCctrayXml(root, CONTEXT_PATH);
    assertThat(root.getChildren().size(), is(2));
    shouldContainStage(root);
    shouldContainBuilds(root);
}
Also used : Element(org.jdom2.Element) Test(org.junit.Test)

Example 22 with Element

use of org.omegat.filters3.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 23 with Element

use of org.omegat.filters3.Element in project gocd by gocd.

the class GoConfigMigration method getCurrentSchemaVersion.

private int getCurrentSchemaVersion(String content) {
    try {
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(new ByteArrayInputStream(content.getBytes()));
        Element root = document.getRootElement();
        String currentVersion = root.getAttributeValue(schemaVersion) == null ? "0" : root.getAttributeValue(schemaVersion);
        return Integer.parseInt(currentVersion);
    } catch (Exception e) {
        throw bomb(e);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) XmlUtils.buildXmlDocument(com.thoughtworks.go.util.XmlUtils.buildXmlDocument) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException)

Example 24 with Element

use of org.omegat.filters3.Element in project gocd by gocd.

the class MagicalGoConfigXmlLoader method deserializeConfig.

public CruiseConfig deserializeConfig(String content) throws Exception {
    String md5 = CachedDigestUtils.md5Hex(content);
    Element element = parseInputStream(new ByteArrayInputStream(content.getBytes()));
    LOGGER.debug("[Config Save] Updating config cache with new XML");
    CruiseConfig configForEdit = classParser(element, BasicCruiseConfig.class, configCache, new GoCipher(), registry, new ConfigReferenceElements()).parse();
    setMd5(configForEdit, md5);
    configForEdit.setOrigins(new FileConfigOrigin());
    return configForEdit;
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ByteArrayInputStream(java.io.ByteArrayInputStream) FileConfigOrigin(com.thoughtworks.go.config.remote.FileConfigOrigin) Element(org.jdom2.Element) ConfigReferenceElements(com.thoughtworks.go.config.parser.ConfigReferenceElements)

Example 25 with Element

use of org.omegat.filters3.Element in project gocd by gocd.

the class GoConfigFieldTest method shouldConvertFromXmlToJavaObjectCorrectly.

@Test
public void shouldConvertFromXmlToJavaObjectCorrectly() throws Exception {
    final Foo object = new Foo();
    final GoConfigFieldWriter field = new GoConfigFieldWriter(Foo.class.getDeclaredField("number"), object, configCache, null);
    final Element element = new Element("foo");
    element.setAttribute("number", "100");
    field.setValueIfNotNull(element, object);
    assertThat(object.number, is(100L));
}
Also used : Element(org.jdom2.Element) Test(org.junit.Test)

Aggregations

Element (org.jdom2.Element)1444 Document (org.jdom2.Document)242 Test (org.junit.Test)157 ArrayList (java.util.ArrayList)111 Attribute (org.jdom2.Attribute)106 IOException (java.io.IOException)76 File (java.io.File)71 JDOMException (org.jdom2.JDOMException)65 XMLOutputter (org.jdom2.output.XMLOutputter)54 List (java.util.List)51 SAXBuilder (org.jdom2.input.SAXBuilder)51 HashMap (java.util.HashMap)49 Test (org.junit.jupiter.api.Test)34 Map (java.util.Map)33 Node (gov.cms.qpp.conversion.model.Node)29 MCRException (org.mycore.common.MCRException)28 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)28 NamedIcon (jmri.jmrit.catalog.NamedIcon)27 Namespace (org.jdom2.Namespace)25 XmlFile (jmri.jmrit.XmlFile)24