Example usage for org.dom4j Node getName

List of usage examples for org.dom4j Node getName

Introduction

In this page you can find the example usage for org.dom4j Node getName.

Prototype

String getName();

Source Link

Document

getName returns the name of this node.

Usage

From source file:org.pentaho.di.ui.trans.steps.getxmldata.GetXMLDataDialog.java

License:Open Source License

private void addLoopXPath(Node node) {
    Element ce = (Element) node;

    // List child 
    for (int j = 0; j < ce.nodeCount(); j++) {
        Node cnode = ce.node(j);

        if (!Const.isEmpty(cnode.getName())) {
            Element cce = (Element) cnode;
            if (!listpath.contains(cnode.getPath()))
                listpath.add(cnode.getPath());
            // let's get child nodes
            if (cce.nodeCount() > 1)
                addLoopXPath(cnode);/*w  w w  .  jav a  2  s  .  com*/
        }
    }
}

From source file:org.pentaho.di.ui.trans.steps.getxmldata.GetXMLDataDialog.java

License:Open Source License

@SuppressWarnings("unchecked")
private void setNodeField(Node node, String realXPathCleaned) {
    Element e = (Element) node;
    // get all attributes
    List<Attribute> lista = e.attributes();
    for (int i = 0; i < lista.size(); i++) {
        setAttributeField(lista.get(i), realXPathCleaned);
    }/*from  w  w w. j a v  a2s.  c o  m*/

    // Get Node Name
    String nodename = node.getName();
    String nodenametxt = cleanString(node.getPath(), realXPathCleaned);

    if (!Const.isEmpty(nodenametxt) && !list.contains(nodenametxt)) {
        TableItem item = new TableItem(wFields.table, SWT.NONE);
        item.setText(1, nodename);
        item.setText(2, nodenametxt);
        item.setText(3, GetXMLDataField.ElementTypeDesc[0]);

        // Get Node value
        String valueNode = node.getText();

        // Try to get the Type
        if (IsDate(valueNode)) {
            item.setText(4, "Date");
            item.setText(5, "yyyy/MM/dd");
        } else if (IsInteger(valueNode))
            item.setText(4, "Integer");
        else if (IsNumber(valueNode))
            item.setText(4, "Number");
        else
            item.setText(4, "String");

        list.add(nodenametxt);

    } // end if
}

From source file:org.pentaho.di.ui.trans.steps.getxmldata.LoopNodesImportProgressDialog.java

License:Apache License

private void addLoopXPath(Node node, IProgressMonitor monitor) {
    Element ce = (Element) node;
    monitor.worked(1);//from  w w  w.  j a v  a2 s  .c om
    // List child
    for (int j = 0; j < ce.nodeCount(); j++) {
        if (monitor.isCanceled()) {
            return;
        }
        Node cnode = ce.node(j);

        if (!Utils.isEmpty(cnode.getName())) {
            Element cce = (Element) cnode;
            if (!listpath.contains(cnode.getPath())) {
                nr++;
                monitor.subTask(BaseMessages.getString(PKG,
                        "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes", String.valueOf(nr)));
                monitor.subTask(BaseMessages.getString(PKG,
                        "GetXMLDateLoopNodesImportProgressDialog.Task.AddingNode", cnode.getPath()));
                listpath.add(cnode.getPath());
            }
            // let's get child nodes
            if (cce.nodeCount() > 1) {
                addLoopXPath(cnode, monitor);
            }
        }
    }
}

From source file:org.pentaho.di.ui.trans.steps.getxmldata.XMLInputFieldsImportProgressDialog.java

License:Apache License

@SuppressWarnings("unchecked")
private void setNodeField(Node node, IProgressMonitor monitor) {
    Element e = (Element) node;
    // get all attributes
    List<Attribute> lista = e.attributes();
    for (int i = 0; i < lista.size(); i++) {
        setAttributeField(lista.get(i), monitor);
    }/*www.ja  va2s  .  c  om*/

    // Get Node Name
    String nodename = node.getName();
    String nodenametxt = cleanString(node.getPath());

    if (!Utils.isEmpty(nodenametxt) && !list.contains(nodenametxt)) {
        nr++;
        monitor.subTask(BaseMessages.getString(PKG,
                "GetXMLDataXMLInputFieldsImportProgressDialog.Task.FetchFields", String.valueOf(nr)));
        monitor.subTask(BaseMessages.getString(PKG,
                "GetXMLDataXMLInputFieldsImportProgressDialog.Task.AddingField", nodename));

        RowMetaAndData row = new RowMetaAndData();
        row.addValue(VALUE_NAME, Value.VALUE_TYPE_STRING, nodename);
        row.addValue(VALUE_PATH, Value.VALUE_TYPE_STRING, nodenametxt);
        row.addValue(VALUE_ELEMENT, Value.VALUE_TYPE_STRING, GetXMLDataField.ElementTypeDesc[0]);
        row.addValue(VALUE_RESULT, Value.VALUE_TYPE_STRING, GetXMLDataField.ResultTypeDesc[0]);

        // Get Node value
        String valueNode = node.getText();

        // Try to get the Type

        if (IsDate(valueNode)) {
            row.addValue(VALUE_TYPE, Value.VALUE_TYPE_STRING, "Date");
            row.addValue(VALUE_FORMAT, Value.VALUE_TYPE_STRING, "yyyy/MM/dd");
        } else if (IsInteger(valueNode)) {
            row.addValue(VALUE_TYPE, Value.VALUE_TYPE_STRING, "Integer");
            row.addValue(VALUE_FORMAT, Value.VALUE_TYPE_STRING, null);
        } else if (IsNumber(valueNode)) {
            row.addValue(VALUE_TYPE, Value.VALUE_TYPE_STRING, "Number");
            row.addValue(VALUE_FORMAT, Value.VALUE_TYPE_STRING, null);
        } else {
            row.addValue(VALUE_TYPE, Value.VALUE_TYPE_STRING, "String");
            row.addValue(VALUE_FORMAT, Value.VALUE_TYPE_STRING, null);
        }
        fieldsList.add(row);
        list.add(nodenametxt);

    } // end if
}

From source file:org.pentaho.di.ui.trans.steps.getxmldata.XMLInputFieldsImportProgressDialog.java

License:Apache License

private boolean childNode(Node node, IProgressMonitor monitor) {
    boolean rc = false; // true: we found child nodes
    Element ce = (Element) node;
    // List child
    for (int j = 0; j < ce.nodeCount(); j++) {
        Node cnode = ce.node(j);
        if (!Utils.isEmpty(cnode.getName())) {
            Element cce = (Element) cnode;
            if (cce.nodeCount() > 1) {
                if (childNode(cnode, monitor) == false) {
                    // We do not have child nodes ...
                    setNodeField(cnode, monitor);
                    rc = true;//from  w w  w.j a  va2  s  . com
                }
            } else {
                setNodeField(cnode, monitor);
                rc = true;
            }
        }
    }
    return rc;
}

From source file:org.pentaho.jpivot.AnalysisSaver.java

License:Open Source License

/**
 * @param componentDefinition//from  w w  w.j a  va 2s . co m
 * @param props
 */
private static void updateComponent(final Element componentDefinition, final HashMap props) {
    Iterator iter = props.keySet().iterator();

    while (iter.hasNext()) {
        Object key = iter.next();
        Node node = componentDefinition.selectSingleNode(key.toString());
        if (node == null) {
            node = componentDefinition.addElement(key.toString());
        }
        if (PivotViewComponent.OPTIONS.equals(node.getName())) {
            List optionsList = (List) props.get(key);
            Iterator optsIter = optionsList.iterator();
            while (optsIter.hasNext()) {
                String anOption = optsIter.next().toString();
                Node anOptionNode = node.selectSingleNode(anOption);
                if (anOptionNode == null) {
                    ((Element) node).addElement(anOption);
                }
            }
        } else {
            Object value = props.get(key);
            if (value != null) {
                // remove existing text
                node.setText(""); //$NON-NLS-1$
                ((Element) node).addCDATA(value.toString());
            }
        }
    }
    // the property "mdx" is no longer being put in the hashmap. So,
    // query will be passed properly now.
}

From source file:org.pentaho.jpivot.AnalysisViewService.java

License:Open Source License

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    String responseEncoding = PentahoSystem.getSystemSetting("web-service-encoding", "utf-8");
    String component = request.getParameter("component"); //$NON-NLS-1$

    // Check if we need to forward off before getting output stream. Fixes
    // JasperException
    if (component.equalsIgnoreCase("newView")) { //$NON-NLS-1$
        newAnalysisView(request, response);
        return;/*  w  w  w. j ava2s . c o m*/
    }

    PentahoSystem.systemEntryPoint();

    try {

        boolean wrapWithSoap = "false".equals(request.getParameter("ajax")); //$NON-NLS-1$ //$NON-NLS-2$
        String actionPath = request.getParameter("path"); //$NON-NLS-1$
        String content = null;
        try {
            content = getPayloadAsString(request);
        } catch (IOException ioEx) {
            String msg = Messages.getInstance()
                    .getErrorString("AdhocWebService.ERROR_0006_FAILED_TO_GET_PAYLOAD_FROM_REQUEST"); //$NON-NLS-1$
            error(msg, ioEx);
            XmlDom4JHelper.saveDom(WebServiceUtil.createErrorDocument(msg + " " + ioEx.getLocalizedMessage()),
                    response.getOutputStream(), responseEncoding, true);
        }
        IParameterProvider parameterProvider = null;
        HashMap parameters = new HashMap();

        if (!StringUtils.isEmpty(content)) {
            Document doc = null;
            try {
                doc = XmlDom4JHelper.getDocFromString(content, new PentahoEntityResolver());
            } catch (XmlParseException e) {
                String msg = Messages.getInstance()
                        .getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"); //$NON-NLS-1$
                error(msg, e);
                XmlDom4JHelper.saveDom(WebServiceUtil.createErrorDocument(msg), response.getOutputStream(),
                        responseEncoding, true);
            }

            List parameterNodes = doc.selectNodes("//SOAP-ENV:Body/*/*"); //$NON-NLS-1$
            for (int i = 0; i < parameterNodes.size(); i++) {
                Node parameterNode = (Node) parameterNodes.get(i);
                String parameterName = parameterNode.getName();
                String parameterValue = parameterNode.getText();
                // String type = parameterNode.selectSingleNode( "@type" );
                // if( "xml-data".equalsIgnoreCase( ) )
                if ("action".equals(parameterName)) { //$NON-NLS-1$
                    //            ActionInfo info = ActionInfo.parseActionString(parameterValue);
                    //            solutionName = info.getSolutionName();
                    //            actionPath = info.getPath();
                    //            actionName = info.getActionName();
                    //            parameters.put("solution", solutionName); //$NON-NLS-1$
                    parameters.put("path", parameterValue); //$NON-NLS-1$
                    //            parameters.put("name", actionName); //$NON-NLS-1$         
                } else if ("component".equals(parameterName)) { //$NON-NLS-1$  
                    component = parameterValue;
                } else {
                    parameters.put(parameterName, parameterValue);
                }
            }
            parameterProvider = new SimpleParameterProvider(parameters);
        } else {
            parameterProvider = new HttpRequestParameterProvider(request);
        }

        //      if (!"generatePreview".equals(component)) { //$NON-NLS-1$
        //        response.setContentType("text/xml"); //$NON-NLS-1$
        //        response.setCharacterEncoding(responseEncoding);
        //      }

        // PentahoHttpSession userSession = new PentahoHttpSession(
        // request.getRemoteUser(), request.getSession(),
        // request.getLocale() );
        IPentahoSession userSession = getPentahoSession(request);

        // send the header of the message to prevent time-outs while we are
        // working
        //response.setHeader("expires", "0"); //$NON-NLS-1$ //$NON-NLS-2$

        dispatch(request, response, component, parameterProvider, userSession, wrapWithSoap);

    } catch (IOException ioEx) {
        String msg = Messages.getInstance()
                .getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"); //$NON-NLS-1$
        error(msg, ioEx);
        XmlDom4JHelper.saveDom(WebServiceUtil.createErrorDocument(msg), response.getOutputStream(),
                responseEncoding, true);
    } catch (PentahoSystemException ex) {
        String msg = ex.getLocalizedMessage();
        error(msg, ex);
        XmlDom4JHelper.saveDom(WebServiceUtil.createErrorDocument(msg), response.getOutputStream(),
                responseEncoding, true);
    } catch (PentahoAccessControlException ex) {
        String msg = ex.getLocalizedMessage();
        error(msg, ex);
        XmlDom4JHelper.saveDom(WebServiceUtil.createErrorDocument(msg), response.getOutputStream(),
                responseEncoding, true);
    } finally {
        PentahoSystem.systemExitPoint();
    }
}

From source file:org.pentaho.platform.config.SystemSettingsConfiguration.java

License:Open Source License

private void addElementsToProperties(List elements, Properties props, String parentPath) {

    for (java.lang.Object o : elements) {
        Node ele = (Node) o;
        if (ele.getNodeType() != 1) { // text
            continue;
        }/*ww  w . j a v a 2  s .c o  m*/
        String contents = ele.getText().trim();

        String newParentPath = "";

        if (!StringUtils.isEmpty(parentPath)) {
            newParentPath = parentPath + ".";
        }
        newParentPath += ele.getName();

        if (!StringUtils.isEmpty(contents)) {
            props.setProperty(newParentPath, contents);
        }
        if (ele instanceof Element) {
            List children = ((Element) ele).content();

            addElementsToProperties(children, props, newParentPath);
        }

    }
}

From source file:org.pentaho.platform.engine.services.actionsequence.SequenceDefinition.java

License:Open Source License

private static IActionSequence getNextLoopGroup(final ISequenceDefinition seqDef, final Node actionsNode,
        final String solutionPath, final ILogger logger, final int loggingLevel) {

    String loopParameterName = XmlDom4JHelper.getNodeText("@loop-on", actionsNode); //$NON-NLS-1$
    boolean loopUsingPeek = "true".equalsIgnoreCase(XmlDom4JHelper.getNodeText("@peek-only", actionsNode)); //$NON-NLS-1$ //$NON-NLS-2$

    Node actionDefinitionNode;
    ActionDefinition actionDefinition;//from   ww  w.j  ava2  s  .  c o  m

    List actionDefinitionList = new ArrayList();

    List nodeList = actionsNode.selectNodes("*"); //$NON-NLS-1$
    Iterator actionDefinitionNodes = nodeList.iterator();
    while (actionDefinitionNodes.hasNext()) {
        actionDefinitionNode = (Node) actionDefinitionNodes.next();
        if (actionDefinitionNode.getName().equals("actions")) { //$NON-NLS-1$
            actionDefinitionList.add(SequenceDefinition.getNextLoopGroup(seqDef, actionDefinitionNode,
                    solutionPath, logger, loggingLevel));
        } else if (actionDefinitionNode.getName().equals("action-definition")) { //$NON-NLS-1$
            actionDefinition = new ActionDefinition(actionDefinitionNode, logger);
            actionDefinition.setLoggingLevel(loggingLevel);
            actionDefinitionList.add(actionDefinition);
        }
    }
    // action sequences with 0 actions are valid, see: JIRA PLATFORM-837

    IConditionalExecution conditionalExecution = SequenceDefinition.parseConditionalExecution(actionsNode,
            logger, "condition"); //$NON-NLS-1$

    ActionSequence sequence = new ActionSequence(loopParameterName, seqDef, actionDefinitionList,
            loopUsingPeek);

    sequence.setConditionalExecution(conditionalExecution);
    return sequence;
}

From source file:org.pentaho.platform.engine.services.actionsequence.SequenceDefinition.java

License:Open Source License

static int parseParameters(final Node actionRootNode, final ILogger logger, final String nodePath,
        final Map parameterMap, final Map mapTo, final boolean inputVar) {
    try {//from   w  w  w.j  av a  2  s . com
        List parameters = actionRootNode.selectNodes(nodePath);

        // TODO create objects to represent the types
        // TODO need source variable list
        Iterator parametersIterator = parameters.iterator();
        Node parameterNode;
        String parameterName;
        String parameterType;
        ActionParameter parameter;
        List variableNodes;
        List variables;
        Node variableNode;
        Iterator variablesIterator;
        String variableSource;
        String variableName;
        int variableIdx;
        Object defaultValue = null;

        while (parametersIterator.hasNext()) {
            parameterNode = (Node) parametersIterator.next();
            parameterName = parameterNode.getName();
            parameterType = XmlDom4JHelper.getNodeText("@type", parameterNode); //$NON-NLS-1$

            if (mapTo != null) {
                mapTo.put(parameterName, XmlDom4JHelper.getNodeText("@mapping", parameterNode, parameterName)); //$NON-NLS-1$
            }

            defaultValue = SequenceDefinition.getDefaultValue(parameterNode);
            // get the list of sources for this parameter
            variableNodes = parameterNode.selectNodes((inputVar) ? "sources/*" : "destinations/*"); //$NON-NLS-1$ //$NON-NLS-2$
            variablesIterator = variableNodes.iterator();
            variableIdx = 1;
            variables = new ArrayList();
            while (variablesIterator.hasNext()) {
                variableNode = (Node) variablesIterator.next();
                // try to resolve the parameter value for this
                try {
                    variableSource = variableNode.getName();
                    variableName = variableNode.getText();
                    ActionParameterSource variable = new ActionParameterSource(variableSource, variableName);
                    if (SequenceDefinition.debug) {
                        logger.debug(Messages.getInstance().getString(
                                "SequenceDefinition.DEBUG_ADDING_SOURCE_FOR_PARAMETER", variableSource, //$NON-NLS-1$
                                parameterName));
                    }

                    variables.add(variable);
                } catch (Exception e) {
                    logger.error(Messages.getInstance().getErrorString(
                            "SequenceDefinition.ERROR_0004_VARIABLE_SOURCE_NOT_VALID", //$NON-NLS-1$
                            Integer.toString(variableIdx), parameterName), e);
                }
                variableIdx++;
            }
            if (defaultValue != null) {
                if (SequenceDefinition.debug) {
                    logger.debug(
                            Messages.getInstance().getString("SequenceDefinition.DEBUG_USING_DEFAULT_VALUE", //$NON-NLS-1$
                                    defaultValue.toString(), parameterName));
                }
            }
            boolean isOutputParameter = Boolean
                    .parseBoolean(XmlDom4JHelper.getNodeText("@is-output-parameter", parameterNode, "true")); //$NON-NLS-1$ //$NON-NLS-2$
            parameter = new ActionParameter(parameterName, parameterType, null, variables, defaultValue);
            parameter.setOutputParameter(isOutputParameter);
            parameterMap.put(parameterName, parameter);
        }
        return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    } catch (Exception e) {
        logger.error(Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0005_PARSING_PARAMETERS"), //$NON-NLS-1$
                e);
    }

    return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC;
}