Example usage for org.w3c.dom Node getParentNode

List of usage examples for org.w3c.dom Node getParentNode

Introduction

In this page you can find the example usage for org.w3c.dom Node getParentNode.

Prototype

public Node getParentNode();

Source Link

Document

The parent of this node.

Usage

From source file:org.chiba.xml.xforms.XFormsElement.java

/**
 * determines the context path for given XFormsElement
 *
 * @param start the XFormsElement for which the parentContextPath will be calculated
 * @return the parent context path or null if no parent exists
 *//*from   ww w.j a v a 2s .  c o  m*/
protected String getParentContextPath(Node start) {
    String result = null;
    NodeImpl parent = (NodeImpl) start.getParentNode();
    if (parent == null)
        return null;

    Object o = parent.getUserData();
    if (o instanceof XFormsElement) {
        XFormsElement xCurrent = (XFormsElement) parent.getUserData();
        if (xCurrent == null) {
            getParentContextPath(parent);
        }

        if (xCurrent instanceof BindingElement) {
            if (((BindingElement) xCurrent).isBound()) {
                String locationPath = ((BindingElement) xCurrent).getLocationPath();
                return locationPath;
            } else {
                result = getParentContextPath(parent.getParentNode());
            }
        }
    } else {
        return getParentContextPath(parent);
    }
    return result;
}

From source file:org.commonjava.maven.ext.core.impl.XMLManipulator.java

void internalApplyChanges(Project project, XMLState.XMLOperation operation) throws ManipulationException {
    File target = new File(project.getPom().getParentFile(), operation.getFile());

    logger.info("Attempting to start XML update to file {} with xpath {} and replacement {}", target,
            operation.getXPath(), operation.getUpdate());

    Document doc = xmlIO.parseXML(target);

    try {//from w ww .  ja  v a2  s .c  o  m
        NodeList nodeList = (NodeList) xPath.evaluate(operation.getXPath(), doc, XPathConstants.NODESET);

        if (nodeList.getLength() == 0) {
            if (project.isIncrementalPME()) {
                logger.warn("Did not locate XML using XPath " + operation.getXPath());
                return;
            } else {
                logger.error("XPath {} did not find any expressions within {} ", operation.getXPath(),
                        operation.getFile());
                throw new ManipulationException("Did not locate XML using XPath " + operation.getXPath());
            }
        }

        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);

            if (isEmpty(operation.getUpdate())) {
                // Delete
                node.getParentNode().removeChild(node);
            } else {
                // Update
                node.setTextContent(operation.getUpdate());
            }
        }

        xmlIO.writeXML(target, doc);
    } catch (XPathExpressionException e) {
        logger.error("Caught XML exception processing file {}, document context {} ", target, doc, e);
        throw new ManipulationException("Caught XML exception processing file", e);
    }
}

From source file:org.commonjava.maven.ext.io.XMLIOTest.java

@Test
public void removePartFile() throws ManipulationException, IOException, XPathExpressionException {
    String tomcatPath = "//include[starts-with(.,'org.apache.tomcat')]";

    Document doc = xmlIO.parseXML(xmlFile);

    XPath xPath = XPathFactory.newInstance().newXPath();
    NodeList nodeList = (NodeList) xPath.evaluate(tomcatPath, doc, XPathConstants.NODESET);
    logger.debug("Found node {} with size {} ", nodeList, nodeList.getLength());

    assertTrue(nodeList.getLength() == 1);

    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);

        logger.debug("Found node {} with type {} and value {}", node.getNodeName(), node.getNodeType(),
                node.getTextContent());//  w w  w. j  a  v  a 2  s.c o m
        node.getParentNode().removeChild(node);
    }

    File target = tf.newFile();
    xmlIO.writeXML(target, doc);

    Diff diff = DiffBuilder.compare(fromFile(xmlFile)).withTest(Input.fromFile(target)).build();
    assertTrue(diff.toString(), diff.hasDifferences());

    String xpathForHamcrest = "/*/*/*/*/*[starts-with(.,'org.apache.tomcat') and local-name() = 'include']";
    Iterable<Node> i = new JAXPXPathEngine().selectNodes(xpathForHamcrest, Input.fromFile(target).build());
    int count = 0;
    for (Node ignored : i) {
        count++;
    }
    assertEquals(0, count);
}

From source file:org.commonjava.maven.galley.maven.model.view.JXPathContextAncestryTest.java

@Test
@Ignore/*w w w .j  a va 2  s .c om*/
public void basicJXPathTest() throws Exception {
    final InputStream is = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream("jxpath/simple.pom.xml");

    final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);

    final JXPathContext ctx = JXPathContext.newContext(document);

    document.getDocumentElement().removeAttribute("xmlns");

    final String projectGroupIdPath = "ancestor::project/groupId";

    // NOT what's failing...just populating the node set to traverse in order to feed the ancestor:: axis test.
    final List<?> nodes = ctx.selectNodes("/project/dependencies/dependency");
    for (final Object object : nodes) {
        final Node node = (Node) object;
        dump(node);

        final Stack<Node> revPath = new Stack<Node>();

        Node parent = node;
        while (parent != null) {
            revPath.push(parent);
            parent = parent.getParentNode();
        }

        JXPathContext nodeCtx = null;
        while (!revPath.isEmpty()) {
            final Node part = revPath.pop();
            if (nodeCtx == null) {
                nodeCtx = JXPathContext.newContext(part);
            } else {
                nodeCtx = JXPathContext.newContext(nodeCtx, part);
            }
        }

        System.out
                .println("Path derived from context: '" + nodeCtx.getNamespaceContextPointer().asPath() + "'");

        // brute-force approach...try to force population of the parent pointers by painstakingly constructing contexts for all intermediate nodes.
        System.out.println("Selecting groupId for declaring project using path-derived context...");
        System.out.println(nodeCtx.getValue(projectGroupIdPath));

        // Naive approach...this has all the context info it needs to get parent contexts up to and including the document!
        System.out.println("Selecting groupId for declaring project using non-derived context...");
        System.out.println(JXPathContext.newContext(node).getValue(projectGroupIdPath));
    }
}

From source file:org.commonjava.maven.galley.maven.model.view.MavenPomView.java

/**
 * Find the id of the profile that contains the given element, if there is one. Otherwise, return null.
 *//*from   w  ww. j a v  a2  s. c  o  m*/
public String getProfileIdFor(final Element element) {
    Node parent = element;
    do {
        parent = parent.getParentNode();
    } while (parent != null && !"profile".equals(parent.getNodeName()));

    if (parent == null) {
        return null;
    }

    return (String) JXPathUtils.newContext(parent).getValue("id");
}

From source file:org.corpus_tools.pepper.cli.PepperStarter.java

/**
 * This method writes a module configuration of GroupId, ArtifactId and
 * Maven repository back to the modules.xml file
 *//* ww  w.  j  a va 2  s  . com*/
private boolean write2ConfigFile(String groupId, String artifactId, String repository) {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    try {
        boolean changes = false;
        File configFile = new File(MODULES_XML_PATH);
        DocumentBuilder docBuilder = dbFactory.newDocumentBuilder();
        Document doc = docBuilder.parse(configFile);
        NodeList configuredModules = doc.getElementsByTagName(ModuleTableReader.TAG_ARTIFACTID);
        if (configuredModules.getLength() == 0) {
            return false;
        }
        /* check, if the module is already in the modules.xml file */
        Node item = configuredModules.item(0);
        int j = 0;
        while (j + 1 < configuredModules.getLength() && !artifactId.equals(item.getTextContent())) {
            item = configuredModules.item(++j);
        }
        if (artifactId.equals(item.getTextContent())) {// already contained
            // -> edit
            Node itemGroupId = null;
            Node itemRepo = null;
            Node node = null;
            for (int i = 0; i < item.getParentNode().getChildNodes().getLength()
                    && (itemGroupId == null || itemRepo == null); i++) {
                node = item.getParentNode().getChildNodes().item(i);
                if (ModuleTableReader.TAG_GROUPID.equals(node.getLocalName())) {
                    itemGroupId = node;
                }
                if (ModuleTableReader.TAG_REPO.equals(node.getLocalName())) {
                    itemRepo = node;
                }
            }
            if (itemGroupId != null) {
                itemGroupId.setTextContent(groupId);
                changes = true;
            } else {
                if (!groupId.equals(doc.getElementsByTagName(ModuleTableReader.ATT_DEFAULTGROUPID).item(0)
                        .getTextContent())) {
                    itemGroupId = doc.createElement(ModuleTableReader.TAG_GROUPID);
                    itemGroupId.setTextContent(groupId);
                    item.getParentNode().appendChild(itemGroupId);
                    changes = true;
                }
            }
            if (itemRepo != null) {
                itemRepo.setTextContent(repository);
                changes = true;
            } else {
                // if
                // (!repository.equals(doc.getElementsByTagName(ModuleTableReader.ATT_DEFAULTREPO).item(0).getTextContent()))
                // {
                // itemRepo = doc.createElement(ModuleTableReader.TAG_REPO);
                // itemRepo.setTextContent(repository);
                // item.getParentNode().appendChild(itemRepo);
                // changes = true;
                // }
            }
            itemGroupId = null;
            itemRepo = null;
            node = null;
        } else {// not contained yet -> insert
            changes = true;
            Node listNode = doc.getElementsByTagName(ModuleTableReader.TAG_LIST).item(0);
            Node newModule = doc.createElement(ModuleTableReader.TAG_ITEM);
            Node groupIdNode = doc.createElement(ModuleTableReader.TAG_GROUPID);
            groupIdNode.appendChild(doc.createTextNode(groupId));
            Node artifactIdNode = doc.createElement(ModuleTableReader.TAG_ARTIFACTID);
            artifactIdNode.appendChild(doc.createTextNode(artifactId));
            Node repositoryNode = doc.createElement(ModuleTableReader.TAG_REPO);
            repositoryNode.appendChild(doc.createTextNode(repository));
            newModule.appendChild(groupIdNode);
            newModule.appendChild(artifactIdNode);
            newModule.appendChild(repositoryNode);
            listNode.appendChild(newModule);

            listNode = null;
            newModule = null;
            groupIdNode = null;
            artifactIdNode = null;
            repository = null;
        }

        if (changes) {
            // write back to file
            TransformerFactory trFactory = TransformerFactory.newInstance();
            // trFactory.setAttribute("indent-number", 2);
            Transformer transformer = trFactory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            DOMSource src = new DOMSource(doc);
            StreamResult result = new StreamResult(configFile);
            transformer.transform(src, result);

            trFactory = null;
            transformer = null;
            src = null;
            result = null;
        }

        docBuilder = null;
        doc = null;
        configuredModules = null;
        item = null;

    } catch (ParserConfigurationException | SAXException | IOException | FactoryConfigurationError
            | TransformerFactoryConfigurationError | TransformerException e) {
        logger.error("Could not read module table.");
        logger.trace(" ", e);
        return false;
    }
    return true;
}

From source file:org.cruxframework.crux.core.declarativeui.ViewParser.java

/**
 * Check if the target node is child from a rootDocument element or from a native XHTML element.
 * //from w  w  w  .  ja  v  a2s .c  om
 * @param node
 * @return
 */
private boolean isHTMLChild(Node node) {
    Node parentNode = node.getParentNode();
    String namespaceURI = parentNode.getNamespaceURI();
    if (namespaceURI == null) {
        log.warn("The view [" + this.viewId
                + "] contains elements that is not bound to any namespace. It can cause errors while translating to an HTML page.");
    }
    if (node.getOwnerDocument().getDocumentElement().equals(parentNode)) {
        return true;
    }
    if (namespaceURI != null && namespaceURI.equals(XHTML_NAMESPACE) || isHtmlContainerWidget(parentNode)) {
        return true;
    }
    if (parentNode instanceof Element && namespaceURI != null && namespaceURI.equals(CRUX_CORE_NAMESPACE)
            && parentNode.getLocalName().equals(CRUX_CORE_SCREEN)) {
        return isHTMLChild(parentNode);
    }

    return false;
}

From source file:org.culturegraph.mf.morph.MorphVisualizer.java

private void exit(final Node node) {
    String name = resolvedAttribute(node, ATTRITBUTE.NAME);
    if (name == null) {
        name = "";
    }// w  w w  . j a va  2  s  . c  om

    final String lastProcessor = lastProcessorStack.pop();
    if (idStack.isEmpty()) {
        if (name.startsWith(RECURSION_INDICATOR)) {
            addEdge(lastProcessor, name);
            sources.add(name);
        } else {
            addEdge(lastProcessor, newOutNode(), name);
        }
    } else {
        if (ORDERED_COLLECTS.contains(node.getParentNode().getLocalName())) {
            addEdge(lastProcessor, idStack.peek(), name + "(" + childCountStack.peek() + ")");
        } else {
            addEdge(lastProcessor, idStack.peek(), name);
        }
    }

}

From source file:org.devgateway.eudevfin.reports.core.utils.ReportTemplate.java

private void appendReportSumRows(HashMap<String, Node> matchingRows, HashMap<String, Node> matchingColumns,
        RowReport row, Document doc, boolean swapAxis) {
    Node rowNode = matchingRows.get("r_" + row.getName());

    if (rowNode == null)
        return;//from   ww  w  . j  a  v  a 2s.  c o  m
    HashMap<String, String> columns = new HashMap<String, String>();
    HashMap<String, String> emptyColumns = new HashMap<String, String>();

    XPath xPath = XPathFactory.newInstance().newXPath();

    for (String rowCode : row.getRowCodes()) {
        try {
            NodeList nodes = (NodeList) xPath
                    .evaluate("/jasperReport/detail/band/textField/reportElement[starts-with(@key, 'r_"
                            + rowCode + "_c_')]", doc.getDocumentElement(), XPathConstants.NODESET);
            for (int i = 0; i < nodes.getLength(); ++i) {
                Element e = (Element) nodes.item(i);
                String columnKey = e.getAttribute("key");
                String columnCode = columnKey.replaceFirst("r_" + rowCode + "_c_", "");
                String expression = columns.get(columnCode) != null ? columns.get(columnCode) : "";
                if (!e.getParentNode().getTextContent().equals("")) {
                    expression += e.getParentNode().getTextContent();
                    expression += "+";
                }
                columns.put(columnCode, expression);
            }
            NodeList nodesEmpty = (NodeList) xPath
                    .evaluate("/jasperReport/detail/band/staticText/reportElement[starts-with(@key, 'r_"
                            + rowCode + "_c_')]", doc.getDocumentElement(), XPathConstants.NODESET);
            for (int i = 0; i < nodesEmpty.getLength(); ++i) {
                Element e = (Element) nodesEmpty.item(i);
                String columnKey = e.getAttribute("key");
                String columnCode = columnKey.replaceFirst("r_" + rowCode + "_c_", "");
                String expression = columns.get(columnCode) != null ? columns.get(columnCode) : "";
                if (!e.getParentNode().getTextContent().equals("")) {
                    expression += e.getParentNode().getTextContent();
                    expression += "+";
                }
                emptyColumns.put(columnCode, expression);
            }
        } catch (XPathExpressionException e) {
            e.printStackTrace();
        }
    }

    Integer yCoord, xCoord, width, height;
    xCoord = yCoord = 0;
    //Set default height
    height = 15;
    //Set default width
    width = 55;
    if (swapAxis) {
        xCoord = rowNode.getAttributes().getNamedItem("x") != null
                ? Integer.parseInt(rowNode.getAttributes().getNamedItem("x").getNodeValue())
                : 0;
    } else {
        yCoord = rowNode.getAttributes().getNamedItem("y") != null
                ? Integer.parseInt(rowNode.getAttributes().getNamedItem("y").getNodeValue())
                : 0;
    }

    for (Map.Entry<String, String> column : columns.entrySet()) {
        String cellStyle = (rowNode.getAttributes().getNamedItem("style") != null)
                ? rowNode.getAttributes().getNamedItem("style").getNodeValue()
                : "";
        Element textField = doc.createElement("textField");
        textField.setAttribute("pattern", "#,##0.00");
        Node columnNode = matchingColumns.get("c_" + column.getKey());
        if (columnNode == null)
            continue;
        Node parentNode;
        if (swapAxis) {
            parentNode = columnNode.getParentNode().getParentNode();
            yCoord = columnNode.getAttributes().getNamedItem("y") != null
                    ? Integer.parseInt(columnNode.getAttributes().getNamedItem("y").getNodeValue())
                    : 0;
        } else {
            parentNode = rowNode.getParentNode().getParentNode();
            xCoord = columnNode.getAttributes().getNamedItem("x") != null
                    ? Integer.parseInt(columnNode.getAttributes().getNamedItem("x").getNodeValue())
                    : 0;
            width = columnNode.getAttributes().getNamedItem("width") != null
                    ? Integer.parseInt(columnNode.getAttributes().getNamedItem("width").getNodeValue())
                    : 0;
            height = rowNode.getAttributes().getNamedItem("height") != null
                    ? Integer.parseInt(rowNode.getAttributes().getNamedItem("height").getNodeValue())
                    : 0;
            if (cellStyle.equals("") && (columnNode.getAttributes().getNamedItem("style") != null)) {
                cellStyle = columnNode.getAttributes().getNamedItem("style").getNodeValue();
            }

        }
        Element reportElement = doc.createElement("reportElement");
        reportElement.setAttribute("key", "r_" + row.getName() + "_c_" + column.getKey());
        reportElement.setAttribute("x", xCoord.toString());
        reportElement.setAttribute("y", yCoord.toString());
        reportElement.setAttribute("width", width.toString());
        reportElement.setAttribute("height", height.toString());

        if (!cellStyle.equals("")) {
            reportElement.setAttribute("style", cellStyle);
        }

        Element textElement = doc.createElement("textElement");
        textElement.setAttribute("textAlignment", "Right");

        Element textFieldExpression = doc.createElement("textFieldExpression");
        String columnValue = column.getValue();
        if (columnValue.endsWith("+")) {
            columnValue = columnValue.substring(0, columnValue.length() - 1);
        }
        CDATASection cdata = doc.createCDATASection(columnValue);

        textFieldExpression.appendChild(cdata);
        textField.appendChild(reportElement);
        textField.appendChild(textElement);
        textField.appendChild(textFieldExpression);
        parentNode.appendChild(textField);

    }

    for (Map.Entry<String, String> column : emptyColumns.entrySet()) {
        if (columns.containsKey(column.getKey())) {
            continue;
        }
        String cellStyle = (rowNode.getAttributes().getNamedItem("style") != null)
                ? rowNode.getAttributes().getNamedItem("style").getNodeValue()
                : "";
        Element staticText = doc.createElement("staticText");
        Node columnNode = matchingColumns.get("c_" + column.getKey());
        if (columnNode == null)
            continue;
        Node parentNode;
        if (swapAxis) {
            parentNode = columnNode.getParentNode().getParentNode();
            yCoord = columnNode.getAttributes().getNamedItem("y") != null
                    ? Integer.parseInt(columnNode.getAttributes().getNamedItem("y").getNodeValue())
                    : 0;
        } else {
            parentNode = rowNode.getParentNode().getParentNode();
            xCoord = columnNode.getAttributes().getNamedItem("x") != null
                    ? Integer.parseInt(columnNode.getAttributes().getNamedItem("x").getNodeValue())
                    : 0;
            width = columnNode.getAttributes().getNamedItem("width") != null
                    ? Integer.parseInt(columnNode.getAttributes().getNamedItem("width").getNodeValue())
                    : 0;
            height = rowNode.getAttributes().getNamedItem("height") != null
                    ? Integer.parseInt(rowNode.getAttributes().getNamedItem("height").getNodeValue())
                    : 0;
            if (cellStyle.equals("") && (columnNode.getAttributes().getNamedItem("style") != null)) {
                cellStyle = columnNode.getAttributes().getNamedItem("style").getNodeValue();
            }

        }
        Element reportElement = doc.createElement("reportElement");
        reportElement.setAttribute("key", "r_" + row.getName() + "_c_" + column.getKey());
        reportElement.setAttribute("x", xCoord.toString());
        reportElement.setAttribute("y", yCoord.toString());
        reportElement.setAttribute("width", width.toString());
        reportElement.setAttribute("height", height.toString());

        if (!cellStyle.equals("")) {
            reportElement.setAttribute("style", cellStyle);
        }

        Element textElement = doc.createElement("textElement");
        textElement.setAttribute("textAlignment", "Right");

        Element textFieldExpression = doc.createElement("text");
        CDATASection cdata = doc.createCDATASection("////////");

        textFieldExpression.appendChild(cdata);
        staticText.appendChild(reportElement);
        staticText.appendChild(textElement);
        staticText.appendChild(textFieldExpression);
        parentNode.appendChild(staticText);

    }
}

From source file:org.devgateway.eudevfin.reports.core.utils.ReportTemplate.java

private void appendReportRows(HashMap<String, Node> matchingRows, HashMap<String, Node> matchingColumns,
        RowReport row, Document doc, boolean swapAxis) {
    Node rowNode = matchingRows.get("r_" + row.getName());
    if (rowNode == null)
        return;/* w w  w. j  a va2 s .  c o  m*/
    Integer rowMultiplier = 1;
    //TODO: Remove this terrible hack for the two columns of DAC2a that needs to subtract
    if (row.getName().equals("205") || row.getName().startsWith("205_") || row.getName().equals("215")
            || row.getName().startsWith("215_") || row.getName().equals("219")
            || row.getName().startsWith("219_")) {
        rowMultiplier = -1;
    }
    Integer yCoord, xCoord, width, height;
    xCoord = yCoord = 0;
    //Set default height
    height = 15;
    //Set default width
    width = 55;
    if (swapAxis) {
        xCoord = rowNode.getAttributes().getNamedItem("x") != null
                ? Integer.parseInt(rowNode.getAttributes().getNamedItem("x").getNodeValue())
                : 0;
    } else {
        yCoord = rowNode.getAttributes().getNamedItem("y") != null
                ? Integer.parseInt(rowNode.getAttributes().getNamedItem("y").getNodeValue())
                : 0;
    }

    Set<ColumnReport> columns = row.getColumns();
    //Store multipliers for later use
    HashMap<String, Integer> multipliersByColumn = new HashMap<String, Integer>();
    for (ColumnReport column : columns) {
        multipliersByColumn.put(column.getName(), column.getMultiplier());
    }
    for (ColumnReport column : columns) {
        //         UUID uuid = UUID.randomUUID();
        String cellStyle = (rowNode.getAttributes().getNamedItem("style") != null)
                ? rowNode.getAttributes().getNamedItem("style").getNodeValue()
                : "";

        Node columnNode = matchingColumns.get("c_" + column.getName());
        if (columnNode == null)
            continue;
        Node parentNode;
        if (swapAxis) {
            parentNode = columnNode.getParentNode().getParentNode();
            yCoord = columnNode.getAttributes().getNamedItem("y") != null
                    ? Integer.parseInt(columnNode.getAttributes().getNamedItem("y").getNodeValue())
                    : 0;
        } else {
            parentNode = rowNode.getParentNode().getParentNode();
            xCoord = columnNode.getAttributes().getNamedItem("x") != null
                    ? Integer.parseInt(columnNode.getAttributes().getNamedItem("x").getNodeValue())
                    : 0;
            width = columnNode.getAttributes().getNamedItem("width") != null
                    ? Integer.parseInt(columnNode.getAttributes().getNamedItem("width").getNodeValue())
                    : 0;
            height = rowNode.getAttributes().getNamedItem("height") != null
                    ? Integer.parseInt(rowNode.getAttributes().getNamedItem("height").getNodeValue())
                    : 0;
            if (cellStyle.equals("") && (columnNode.getAttributes().getNamedItem("style") != null)) {
                cellStyle = columnNode.getAttributes().getNamedItem("style").getNodeValue();
            }
        }

        Element textField = doc.createElement("textField");
        textField.setAttribute("pattern", column.getPattern() != null ? column.getPattern() : "#,##0.00");

        Element reportElement = doc.createElement("reportElement");
        reportElement.setAttribute("key", "r_" + row.getName() + "_c_" + column.getName());
        reportElement.setAttribute("x", xCoord.toString());
        reportElement.setAttribute("y", yCoord.toString());
        reportElement.setAttribute("width", width.toString());
        if (row.getVisible() != null && !row.getVisible()) {
            reportElement.setAttribute("height", "0");
        } else {
            reportElement.setAttribute("height", height.toString());
        }
        if (!cellStyle.equals("")) {
            reportElement.setAttribute("style", cellStyle);
        }

        Element textElement = doc.createElement("textElement");
        textElement.setAttribute("textAlignment", "Right");

        Element textFieldExpression = doc.createElement("textFieldExpression");

        if (column.getType() == Constants.CALCULATED) {
            StringBuffer expression = new StringBuffer();
            if (column.getSlicer().equals("All")) {
                String fieldName = row.getName() + "_" + column.getName() + "_All_" + column.getMeasure();
                expression.append("checkNull($F{" + fieldName + "}).doubleValue()");
            } else {
                String[] types = column.getSlicer().split(",");
                for (int i = 0; i < types.length; i++) {
                    if (!types[i].equals("")) {
                        String fieldName = row.getName() + "_" + column.getName() + "_" + shortenType(types[i])
                                + "_" + column.getMeasure();
                        if (nonFlowItems.contains(column.getSlicer())) {
                            expression.append("$F{" + fieldName + "}");
                        } else {
                            expression.append("checkNull($F{" + fieldName + "}).doubleValue()");
                        }
                        if (i != types.length - 1) {
                            expression.append("+");
                        }
                    }
                }
            }
            String finalExpression = "";

            Integer multiplier = rowMultiplier * column.getMultiplier();
            if (expression.length() > 0) {
                finalExpression = "checkZero((" + expression.toString() + "), " + multiplier
                        + ").doubleValue()";
            }

            CDATASection cdata = doc.createCDATASection(finalExpression);
            textFieldExpression.appendChild(cdata);
        } else if (column.getType() == Constants.SUM) {
            StringBuffer expression = new StringBuffer();
            Set<String> subcols = column.getColumnCodes();
            for (Iterator<String> it = subcols.iterator(); it.hasNext();) {
                String code = it.next();
                String[] types = code.split(",");
                for (int i = 0; i < types.length; i++) {
                    String fieldName = row.getName() + "_" + types[i];
                    expression.append("(");
                    expression.append("checkNull($F{" + fieldName + "}).doubleValue()");
                    String extractedColumnName = types[i].split("_")[0];
                    Integer multiplier = multipliersByColumn.get(extractedColumnName);
                    if (multiplier == null) {
                        multiplier = 1;
                    }
                    if (multiplier != null && multiplier < 0) {
                        expression.append("* (" + multiplier + ")");
                    }
                    expression.append(")");
                    if (i != types.length - 1) {
                        expression.append("+");
                    }
                }
                if (it.hasNext()) {
                    expression.append("+");
                }
            }
            String finalExpression = "";
            if (expression.length() > 0)
                finalExpression = "checkZero((" + expression.toString() + "), " + rowMultiplier
                        + ").doubleValue()";

            CDATASection cdata = doc.createCDATASection(finalExpression);
            textFieldExpression.appendChild(cdata);
        } else {
            textField = doc.createElement("staticText");
            textFieldExpression = doc.createElement("text");
            CDATASection cdata = doc.createCDATASection("////////");
            textFieldExpression.appendChild(cdata);
        }

        textField.appendChild(reportElement);
        textField.appendChild(textElement);
        textField.appendChild(textFieldExpression);
        parentNode.appendChild(textField);
    }

}