Example usage for org.dom4j Element clearContent

List of usage examples for org.dom4j Element clearContent

Introduction

In this page you can find the example usage for org.dom4j Element clearContent.

Prototype

void clearContent();

Source Link

Document

Clears the content for this branch, removing any Node instances this branch may contain.

Usage

From source file:org.orbeon.oxf.transformer.xupdate.statement.Update.java

License:Open Source License

public Object execute(URIResolver uriResolver, Object context, VariableContextImpl variableContext,
        DocumentContext documentContext) {
    for (Iterator i = Utils.evaluateToList(uriResolver, context, variableContext, getLocationData(), select,
            namespaceContext, documentContext).iterator(); i.hasNext();) {
        Object node = i.next();//from  ww  w  .  j a v a  2  s  . c  o  m
        Object toInsert = Utils.execute(uriResolver, node, variableContext, documentContext, statements);
        if (node instanceof Element) {
            Element parent = (Element) node;
            Dom4jUtils.clearElementContent(parent);
            Utils.insert(getLocationData(), parent, 0, toInsert);
        } else if (node instanceof Document) {
            Document parent = (Document) node;
            parent.clearContent();
            Utils.insert(getLocationData(), parent, 0, toInsert);
        } else if (node instanceof Attribute) {
            Attribute parent = (Attribute) node;
            parent.setValue("");
            Utils.insert(getLocationData(), parent, 0, toInsert);
        } else if (node instanceof org.dom4j.Text) {
            if (!(toInsert instanceof org.dom4j.Text))
                throw new ValidationException("A text node can only be updated with text", getLocationData());
            ((org.dom4j.Text) node).setText(((org.dom4j.Text) toInsert).getText());
        } else {
            throw new ValidationException("Cannot update a " + node.getClass().getName(), getLocationData());
        }
    }
    return Collections.EMPTY_LIST;
}

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

License:Open Source License

/**
 * Sets the if condition. The condition should be well formatted javascript.
 * //from w  w  w  . j a v a2  s  .co m
 * @param condition
 *          the condition.
 */
public void setCondition(String condition) {
    Element conditionElement = controlElement.element(ActionSequenceDocument.CONDITION_NAME);
    if (conditionElement == null) {
        conditionElement = controlElement.addElement(ActionSequenceDocument.CONDITION_NAME);
    }
    conditionElement.clearContent();
    conditionElement.addCDATA(condition);
    ActionSequenceDocument.fireControlStatementChanged(this);
}

From source file:org.pentaho.actionsequence.dom.actions.ActionDefinition.java

License:Open Source License

/**
 * Sets the value of the component definition element at the specified XPath.
 * // ww w. ja v a  2  s . com
 * @param compDefXpath
 *          the XPath of the element relative to the component definition element.
 * @param value
 *          the value to be assigned to the element
 * @param useCData
 *          whether a CDATA node should be used to save the value
 */
public void setComponentDefinition(String compDefXpath, String value, boolean useCData) {
    if (value == null) {
        Element[] componentDefs = getComponentDefElements(compDefXpath);
        for (int i = 0; i < componentDefs.length; i++) {
            componentDefs[i].detach();
        }
        if (componentDefs.length > 0) {
            ActionSequenceDocument.fireActionChanged(this);
        }
    } else {
        Element componentDef = getComponentDefElement(compDefXpath);
        if (componentDef == null) {
            componentDef = DocumentHelper.makeElement(actionDefElement,
                    ActionSequenceDocument.COMPONENT_DEF_NAME + "/" + compDefXpath); //$NON-NLS-1$
        }
        componentDef.clearContent();
        if (useCData) {
            componentDef.addCDATA(value);
        } else {
            componentDef.setText(value);
        }
        ActionSequenceDocument.fireActionChanged(this);
    }
}

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

License:Open Source License

public void setType(String ioType) {
    if ((ioType != null) && !ioType.equals(getType())) {
        ioElement.addAttribute(TYPE_NAME, ioType);
        Element defValElement = ioElement.element(ActionSequenceDocument.DEFAULT_VAL_NAME);
        if (defValElement != null) {
            defValElement.clearContent();
        }//from  w w  w .jav a2 s  .c o  m
        ActionSequenceDocument.fireIoChanged(this);
    }
}

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

License:Open Source License

/**
 * Sets the input default value.// www.ja v  a  2 s  . co  m
 * 
 * @param defValue
 *          the default value
 */
public void setDefaultValue(String defValue) {
    Element defValElement = ioElement.element(ActionSequenceDocument.DEFAULT_VAL_NAME);
    ioElement.elements(ActionSequenceDocument.RESULTSET_DEFAULT_COLUMNS).clear();
    if (defValue == null) {
        if (defValElement != null) {
            defValElement.detach();
            ActionSequenceDocument.fireIoChanged(this);
        }
    } else {
        if (defValElement == null) {
            defValElement = ioElement.addElement(ActionSequenceDocument.DEFAULT_VAL_NAME);
        } else {
            defValElement.clearContent();
        }
        defValElement.addAttribute(TYPE_NAME, null);
        if (defValue.length() > 0) {
            defValElement.addCDATA(defValue);
        }
        ActionSequenceDocument.fireIoChanged(this);
    }
}

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

License:Open Source License

/**
 * Sets the input default value./*  w w w. j a v  a 2 s  .c om*/
 * 
 * @param defValue
 *          the default value
 */
public void setDefaultValue(String[] defValue) {
    Element defValElement = ioElement.element(ActionSequenceDocument.DEFAULT_VAL_NAME);
    ioElement.elements(ActionSequenceDocument.RESULTSET_DEFAULT_COLUMNS).clear();
    if (defValue == null) {
        if (defValElement != null) {
            defValElement.detach();
            ActionSequenceDocument.fireIoChanged(this);
        }
    } else {
        if (defValElement == null) {
            defValElement = ioElement.addElement(ActionSequenceDocument.DEFAULT_VAL_NAME);
        } else {
            defValElement.clearContent();
        }
        if (defValue.length > 0) {
            defValElement.addAttribute(TYPE_NAME, ActionSequenceDocument.STRING_LIST_TYPE);
            for (int i = 0; i < defValue.length; i++) {
                defValElement.addElement(ActionSequenceDocument.DEFAULT_STRING_LIST_ITEM).setText(defValue[i]);
            }
        }
        ActionSequenceDocument.fireIoChanged(this);
    }
}

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

License:Open Source License

/**
 * Sets the input default value./*from   w w  w  . ja v a 2  s .co  m*/
 * 
 * @param paramMap
 *          the default value
 */
public void setDefaultValue(HashMap paramMap) {
    Element defValElement = ioElement.element(ActionSequenceDocument.DEFAULT_VAL_NAME);
    ioElement.elements(ActionSequenceDocument.RESULTSET_DEFAULT_COLUMNS).clear();
    if (paramMap == null) {
        if (defValElement != null) {
            defValElement.detach();
            ActionSequenceDocument.fireIoChanged(this);
        }
    } else {
        if (defValElement == null) {
            defValElement = ioElement.addElement(ActionSequenceDocument.DEFAULT_VAL_NAME);
        } else {
            defValElement.clearContent();
        }
        if (paramMap.size() > 0) {
            defValElement.addAttribute(TYPE_NAME, ActionSequenceDocument.PROPERTY_MAP_TYPE);

            DefaultTableModel defaultTableModel = new DefaultTableModel();
            for (Iterator keyIter = paramMap.keySet().iterator(); keyIter.hasNext();) {
                defaultTableModel.addColumn(keyIter.next().toString());
            }
            defaultTableModel.addRow((String[]) paramMap.values().toArray(new String[0]));
            initPropertyMap(defValElement, defaultTableModel);
        }
        ActionSequenceDocument.fireIoChanged(this);
    }
}

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

License:Open Source License

private void setPropMapListDefVal(TableModel defValue) {
    Element defValElement = ioElement.element(ActionSequenceDocument.DEFAULT_VAL_NAME);
    ioElement.elements(ActionSequenceDocument.RESULTSET_DEFAULT_COLUMNS).clear();
    if (defValue == null) {
        if (defValElement != null) {
            defValElement.detach();//  ww w .  j av  a2 s.  c o m
            ActionSequenceDocument.fireIoChanged(this);
        }
    } else {
        if (defValElement == null) {
            defValElement = ioElement.addElement(ActionSequenceDocument.DEFAULT_VAL_NAME);
        } else {
            defValElement.clearContent();
        }
        if (defValue.getColumnCount() > 0) {
            defValElement.addAttribute(TYPE_NAME, ActionSequenceDocument.PROPERTY_MAP_LIST_TYPE);
            initPropertyMap(defValElement, defValue);
        }
        ActionSequenceDocument.fireIoChanged(this);
    }
}

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

License:Open Source License

private void setResultSetDefVal(TableModel defValue) {
    Element defValElement = ioElement.element(ActionSequenceDocument.DEFAULT_VAL_NAME);
    ioElement.elements(ActionSequenceDocument.RESULTSET_DEFAULT_COLUMNS).clear();
    if (defValue == null) {
        if (defValElement != null) {
            defValElement.detach();//from ww  w  .j  a v a  2 s  . c o  m
            ActionSequenceDocument.fireIoChanged(this);
        }
    } else {
        if (defValElement == null) {
            defValElement = ioElement.addElement(ActionSequenceDocument.DEFAULT_VAL_NAME);
        } else {
            defValElement.clearContent();
        }
        if (defValue.getColumnCount() > 0) {
            defValElement.addAttribute(TYPE_NAME, ActionSequenceDocument.RESULTSET_TYPE);
            Element columnsElement = ioElement.addElement(ActionSequenceDocument.RESULTSET_DEFAULT_COLUMNS);
            for (int colIdx = 0; colIdx < defValue.getColumnCount(); colIdx++) {
                columnsElement.addElement(defValue.getColumnName(colIdx))
                        .addAttribute(ActionSequenceResource.TYPE_NAME, ActionSequenceDocument.STRING_TYPE);
            }
            for (int rowIdx = 0; rowIdx < defValue.getRowCount(); rowIdx++) {
                Element rowElement = defValElement.addElement(ActionSequenceDocument.RESULTSET_ROW);
                for (int colIdx = 0; colIdx < defValue.getColumnCount(); colIdx++) {
                    Object value = defValue.getValueAt(rowIdx, colIdx);
                    Element cellElement = rowElement.addElement(defValue.getColumnName(colIdx));
                    cellElement.setText(value == null ? "" : value.toString()); //$NON-NLS-1$
                }
            }
        }
        ActionSequenceDocument.fireIoChanged(this);
    }
}

From source file:org.pentaho.pac.server.config.HibernateConfigXml.java

License:Open Source License

private void setValue(String xPath, String value, boolean useCData) {
    Element element = (Element) document.selectSingleNode(xPath);
    if (element == null) {
        element = DocumentHelper.makeElement(document, xPath);
    }//from  w ww.  j  a v  a2 s.c  o m
    if (useCData) {
        element.clearContent();
        element.addCDATA(value);
    } else {
        element.setText(value);
    }
}