Example usage for org.w3c.dom Element getOwnerDocument

List of usage examples for org.w3c.dom Element getOwnerDocument

Introduction

In this page you can find the example usage for org.w3c.dom Element getOwnerDocument.

Prototype

public Document getOwnerDocument();

Source Link

Document

The Document object associated with this node.

Usage

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addProcessor(final Element parentElement, ProcessorSchema processorConfig)
        throws ConfigurationChangeException {
    try {/*from   w w  w  . j a  v  a 2 s  .c o  m*/
        final Document doc = parentElement.getOwnerDocument();
        final Element element = doc.createElement("processor");
        parentElement.appendChild(element);

        addTextElement(element, "id", processorConfig.getId());
        addTextElement(element, "name", processorConfig.getName());

        addPosition(element);
        addStyle(element);

        addTextElement(element, "comment", "");
        addTextElement(element, "class", processorConfig.getProcessorClass());
        addTextElement(element, "maxConcurrentTasks", String.valueOf(processorConfig.getMaxConcurrentTasks()));
        addTextElement(element, "schedulingPeriod", processorConfig.getSchedulingPeriod());
        addTextElement(element, "penalizationPeriod", processorConfig.getPenalizationPeriod());
        addTextElement(element, "yieldPeriod", processorConfig.getYieldPeriod());
        addTextElement(element, "bulletinLevel", "WARN");
        addTextElement(element, "lossTolerant", "false");
        addTextElement(element, "scheduledState", "RUNNING");
        addTextElement(element, "schedulingStrategy", processorConfig.getSchedulingStrategy());
        addTextElement(element, "runDurationNanos", String.valueOf(processorConfig.getRunDurationNanos()));

        String annotationData = processorConfig.getAnnotationData();
        if (annotationData != null && !annotationData.isEmpty()) {
            addTextElement(element, "annotationData", annotationData);
        }

        addConfiguration(element, processorConfig.getProperties());

        Collection<String> autoTerminatedRelationships = processorConfig.getAutoTerminatedRelationshipsList();
        if (autoTerminatedRelationships != null) {
            for (String rel : autoTerminatedRelationships) {
                addTextElement(element, "autoTerminatedRelationship", rel);
            }
        }
    } catch (Exception e) {
        throw new ConfigurationChangeException(
                "Failed to parse the config YAML while trying to add a Processor", e);
    }
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addFunnel(final Element parentElement, FunnelSchema funnelSchema) {
    Document document = parentElement.getOwnerDocument();
    Element element = document.createElement("funnel");
    parentElement.appendChild(element);//  w ww  .  jav  a  2  s  .c  o  m

    addTextElement(element, "id", funnelSchema.getId());

    addPosition(element);
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addProvenanceReportingTask(final Element element, ConfigSchema configSchema)
        throws ConfigurationChangeException {
    try {//from w  w w  .j a v  a2s  .  com
        ProvenanceReportingSchema provenanceProperties = configSchema.getProvenanceReportingProperties();
        final Element taskElement = element.getOwnerDocument().createElement("reportingTask");
        addTextElement(taskElement, "id", "Provenance-Reporting");
        addTextElement(taskElement, "name", "Site-To-Site-Provenance-Reporting");
        addTextElement(taskElement, "comment", provenanceProperties.getComment());
        addTextElement(taskElement, "class", DEFAULT_PROV_REPORTING_TASK_CLASS);
        addTextElement(taskElement, "schedulingPeriod", provenanceProperties.getSchedulingPeriod());
        addTextElement(taskElement, "scheduledState", "RUNNING");
        addTextElement(taskElement, "schedulingStrategy", provenanceProperties.getSchedulingStrategy());

        Map<String, Object> attributes = new HashMap<>();
        attributes.put("Destination URL", provenanceProperties.getDestinationUrl());
        attributes.put("Input Port Name", provenanceProperties.getPortName());
        attributes.put("Instance URL", provenanceProperties.getOriginatingUrl());
        attributes.put("Compress Events", provenanceProperties.getUseCompression());
        attributes.put("Batch Size", provenanceProperties.getBatchSize());
        attributes.put("Communications Timeout", provenanceProperties.getTimeout());

        SecurityPropertiesSchema securityProps = configSchema.getSecurityProperties();
        if (securityProps.useSSL()) {
            attributes.put("SSL Context Service", "SSL-Context-Service");
        }

        addConfiguration(taskElement, attributes);

        element.appendChild(taskElement);
    } catch (Exception e) {
        throw new ConfigurationChangeException(
                "Failed to parse the config YAML while trying to add the Provenance Reporting Task", e);
    }
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addConfiguration(final Element element, Map<String, Object> elementConfig) {
    final Document doc = element.getOwnerDocument();
    if (elementConfig == null) {
        return;//www . ja va2  s.c o m
    }
    for (final Map.Entry<String, Object> entry : elementConfig.entrySet()) {

        final Element propElement = doc.createElement("property");
        addTextElement(propElement, "name", entry.getKey());
        if (entry.getValue() != null) {
            addTextElement(propElement, "value", entry.getValue().toString());
        }

        element.appendChild(propElement);
    }
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addStyle(final Element parentElement) {
    final Element element = parentElement.getOwnerDocument().createElement("styles");
    parentElement.appendChild(element);/* w  ww. ja v  a  2s  .  c  o  m*/
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addRemoteProcessGroup(final Element parentElement,
        RemoteProcessGroupSchema remoteProcessGroupProperties) throws ConfigurationChangeException {
    try {//from ww  w . j  av a 2s  .  co m
        final Document doc = parentElement.getOwnerDocument();
        final Element element = doc.createElement("remoteProcessGroup");
        parentElement.appendChild(element);
        addTextElement(element, "id", remoteProcessGroupProperties.getId());
        addTextElement(element, "name", remoteProcessGroupProperties.getName());
        addPosition(element);
        addTextElement(element, "comment", remoteProcessGroupProperties.getComment());
        addTextElement(element, "url", remoteProcessGroupProperties.getUrl());
        addTextElement(element, "timeout", remoteProcessGroupProperties.getTimeout());
        addTextElement(element, "yieldPeriod", remoteProcessGroupProperties.getYieldPeriod());
        addTextElement(element, "transmitting", "true");
        addTextElement(element, "transportProtocol", remoteProcessGroupProperties.getTransportProtocol());
        addTextElement(element, "proxyHost", remoteProcessGroupProperties.getProxyHost());
        if (remoteProcessGroupProperties.getProxyPort() != null) {
            addTextElement(element, "proxyPort", Integer.toString(remoteProcessGroupProperties.getProxyPort()));
        }
        addTextElement(element, "proxyUser", remoteProcessGroupProperties.getProxyUser());
        if (!StringUtils.isEmpty(remoteProcessGroupProperties.getProxyPassword())) {
            addTextElement(element, "proxyPassword", remoteProcessGroupProperties.getProxyPassword());
        }

        List<RemotePortSchema> remoteInputPorts = remoteProcessGroupProperties.getInputPorts();
        for (RemotePortSchema remoteInputPortSchema : remoteInputPorts) {
            addRemoteGroupPort(element, remoteInputPortSchema, "inputPort");
        }

        List<RemotePortSchema> remoteOutputPorts = remoteProcessGroupProperties.getOutputPorts();
        for (RemotePortSchema remoteOutputPortSchema : remoteOutputPorts) {
            addRemoteGroupPort(element, remoteOutputPortSchema, "outputPort");
        }
        addTextElement(element, "networkInterface", remoteProcessGroupProperties.getLocalNetworkInterface());

        parentElement.appendChild(element);
    } catch (Exception e) {
        throw new ConfigurationChangeException(
                "Failed to parse the config YAML while trying to add the Remote Process Group", e);
    }
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addRemoteGroupPort(final Element parentElement, RemotePortSchema inputPort,
        String tagName) throws ConfigurationChangeException {
    try {/*ww  w .j a v a2 s. c  o m*/
        final Document doc = parentElement.getOwnerDocument();
        final Element element = doc.createElement(tagName);
        parentElement.appendChild(element);
        addTextElement(element, "id", inputPort.getId());
        addTextElement(element, "name", inputPort.getName());
        addPosition(element);
        addTextElement(element, "comments", inputPort.getComment());
        addTextElement(element, "scheduledState", "RUNNING");
        addTextElement(element, "maxConcurrentTasks", String.valueOf(inputPort.getMax_concurrent_tasks()));
        addTextElement(element, "useCompression", String.valueOf(inputPort.getUseCompression()));

        parentElement.appendChild(element);
    } catch (Exception e) {
        throw new ConfigurationChangeException(
                "Failed to parse the config YAML while trying to add the input port of the Remote Process Group",
                e);
    }
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addConnection(final Element parentElement, ConnectionSchema connectionProperties,
        ParentGroupIdResolver parentGroupIdResolver) throws ConfigurationChangeException {
    try {// ww  w . ja  v a  2  s . co  m
        final Document doc = parentElement.getOwnerDocument();
        final Element element = doc.createElement("connection");
        parentElement.appendChild(element);

        addTextElement(element, "id", connectionProperties.getId());
        addTextElement(element, "name", connectionProperties.getName());

        final Element bendPointsElement = doc.createElement("bendPoints");
        element.appendChild(bendPointsElement);

        addTextElement(element, "labelIndex", "1");
        addTextElement(element, "zIndex", "0");

        addConnectionSourceOrDestination(element, "source", connectionProperties.getSourceId(),
                parentGroupIdResolver);
        addConnectionSourceOrDestination(element, "destination", connectionProperties.getDestinationId(),
                parentGroupIdResolver);

        List<String> sourceRelationshipNames = connectionProperties.getSourceRelationshipNames();
        if (sourceRelationshipNames.isEmpty()) {
            addTextElement(element, "relationship", null);
        } else {
            for (String relationshipName : sourceRelationshipNames) {
                addTextElement(element, "relationship", relationshipName);
            }
        }

        addTextElement(element, "maxWorkQueueSize", String.valueOf(connectionProperties.getMaxWorkQueueSize()));
        addTextElement(element, "maxWorkQueueDataSize", connectionProperties.getMaxWorkQueueDataSize());

        addTextElement(element, "flowFileExpiration", connectionProperties.getFlowfileExpiration());
        addTextElementIfNotNullOrEmpty(element, "queuePrioritizerClass",
                connectionProperties.getQueuePrioritizerClass());

        parentElement.appendChild(element);
    } catch (Exception e) {
        throw new ConfigurationChangeException(
                "Failed to parse the config YAML while trying to add the connection from the Processor to the input port of the Remote Process Group",
                e);
    }
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addPosition(final Element parentElement) {
    final Element element = parentElement.getOwnerDocument().createElement("position");
    element.setAttribute("x", String.valueOf("0"));
    element.setAttribute("y", String.valueOf("0"));
    parentElement.appendChild(element);//  w  w  w .ja v  a 2s .co  m
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addTextElement(final Element element, final String name, final String value) {
    final Document doc = element.getOwnerDocument();
    final Element toAdd = doc.createElement(name);
    toAdd.setTextContent(value);//from  w  w  w . j a v a  2 s.co m
    element.appendChild(toAdd);
}