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);
}
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;
}
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);
}
}
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;
}
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));
}
Aggregations