Search in sources :

Example 26 with Content

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

the class UniqueOnCancelValidatorTest method shouldFailWithExceptionWhenThereIsMoreThanOneOnCancelTasksForAPluginInTask.

@Test
public void shouldFailWithExceptionWhenThereIsMoreThanOneOnCancelTasksForAPluginInTask() throws Exception {
    ConfigElementImplementationRegistry registry = mock(ConfigElementImplementationRegistry.class);
    when(registry.implementersOf(Task.class)).thenReturn(tasks(ExecTask.class, PluggableTask.class));
    String content = "<cruise>" + "  <pipeline>" + "    <stage>" + "      <jobs>" + "        <job>" + "          <tasks>" + "              <task name=\"\">\n" + "                <pluginConfiguration id=\"curl.task.plugin\" version=\"1\" />\n" + "                <configuration>\n" + "                  <property>\n" + "                    <key>Url</key>\n" + "                    <value>With_On_Cancel</value>\n" + "                  </property>\n" + "                </configuration>\n" + "                <runif status=\"passed\" />\n" + "                <oncancel>\n" + "                  <ant buildfile=\"blah\" target=\"blah1\" />\n" + "                </oncancel>\n" + "                <oncancel>\n" + "                  <ant buildfile=\"blah\" target=\"blah2\" />\n" + "                </oncancel>\n" + "              </task>" + "          </tasks>" + "        </job>" + "      </jobs>" + "    </stage>" + "  </pipeline>" + "</cruise>";
    try {
        UniqueOnCancelValidator validator = new UniqueOnCancelValidator();
        validator.validate(elementFor(content), registry);
    } catch (Exception e) {
        assertThat(e.getMessage(), is("Task [task] should not contain more than 1 oncancel task"));
    }
}
Also used : ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ExecTask(com.thoughtworks.go.config.ExecTask) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) Test(org.junit.jupiter.api.Test)

Example 27 with Content

use of org.jdom2.Content 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) XmlUtils.buildXmlDocument(com.thoughtworks.go.util.XmlUtils.buildXmlDocument) Document(org.jdom2.Document) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException)

Example 28 with Content

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

the class MagicalGoConfigXmlLoader method deserializeConfig.

public CruiseConfig deserializeConfig(String content) throws Exception {
    String md5 = 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 29 with Content

use of org.jdom2.Content in project mycore by MyCoRe-Org.

the class MCRMetaLink method createXML.

/**
 * This method create a XML stream for all data in this class, defined by the MyCoRe XML MCRMetaLink definition for the given subtag.
 *
 * @exception MCRException
 *                if the content of this class is not valid
 * @return a JDOM Element with the XML MCRMetaLink part
 */
@Override
public org.jdom2.Element createXML() throws MCRException {
    Element elm = super.createXML();
    elm.setAttribute("type", linktype, XLINK_NAMESPACE);
    if (title != null) {
        elm.setAttribute("title", title, XLINK_NAMESPACE);
    }
    if (label != null) {
        elm.setAttribute("label", label, XLINK_NAMESPACE);
    }
    if (role != null) {
        elm.setAttribute("role", role, XLINK_NAMESPACE);
    }
    if (linktype.equals("locator")) {
        elm.setAttribute("href", href, XLINK_NAMESPACE);
    } else {
        elm.setAttribute("from", from, XLINK_NAMESPACE);
        elm.setAttribute("to", to, XLINK_NAMESPACE);
    }
    return elm;
}
Also used : Element(org.jdom2.Element)

Example 30 with Content

use of org.jdom2.Content in project mycore by MyCoRe-Org.

the class MCRMetaNumber method createXML.

/**
 * This method creates an XML element containing all data in this instance,
 * as defined by the MyCoRe XML MCRNumber definition for the given subtag.
 *
 * @exception MCRException
 *                if the content of this instance is not valid
 * @return a JDOM Element with the XML MCRNumber part
 */
@Override
public final org.jdom2.Element createXML() throws MCRException {
    Element elm = super.createXML();
    if (dimension != null && dimension.length() != 0) {
        elm.setAttribute("dimension", dimension);
    }
    if (measurement != null && measurement.length() != 0) {
        elm.setAttribute("measurement", measurement);
    }
    elm.addContent(getNumberAsString());
    return elm;
}
Also used : Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)77 Document (org.jdom2.Document)27 IOException (java.io.IOException)18 JDOMException (org.jdom2.JDOMException)16 File (java.io.File)11 MCRException (org.mycore.common.MCRException)11 Content (org.jdom2.Content)10 MCRContent (org.mycore.common.content.MCRContent)10 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)10 XMLOutputter (org.jdom2.output.XMLOutputter)9 SAXBuilder (org.jdom2.input.SAXBuilder)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Attribute (org.jdom2.Attribute)6 MCRPath (org.mycore.datamodel.niofs.MCRPath)6 SAXException (org.xml.sax.SAXException)6 JsonElement (com.google.gson.JsonElement)5 Color (java.awt.Color)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 MCRObject (org.mycore.datamodel.metadata.MCRObject)4