Search in sources :

Example 6 with Node

use of org.dom4j.Node in project tdi-studio-se by Talend.

the class DocumentExtractor method getSingleResult.

public String getSingleResult(String name) {
    final String finalName = replaceNamespace(name);
    XPath xpath = org.dom4j.DocumentHelper.createXPath(sb.append("/").append(finalFunction).append("/OUTPUT/").append(finalName).append("|").append("/").append(finalFunction).append("/CHANGING/").append(finalName).toString());
    sb.setLength(0);
    Node node = xpath.selectSingleNode(doc);
    if (node == null) {
        return null;
    }
    return node.getText();
}
Also used : XPath(org.dom4j.XPath) Node(org.dom4j.Node)

Example 7 with Node

use of org.dom4j.Node in project cubrid-manager by CUBRID.

the class Parser method loopSqlNode.

/**
	 * 멀티파일 include 처리위해 sql 엘리먼트 타입만 우선 파싱하여 SqlMapQuery 해쉬맵에 저장한다.
	 *
	 * @param document XML Document
	 * @param sqlMapFile SqlMapFile
	 * @throws Exception 예외
	 */
private void loopSqlNode(Document document, SqlMapFile sqlMapFile) throws Exception {
    String currentComment = "";
    SqlMapQueryParser queryParser = new SqlMapQueryParser();
    // rootElement 하위의 모든 Node를 읽어온다
    // Node 타입이 COMMENT, ELEMENT인 경우에 따라 정보 수집
    Iterator<?> nodeIterator = document.getRootElement().nodeIterator();
    while (nodeIterator.hasNext()) {
        Node node = (Node) nodeIterator.next();
        switch(node.getNodeType()) {
            case Node.COMMENT_NODE:
                currentComment = node.getText();
                break;
            case Node.ELEMENT_NODE:
                // 멀티파일 include 처리위해 sql 엘리먼트이면 SqlMapQuery 해쉬맵에 추가
                if ("sql".equals(node.getName())) {
                    //Element 타입의 node에서 Query 정보를 읽어 SqlMapQuery를 생성한다.
                    SqlMapQuery query = queryParser.parse((Element) node);
                    // ELEMENT_NODE 직전에 읽어들인 Comment를 본 쿼리의 comment로 간주하여 설정한다.
                    query.setComment(currentComment.replaceAll("\t", ""));
                    // SqlMapQuery 해쉬맵에 추가
                    if (refSqlHashMap != null && "sql".equals(query.getType())) {
                        refSqlHashMap.put(sqlMapFile.getNamespace() + "." + query.getId().replace(sqlMapFile.getNamespace() + ".", ""), query);
                    }
                }
                currentComment = "";
                break;
            default:
                currentComment = "";
                break;
        }
    }
}
Also used : Node(org.dom4j.Node) SqlMapQuery(com.nhn.dbtool.query.parser.sqlmap.model.SqlMapQuery)

Example 8 with Node

use of org.dom4j.Node in project cubrid-manager by CUBRID.

the class SqlMapConditionParser method parse.

/**
	 * Condition 단위의 Element를 통해 SqlMapCondition를 생성한다.
	 *
	 * @param conditionElement Condition 단위의 Element
	 * @param query
	 * @throws Exception
	 */
public SqlMapCondition parse(Element conditionElement, SqlMapQuery query) throws Exception {
    SqlMapConditionParser conditionParser = new SqlMapConditionParser();
    SqlMapParameterParser parameterParser = new SqlMapParameterParser();
    StringBuffer modifiedStatement = new StringBuffer();
    // 최상위 Element의 attribute로 Condition 생성
    SqlMapCondition condition = createSqlMapCondition(conditionElement);
    if (condition != null) {
        parameterParser.parse(conditionElement, query);
        // rootElement 하위의 모든 Node를 읽어온다
        // Node 타입이 TEXT, ELEMENT인 경우에 따라 정보 수집
        Iterator<?> nodeIterator = conditionElement.nodeIterator();
        while (nodeIterator.hasNext()) {
            Node node = (Node) nodeIterator.next();
            switch(node.getNodeType()) {
                case Node.TEXT_NODE:
                case Node.CDATA_SECTION_NODE:
                    // 변환된 statement 취합
                    modifiedStatement.append(node.getText());
                    // Parameter 파싱
                    parameterParser.parse(node, query);
                    break;
                case Node.ELEMENT_NODE:
                    // recursive
                    // 생성된 condition을 childConditionList에서 추가
                    SqlMapCondition childCondition = conditionParser.parse((Element) node, query);
                    if (childCondition != null) {
                        // MyBatis
                        initSqlMapCondition(node, childCondition);
                        condition.getChildConditionList().add(childCondition);
                        // 변환된 statement 취합
                        modifiedStatement.append(childCondition.getKey());
                    }
                    // Parameter 파싱
                    parameterParser.parse(node, query);
                    break;
                default:
                    break;
            }
        }
        // 변경된 statement 저장
        condition.setModifiedStatement(modifiedStatement.toString());
        // include 처리용 statement 저장
        Element copiedElement = conditionElement.createCopy();
        copiedElement.clearContent();
        copiedElement.setText(modifiedStatement.toString());
        condition.setIncludedStatement(copiedElement.asXML());
    }
    return condition;
}
Also used : Node(org.dom4j.Node) Element(org.dom4j.Element) SqlMapCondition(com.nhn.dbtool.query.parser.sqlmap.model.SqlMapCondition)

Example 9 with Node

use of org.dom4j.Node in project pentaho-kettle by pentaho.

the class GetXMLData method processPutRow.

private Object[] processPutRow(AbstractNode node) throws KettleException {
    // Create new row...
    Object[] outputRowData = buildEmptyRow();
    // Create new row or clone
    if (meta.isInFields()) {
        System.arraycopy(data.readrow, 0, outputRowData, 0, data.nrReadRow);
    }
    try {
        data.nodenr++;
        // Read fields...
        for (int i = 0; i < data.nrInputFields; i++) {
            // Get field
            GetXMLDataField xmlDataField = meta.getInputFields()[i];
            // Get the Path to look for
            String XPathValue = xmlDataField.getXPath();
            XPathValue = environmentSubstitute(XPathValue);
            if (xmlDataField.getElementType() == GetXMLDataField.ELEMENT_TYPE_ATTRIBUT) {
                // We have an attribute
                // do we need to add leading @?
                // Only put @ to the last element in path, not in front at all
                int last = XPathValue.lastIndexOf(GetXMLDataMeta.N0DE_SEPARATOR);
                if (last > -1) {
                    last++;
                    String attribut = XPathValue.substring(last, XPathValue.length());
                    if (!attribut.startsWith(GetXMLDataMeta.AT)) {
                        XPathValue = XPathValue.substring(0, last) + GetXMLDataMeta.AT + attribut;
                    }
                } else {
                    if (!XPathValue.startsWith(GetXMLDataMeta.AT)) {
                        XPathValue = GetXMLDataMeta.AT + XPathValue;
                    }
                }
            }
            if (meta.isuseToken()) {
                // See if user use Token inside path field
                // The syntax is : @_Fieldname-
                // PDI will search for Fieldname value and replace it
                // Fieldname must be defined before the current node
                XPathValue = substituteToken(XPathValue, outputRowData);
                if (isDetailed()) {
                    logDetailed(XPathValue);
                }
            }
            // Get node value
            String nodevalue;
            // Handle namespaces
            if (meta.isNamespaceAware()) {
                XPath xpathField = node.createXPath(addNSPrefix(XPathValue, data.PathValue));
                xpathField.setNamespaceURIs(data.NAMESPACE);
                if (xmlDataField.getResultType() == GetXMLDataField.RESULT_TYPE_VALUE_OF) {
                    nodevalue = xpathField.valueOf(node);
                } else {
                    // nodevalue=xpathField.selectSingleNode(node).asXML();
                    Node n = xpathField.selectSingleNode(node);
                    if (n != null) {
                        nodevalue = n.asXML();
                    } else {
                        nodevalue = "";
                    }
                }
            } else {
                if (xmlDataField.getResultType() == GetXMLDataField.RESULT_TYPE_VALUE_OF) {
                    nodevalue = node.valueOf(XPathValue);
                } else {
                    // nodevalue=node.selectSingleNode(XPathValue).asXML();
                    Node n = node.selectSingleNode(XPathValue);
                    if (n != null) {
                        nodevalue = n.asXML();
                    } else {
                        nodevalue = "";
                    }
                }
            }
            // Do trimming
            switch(xmlDataField.getTrimType()) {
                case GetXMLDataField.TYPE_TRIM_LEFT:
                    nodevalue = Const.ltrim(nodevalue);
                    break;
                case GetXMLDataField.TYPE_TRIM_RIGHT:
                    nodevalue = Const.rtrim(nodevalue);
                    break;
                case GetXMLDataField.TYPE_TRIM_BOTH:
                    nodevalue = Const.trim(nodevalue);
                    break;
                default:
                    break;
            }
            // Do conversions
            // 
            ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(data.totalpreviousfields + i);
            ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(data.totalpreviousfields + i);
            outputRowData[data.totalpreviousfields + i] = targetValueMeta.convertData(sourceValueMeta, nodevalue);
            // Do we need to repeat this field if it is null?
            if (meta.getInputFields()[i].isRepeated()) {
                if (data.previousRow != null && Utils.isEmpty(nodevalue)) {
                    outputRowData[data.totalpreviousfields + i] = data.previousRow[data.totalpreviousfields + i];
                }
            }
        }
        // End of loop over fields...
        int rowIndex = data.totalpreviousfields + data.nrInputFields;
        // See if we need to add the filename to the row...
        if (meta.includeFilename() && !Utils.isEmpty(meta.getFilenameField())) {
            outputRowData[rowIndex++] = data.filename;
        }
        // See if we need to add the row number to the row...
        if (meta.includeRowNumber() && !Utils.isEmpty(meta.getRowNumberField())) {
            outputRowData[rowIndex++] = data.rownr;
        }
        // Possibly add short filename...
        if (meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0) {
            outputRowData[rowIndex++] = data.shortFilename;
        }
        // Add Extension
        if (meta.getExtensionField() != null && meta.getExtensionField().length() > 0) {
            outputRowData[rowIndex++] = data.extension;
        }
        // add path
        if (meta.getPathField() != null && meta.getPathField().length() > 0) {
            outputRowData[rowIndex++] = data.path;
        }
        // Add Size
        if (meta.getSizeField() != null && meta.getSizeField().length() > 0) {
            outputRowData[rowIndex++] = data.size;
        }
        // add Hidden
        if (meta.isHiddenField() != null && meta.isHiddenField().length() > 0) {
            outputRowData[rowIndex++] = Boolean.valueOf(data.path);
        }
        // Add modification date
        if (meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0) {
            outputRowData[rowIndex++] = data.lastModificationDateTime;
        }
        // Add Uri
        if (meta.getUriField() != null && meta.getUriField().length() > 0) {
            outputRowData[rowIndex++] = data.uriName;
        }
        // Add RootUri
        if (meta.getRootUriField() != null && meta.getRootUriField().length() > 0) {
            outputRowData[rowIndex] = data.rootUriName;
        }
        RowMetaInterface irow = getInputRowMeta();
        if (irow == null) {
            data.previousRow = outputRowData;
        } else {
            // clone to previously allocated array to make sure next step doesn't
            // change it in between...
            System.arraycopy(outputRowData, 0, this.prevRow, 0, outputRowData.length);
            // Pick up everything else that needs a real deep clone
            data.previousRow = irow.cloneRow(outputRowData, this.prevRow);
        }
    } catch (Exception e) {
        if (getStepMeta().isDoingErrorHandling()) {
            // Simply add this row to the error row
            putError(data.outputRowMeta, outputRowData, 1, e.toString(), null, "GetXMLData001");
            data.errorInRowButContinue = true;
            return null;
        } else {
            logError(e.toString());
            throw new KettleException(e.toString());
        }
    }
    return outputRowData;
}
Also used : XPath(org.dom4j.XPath) KettleException(org.pentaho.di.core.exception.KettleException) Node(org.dom4j.Node) AbstractNode(org.dom4j.tree.AbstractNode) FileObject(org.apache.commons.vfs2.FileObject) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) KettleException(org.pentaho.di.core.exception.KettleException) FileSystemException(org.apache.commons.vfs2.FileSystemException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 10 with Node

use of org.dom4j.Node in project pentaho-platform by pentaho.

the class SystemSettings method getSystemSetting.

public String getSystemSetting(final String path, final String settingName, final String defaultValue) {
    // $NON-NLS-1$
    debug(Messages.getInstance().getString("SYSTEMSETTINGS.DEBUG_GET_SYSTEM_SETTING_PATH", File.separator + path));
    Document doc = getSystemSettingsDocument(path);
    if (doc == null) {
        return defaultValue;
    }
    // $NON-NLS-1$
    Node node = doc.selectSingleNode("//" + settingName);
    if (node == null) {
        return defaultValue;
    }
    return node.getText();
}
Also used : Node(org.dom4j.Node) Document(org.dom4j.Document)

Aggregations

Node (org.dom4j.Node)253 Document (org.dom4j.Document)83 Element (org.dom4j.Element)61 ArrayList (java.util.ArrayList)56 List (java.util.List)54 Test (org.junit.Test)40 SAXReader (org.dom4j.io.SAXReader)28 File (java.io.File)25 Iterator (java.util.Iterator)18 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)18 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)18 HashMap (java.util.HashMap)16 URL (java.net.URL)15 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)15 InputStream (java.io.InputStream)14 Attribute (org.dom4j.Attribute)14 Image (java.awt.Image)12 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)11 VFSItem (org.olat.core.util.vfs.VFSItem)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10