Example usage for org.dom4j DocumentHelper makeElement

List of usage examples for org.dom4j DocumentHelper makeElement

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper makeElement.

Prototype

public static Element makeElement(Branch source, String path) 

Source Link

Document

makeElement

a helper method which navigates from the given Document or Element node to some Element using the path expression, creating any necessary elements along the way.

Usage

From source file:org.pentaho.actionsequence.dom.ActionSequenceDocument.java

License:Open Source License

/**
 * Sets the action sequence title.//from   w ww . j  av a 2  s. c  o m
 * 
 * @param value
 *          the title
 */
public void setTitle(String value) {
    Element actSeq = (Element) document.selectSingleNode(ACTION_SEQUENCE);
    Element subElement = DocumentHelper.makeElement(actSeq, ACTION_SEQUENCE_TITLE);
    subElement.setText(value == null ? "" : value); //$NON-NLS-1$
    fireHeaderChanged(this);
}

From source file:org.pentaho.actionsequence.dom.ActionSequenceDocument.java

License:Open Source License

/**
 * Adds a new input this action sequence. If the input already exists the type of the input is set to the specified
 * type.//  ww  w .j  a  v  a  2s.c  om
 * 
 * @param inputName
 *          the input name
 * @param inputType
 *          the input type
 * @return the action sequence input
 */
public IActionSequenceInput createInput(String inputName, String inputType) {
    IActionSequenceInput input = getInput(inputName);
    if (input == null) {
        Element inputElement = DocumentHelper.makeElement(document.getRootElement(),
                DOC_INPUTS_NAME + "/" + inputName); //$NON-NLS-1$
        inputElement.addAttribute(IAbstractIOElement.TYPE_NAME, inputType);
        input = new ActionSequenceInput(inputElement, actionInputProvider);
        fireIoAdded(input);
        if (inputType.equals(ActionSequenceDocument.STRING_TYPE)) {
            input.addSource(REQUEST_INPUT_SOURCE, inputName);
        }
    } else {
        input.setType(inputType);
    }
    return input;
}

From source file:org.pentaho.actionsequence.dom.ActionSequenceDocument.java

License:Open Source License

/**
 * Adds a new output to this action sequence. If the output already exists the type of the output is set to the
 * specified type./*from w  w w . jav a2  s .c  o m*/
 * 
 * @param outputName
 *          the input name
 * @param outputType
 *          the input type
 * @return the action sequence output
 */
public IActionSequenceOutput createOutput(String outputName, String outputType) {
    IActionSequenceOutput output = getOutput(outputName);
    if (output == null) {
        Element outputElement = DocumentHelper.makeElement(document.getRootElement(),
                DOC_OUTPUTS_NAME + "/" + outputName); //$NON-NLS-1$
        outputElement.addAttribute(IAbstractIOElement.TYPE_NAME, outputType);
        output = new ActionSequenceOutput(outputElement, actionInputProvider);
        fireIoAdded(output);
    } else {
        output.setType(outputType);
    }
    return output;
}

From source file:org.pentaho.actionsequence.dom.ActionSequenceDocument.java

License:Open Source License

/**
 * Adds a new resource to this action sequence.
 * //w w  w  .  j  a  v  a 2  s  .c  o  m
 * @param resourceName
 *          the resource name
 * @param resourceFileType
 *          the resource file type
 * @param filePath
 *          the resource file path
 * @param mimeType
 *          the resource mime type
 * @return the action sequence resource
 */
public IActionSequenceResource setResourceUri(String resourceName, URI uri, String mimeType) {
    IActionSequenceResource docResource = getResource(resourceName);
    if (uri == null) {
        if (docResource != null) {
            docResource.delete();
            fireResourceRemoved(getDocument(), docResource);
        }
    } else {
        if (docResource == null) {
            Element resourceElement = DocumentHelper.makeElement(document.getRootElement(),
                    DOC_RESOURCES_NAME + "/" + resourceName); //$NON-NLS-1$
            docResource = new ActionSequenceResource(resourceElement, actionInputProvider);
            fireResourceAdded(docResource);
        }
        docResource.setUri(uri);
        docResource.setMimeType(mimeType);
    }
    return docResource;
}

From source file:org.pentaho.actionsequence.dom.ActionSequenceInput.java

License:Open Source License

public IActionSequenceInputSource addSource(String origin, String name) {
    Element sourceParent = DocumentHelper.makeElement(ioElement, ActionSequenceDocument.INPUT_SOURCES_NAME);
    Element newSourceElement = sourceParent.addElement(origin);
    newSourceElement.setText(name);//from   w ww. j  av a  2s .c  o  m
    IActionSequenceInputSource actionSequenceInputSource = new ActionSequenceInputSource(newSourceElement,
            actionInputProvider);
    ActionSequenceDocument.fireIoChanged(this);
    return actionSequenceInputSource;
}

From source file:org.pentaho.actionsequence.dom.ActionSequenceOutput.java

License:Open Source License

public IActionSequenceOutputDestination addDestination(String destination, String name) {
    Element destinationParent = DocumentHelper.makeElement(ioElement,
            ActionSequenceDocument.OUTPUTS_DESTINATIONS_NAME);
    Element newDestinationElement = destinationParent.addElement(destination);
    newDestinationElement.setText(name);
    IActionSequenceOutputDestination actionSequenceOutputDestination = new ActionSequenceOutputDestination(
            newDestinationElement, actionInputProvider);
    ActionSequenceDocument.fireIoChanged(this);
    return actionSequenceOutputDestination;
}

From source file:org.pentaho.actionsequence.dom.ActionSequenceResource.java

License:Open Source License

/**
 * Sets the resource mime type./*from w ww.  j a v  a  2 s.  co m*/
 * 
 * @param mimeType
 *          the mime type
 */
public void setMimeType(String mimeType) {
    String resType = getType();
    Element mimeElement = null;
    if (SOLUTION_FILE_RESOURCE_TYPE.equals(resType)) {
        mimeElement = (Element) ioElement
                .selectSingleNode(SOLUTION_FILE_RESOURCE_TYPE + "/" + RES_MIME_TYPE_NAME); //$NON-NLS-1$
    } else if (FILE_RESOURCE_TYPE.equals(resType)) {
        mimeElement = (Element) ioElement.selectSingleNode(FILE_RESOURCE_TYPE + "/" + RES_MIME_TYPE_NAME); //$NON-NLS-1$
    } else if (URL_RESOURCE_TYPE.equals(resType)) {
        mimeElement = (Element) ioElement.selectSingleNode(URL_RESOURCE_TYPE + "/" + RES_MIME_TYPE_NAME); //$NON-NLS-1$
    }

    if (mimeElement == null) {
        if (SOLUTION_FILE_RESOURCE_TYPE.equals(resType)) {
            mimeElement = DocumentHelper.makeElement(ioElement,
                    SOLUTION_FILE_RESOURCE_TYPE + "/" + RES_MIME_TYPE_NAME); //$NON-NLS-1$
        } else if (FILE_RESOURCE_TYPE.equals(resType)) {
            mimeElement = DocumentHelper.makeElement(ioElement, FILE_RESOURCE_TYPE + "/" + RES_MIME_TYPE_NAME); //$NON-NLS-1$
        } else if (URL_RESOURCE_TYPE.equals(resType)) {
            mimeElement = DocumentHelper.makeElement(ioElement, URL_RESOURCE_TYPE + "/" + RES_MIME_TYPE_NAME); //$NON-NLS-1$
        }
        mimeElement.setText(mimeType);
        ActionSequenceDocument.fireResourceChanged(this);
    } else if (!mimeElement.getText().equals(mimeType)) {
        mimeElement.setText(mimeType);
        ActionSequenceDocument.fireResourceChanged(this);
    }
}

From source file:org.pentaho.actionsequence.dom.ActionSequenceResource.java

License:Open Source License

/**
 * Sets the resource URI/*from ww  w . ja  v a  2  s. c o  m*/
 * 
 * @param uri
 *          the resource URI
 */
public void setPath(String uri) {
    String resType = getType();
    Element pathElement = null;
    if (SOLUTION_FILE_RESOURCE_TYPE.equals(resType)) {
        pathElement = (Element) ioElement
                .selectSingleNode(SOLUTION_FILE_RESOURCE_TYPE + "/" + RES_LOCATION_NAME); //$NON-NLS-1$
    } else if (FILE_RESOURCE_TYPE.equals(resType)) {
        pathElement = (Element) ioElement.selectSingleNode(FILE_RESOURCE_TYPE + "/" + RES_LOCATION_NAME); //$NON-NLS-1$
    } else if (URL_RESOURCE_TYPE.equals(resType)) {
        pathElement = (Element) ioElement.selectSingleNode(URL_RESOURCE_TYPE + "/" + RES_LOCATION_NAME); //$NON-NLS-1$
    }

    if (pathElement == null) {
        if (SOLUTION_FILE_RESOURCE_TYPE.equals(resType)) {
            pathElement = DocumentHelper.makeElement(ioElement,
                    SOLUTION_FILE_RESOURCE_TYPE + "/" + RES_LOCATION_NAME); //$NON-NLS-1$
        } else if (FILE_RESOURCE_TYPE.equals(resType)) {
            pathElement = DocumentHelper.makeElement(ioElement, FILE_RESOURCE_TYPE + "/" + RES_LOCATION_NAME); //$NON-NLS-1$
        } else if (URL_RESOURCE_TYPE.equals(resType)) {
            pathElement = DocumentHelper.makeElement(ioElement, URL_RESOURCE_TYPE + "/" + RES_LOCATION_NAME); //$NON-NLS-1$
        }
        pathElement.setText(uri);
        ActionSequenceDocument.fireResourceChanged(this);
    } else if (!pathElement.getText().equals(uri)) {
        pathElement.setText(uri);
        ActionSequenceDocument.fireResourceChanged(this);
    }
}

From source file:org.pentaho.actionsequence.dom.ImplicitActionResource.java

License:Open Source License

public void setMapping(String mapping) {
    if (actionDefinition != null) {
        IActionResource actionResource = actionDefinition.getResource(resourceName, false);
        if (actionResource != null) {
            actionResource.setMapping(mapping);
        } else {//from   w  w w  .  j  a v a2 s  .  co m
            Element tempElement = getElement();
            Element resourcesParent = DocumentHelper.makeElement(actionDefinition.getElement(),
                    ActionSequenceDocument.ACTION_RESOURCES_NAME); //$NON-NLS-1$
            resourcesParent.add(tempElement);
            super.setMapping(mapping);
        }
    } else {
        super.setMapping(mapping);
    }
}

From source file:org.pentaho.actionsequence.dom.ImplicitActionResource.java

License:Open Source License

public void setMimeType(String mimeType) {
    if (actionDefinition != null) {
        IActionResource actionResource = actionDefinition.getResource(resourceName, false);
        if (actionResource != null) {
            actionResource.setMimeType(mimeType);
        } else {/* w  w w . j  av a 2s  .c  om*/
            Element tempElement = getElement();
            Element resourcesParent = DocumentHelper.makeElement(actionDefinition.getElement(),
                    ActionSequenceDocument.ACTION_RESOURCES_NAME); //$NON-NLS-1$
            resourcesParent.add(tempElement);
            super.setMimeType(mimeType);
        }
    } else {
        super.setMimeType(mimeType);
    }
}