Search in sources :

Example 6 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project pcgen by PCGen.

the class RoomBoardFactory method load.

public static RoomBoard load(File dataDir) {
    //Create a new list for the room and board
    PairList<RBCost> inns = new PairList<>();
    PairList<RBCost> foods = new PairList<>();
    PairList<RBCost> animals = new PairList<>();
    File path = new File(dataDir, DIR_RNBPRICE);
    if (path.isDirectory()) {
        File[] dataFiles = path.listFiles(new XMLFilter());
        SAXBuilder builder = new SAXBuilder();
        for (int i = 0; i < dataFiles.length; i++) {
            try {
                Document methodSet = builder.build(dataFiles[i]);
                DocType dt = methodSet.getDocType();
                if (//$NON-NLS-1$
                dt.getElementName().equals("RNBPRICE")) {
                    //Do work here
                    loadRBData(methodSet, inns, foods, animals);
                }
                methodSet = null;
                dt = null;
            } catch (Exception e) {
                Logging.errorPrintLocalised("XML Error with file {0}", dataFiles[i].getName());
                Logging.errorPrint(e.getMessage(), e);
            }
        }
    } else {
        //$NON-NLS-1$
        Logging.errorPrintLocalised("in_plugin_overland_noDatafile", path.getPath());
    }
    return new RoomBoardImplementation(inns, foods, animals);
}
Also used : RBCost(plugin.overland.util.RBCost) SAXBuilder(org.jdom2.input.SAXBuilder) XMLFilter(plugin.overland.gui.XMLFilter) PairList(plugin.overland.util.PairList) Document(org.jdom2.Document) File(java.io.File) DocType(org.jdom2.DocType) ParseException(java.text.ParseException)

Example 7 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project gocd by gocd.

the class XmlView method renderMergedOutputModel.

protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Document document = (Document) model.get("document");
    ServletOutputStream outputStream = response.getOutputStream();
    try {
        XmlUtils.writeXml(document, outputStream);
    } finally {
        IOUtils.closeQuietly(outputStream);
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) Document(org.jdom2.Document)

Example 8 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project gocd by gocd.

the class GoControlLog method writeLogFile.

protected void writeLogFile(File file, Element element) throws IOException {
    // Write the log file out, let jdom care about the encoding by using
    // an OutputStream instead of a Writer.
    OutputStream logStream = null;
    try {
        Format format = Format.getPrettyFormat();
        XMLOutputter outputter = new XMLOutputter(format);
        IO.mkdirFor(file);
        file.setWritable(true);
        logStream = new BufferedOutputStream(new FileOutputStream(file));
        outputter.output(new Document(element), logStream);
    } finally {
        IO.close(logStream);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Format(org.jdom2.output.Format) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) Document(org.jdom2.Document) BufferedOutputStream(java.io.BufferedOutputStream)

Example 9 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document 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 10 with Document

use of org.datanucleus.samples.annotations.one_many.bidir_3.Document in project gocd by gocd.

the class GoConfigMigrationIntegrationTest method shouldRemoveAllLuauConfigurationFromConfig.

@Test
public void shouldRemoveAllLuauConfigurationFromConfig() throws Exception {
    String configString = "<cruise schemaVersion='66'>" + "<server siteUrl='https://hostname'>" + "<security>" + "      <luau url='https://luau.url.com' clientKey='0d010cf97ec505ee3788a9b5b8cf71d482c394ae88d32f0333' authState='authorized' />" + "      <ldap uri='ldap' managerDn='managerDn' encryptedManagerPassword='+XhtUNvVAxJdHGF4qQGnWw==' searchFilter='(sAMAccountName={0})'>" + "        <bases>" + "          <base value='ou=Enterprise,ou=Principal,dc=corporate,dc=thoughtworks,dc=com' />" + "        </bases>" + "      </ldap>" + "      <roles>" + "         <role name='luau-role'><groups><luauGroup>luau-group</luauGroup></groups></role>" + "         <role name='ldap-role'><users><user>some-user</user></users></role>" + "</roles>" + "</security>" + "</server>" + "</cruise>";
    String migratedContent = migrateXmlString(configString, 66);
    Document document = new SAXBuilder().build(new StringReader(migratedContent));
    assertThat(document.getDescendants(new ElementFilter("luau")).hasNext(), is(false));
    assertThat(document.getDescendants(new ElementFilter("groups")).hasNext(), is(false));
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) ElementFilter(org.jdom2.filter.ElementFilter) StringReader(java.io.StringReader) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Document(org.jdom2.Document) Test(org.junit.Test)

Aggregations

Document (org.jdom2.Document)391 Element (org.jdom2.Element)243 Test (org.junit.Test)104 SAXBuilder (org.jdom2.input.SAXBuilder)84 IOException (java.io.IOException)72 File (java.io.File)56 XMLOutputter (org.jdom2.output.XMLOutputter)56 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 ArrayList (java.util.ArrayList)22 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 MCRException (org.mycore.common.MCRException)21 Document (com.google.cloud.language.v1.Document)20 HashMap (java.util.HashMap)19 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 URL (java.net.URL)18