Search in sources :

Example 61 with Document

use of org.apache.type_test.types1.Document in project jPOS by jpos.

the class Q2 method deploy.

private boolean deploy(File f) {
    LogEvent evt = log != null ? log.createInfo() : null;
    try {
        QEntry qentry = dirMap.get(f);
        SAXBuilder builder = createSAXBuilder();
        Document doc;
        if (decorator != null && !f.getName().equals(LOGGER_CONFIG)) {
            doc = decrypt(builder.build(new StringReader(decorator.decorateFile(f))));
        } else {
            doc = decrypt(builder.build(f));
        }
        Element rootElement = doc.getRootElement();
        String iuuid = rootElement.getAttributeValue("instance");
        if (iuuid != null) {
            UUID uuid = UUID.fromString(iuuid);
            if (!uuid.equals(getInstanceId())) {
                deleteFile(f, iuuid);
                return false;
            }
        }
        String enabledAttribute = rootElement.getAttributeValue("enabled", "true");
        if ("true".equalsIgnoreCase(enabledAttribute) || "yes".equalsIgnoreCase(enabledAttribute)) {
            if (evt != null)
                evt.addMessage("deploy: " + f.getCanonicalPath());
            Object obj = factory.instantiate(this, rootElement);
            qentry.setObject(obj);
            ObjectInstance instance = factory.createQBean(this, doc.getRootElement(), obj);
            qentry.setInstance(instance);
        } else if (evt != null) {
            evt.addMessage("deploy ignored (enabled='" + enabledAttribute + "'): " + f.getCanonicalPath());
        }
    } catch (InstanceAlreadyExistsException e) {
        /*
            * Ok, the file we tried to deploy, holds an object
            *  that already has been deployed.
            *  
            * Rename it out of the way.
            * 
            */
        tidyFileAway(f, DUPLICATE_EXTENSION);
        if (evt != null)
            evt.addMessage(e);
        return false;
    } catch (Exception e) {
        if (evt != null)
            evt.addMessage(e);
        tidyFileAway(f, ERROR_EXTENSION);
        // This will also save deploy error repeats...
        return false;
    } catch (Error e) {
        if (evt != null)
            evt.addMessage(e);
        tidyFileAway(f, ENV_EXTENSION);
        // This will also save deploy error repeats...
        return false;
    } finally {
        if (evt != null)
            Logger.log(evt);
    }
    return true;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) LogEvent(org.jpos.util.LogEvent) Element(org.jdom2.Element) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectInstance(javax.management.ObjectInstance) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) GeneralSecurityException(java.security.GeneralSecurityException) BundleException(org.osgi.framework.BundleException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) SAXException(org.xml.sax.SAXException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ISOException(org.jpos.iso.ISOException) MissingArgumentException(org.apache.commons.cli.MissingArgumentException)

Example 62 with Document

use of org.apache.type_test.types1.Document in project jPOS by jpos.

the class Q2 method encrypt.

protected Document encrypt(Document doc) throws GeneralSecurityException, IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(os);
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    out.output(doc, writer);
    writer.close();
    byte[] crypt = dodes(os.toByteArray(), Cipher.ENCRYPT_MODE);
    Document secureDoc = new Document();
    Element root = new Element(PROTECTED_QBEAN);
    secureDoc.setRootElement(root);
    Element secureData = new Element("data");
    root.addContent(secureData);
    secureData.setText(ISOUtil.hexString(crypt));
    return secureDoc;
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 63 with Document

use of org.apache.type_test.types1.Document in project jPOS by jpos.

the class Q2 method deployResource.

private void deployResource(String resource) throws IOException, SAXException, JDOMException, GeneralSecurityException, ISOException {
    SAXBuilder builder = new SAXBuilder();
    try (InputStream source = getClass().getClassLoader().getResourceAsStream(resource)) {
        Document doc = builder.build(source);
        deployElement(doc.getRootElement(), resource.substring(DEPLOY_PREFIX.length()), false, true);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document)

Example 64 with Document

use of org.apache.type_test.types1.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)

Example 65 with Document

use of org.apache.type_test.types1.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)

Aggregations

Document (org.jdom2.Document)109 Element (org.jdom2.Element)74 SAXBuilder (org.jdom2.input.SAXBuilder)34 File (java.io.File)32 Test (org.junit.Test)29 DocType (org.jdom2.DocType)23 IOException (java.io.IOException)22 XMLOutputter (org.jdom2.output.XMLOutputter)20 JDOMException (org.jdom2.JDOMException)14 ProcessingInstruction (org.jdom2.ProcessingInstruction)13 XmlFile (jmri.jmrit.XmlFile)11 Document (com.google.cloud.language.v1beta2.Document)10 ApiException (com.google.api.gax.grpc.ApiException)9 Document (com.google.cloud.language.v1.Document)9 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)9 StatusRuntimeException (io.grpc.StatusRuntimeException)9 FileOutputStream (java.io.FileOutputStream)9 EncodingType (com.google.cloud.language.v1beta2.EncodingType)8 ArrayList (java.util.ArrayList)7 EncodingType (com.google.cloud.language.v1.EncodingType)6