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.platform.web.servlet.HttpWebService.java

License:Open Source License

public void doGetFixMe(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {

    ////from   w  w w .  j  a  v a2s .co  m
    // System Entry/Exit point handled by the doGet method.
    //

    try {
        String actionPath = request.getParameter("path"); //$NON-NLS-1$
        String solutionName = actionPath.substring(0, actionPath.indexOf('/', 1));
        String actionName = actionPath.substring(actionPath.lastIndexOf('/'));

        String actionSeqPath = ActionInfo.buildSolutionPath(solutionName, actionPath, actionName);

        String component = request.getParameter("component"); //$NON-NLS-1$
        String content = getPayloadAsString(request);

        IParameterProvider parameterProvider = null;
        HashMap parameters = new HashMap();
        if ((content != null) && (content.length() > 0)) {
            Document doc = XmlDom4JHelper.getDocFromString(content, new PentahoEntityResolver());
            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();
                } else if ("component".equals(parameterName)) { //$NON-NLS-1$
                    component = parameterValue;
                } else {
                    parameters.put(parameterName, parameterValue);
                }

            }
            parameterProvider = new SimpleParameterProvider(parameters);
        } else {
            parameterProvider = new HttpRequestParameterProvider(request);
        }

        response.setContentType("text/xml"); //$NON-NLS-1$
        response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
        // PentahoHttpSession userSession = new PentahoHttpSession(
        // request.getRemoteUser(), request.getSession(),
        // request.getLocale() );
        IPentahoSession userSession = getPentahoSession(request);

        String instanceId = request.getParameter("instance-id"); //$NON-NLS-1$
        String processId = this.getClass().getName();

        OutputStream contentStream = new ByteArrayOutputStream();

        SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentStream, false);

        // send the header of the message to prevent time-outs while we are
        // working
        OutputStream outputStream = response.getOutputStream();
        if ((component == null) || "action".equals(component)) { //$NON-NLS-1$
            // assume this is an action sequence execute
            HttpWebServiceRequestHandler requestHandler = new HttpWebServiceRequestHandler(userSession, null,
                    outputHandler, parameterProvider, null);

            requestHandler.setParameterProvider(IParameterProvider.SCOPE_SESSION,
                    new HttpSessionParameterProvider(userSession));
            requestHandler.setInstanceId(instanceId);
            requestHandler.setProcessId(processId);
            requestHandler.setActionPath(actionSeqPath);

            if (ServletBase.debug) {
                debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_START")); //$NON-NLS-1$
            }
            IRuntimeContext runtime = null;
            try {
                runtime = requestHandler.handleActionRequest(0, 0);
                Document responseDoc = SoapHelper.createSoapResponseDocument(runtime, outputHandler,
                        contentStream, requestHandler.getMessages());
                XmlDom4JHelper.saveDom(responseDoc, outputStream,
                        PentahoSystem.getSystemSetting("web-service-encoding", "utf-8"), true);
            } finally {
                if (runtime != null) {
                    runtime.dispose();
                }
            }
        } else if ("dial".equals(component)) { //$NON-NLS-1$
            doDial(solutionName, actionPath, actionName, parameterProvider, outputStream, userSession);
        } else if ("chart".equals(component)) { //$NON-NLS-1$
            doChart(actionPath, parameterProvider, outputStream, userSession);
        } else if ("xaction-parameter".equals(component)) { //$NON-NLS-1$
            doParameter(solutionName, actionPath, actionName, parameterProvider, outputStream, userSession,
                    response);
        }

    } catch (Throwable t) {
        error(Messages.getInstance().getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"), t); //$NON-NLS-1$
    }
    if (ServletBase.debug) {
        debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_END")); //$NON-NLS-1$
    }

}

From source file:org.pentaho.platform.web.servlet.HttpWebService.java

License:Open Source License

protected Map getParameterMapFromPayload(final String xml) {
    Map parameters = new HashMap();
    Document doc = null;//from   ww w  .java 2  s  .  c o  m
    try {
        doc = XmlDom4JHelper.getDocFromString(xml, new PentahoEntityResolver());
    } catch (XmlParseException e) {
        error(Messages.getInstance().getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"), e); //$NON-NLS-1$
        return parameters;
    }
    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();
        parameters.put(parameterName, parameterValue);
    }
    return parameters;
}

From source file:org.pentaho.reporting.platform.plugin.SimpleEmailComponent.java

License:Open Source License

private Session buildSession() throws Exception {

    final Properties props = new Properties();

    try {/*w  w  w.ja v  a2  s . c  om*/
        final Document configDocument = PentahoSystem.getSystemSettings()
                .getSystemSettingsDocument("smtp-email/email_config.xml"); //$NON-NLS-1$
        final List properties = configDocument.selectNodes("/email-smtp/properties/*"); //$NON-NLS-1$
        final Iterator propertyIterator = properties.iterator();
        while (propertyIterator.hasNext()) {
            final Node propertyNode = (Node) propertyIterator.next();
            final String propertyName = propertyNode.getName();
            final String propertyValue = propertyNode.getText();
            props.put(propertyName, propertyValue);
        }
    } catch (Exception e) {
        log.error(Messages.getInstance().getString("ReportPlugin.emailConfigFileInvalid")); //$NON-NLS-1$
        throw e;
    }

    final boolean authenticate = "true".equals(props.getProperty("mail.smtp.auth")); //$NON-NLS-1$//$NON-NLS-2$

    // Get a Session object

    final Session session;
    if (authenticate) {
        final Authenticator authenticator = new EmailAuthenticator();
        session = Session.getInstance(props, authenticator);
    } else {
        session = Session.getInstance(props);
    }

    // if debugging is not set in the email config file, match the
    // component debug setting
    if (!props.containsKey("mail.debug")) { //$NON-NLS-1$
        session.setDebug(true);
    }

    return session;

}

From source file:org.springfield.lou.application.ApplicationManager.java

License:Open Source License

private void readJumpersForApp(String filename) {
    //      System.out.println("SCANPATH="+filename);
    //      String filename = basepath+File.separator+"apps"+File.separator+part+File.separator+"components"+File.separator+"app.xml";
    File file = new File(filename);
    if (file.exists()) {
        try {/*from   www.  jav  a  2  s . c  om*/
            BufferedReader br = new BufferedReader(new FileReader(filename));
            StringBuffer str = new StringBuffer();
            String line = br.readLine();
            while (line != null) {
                str.append(line);
                str.append("\n");
                line = br.readLine();
            }
            br.close();

            String body = str.toString();
            Document result = DocumentHelper.parseText(body);
            for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) {

                Node child = (Node) iter.next();
                //System.out.println("C="+child.getName());
                if (child.getName() != null && child.getName().equals("jumper")) {
                    Element model = (Element) child;
                    String sid = model.attributeValue("id");

                    //FsNode modelnode = new FsNode("model",modelid);
                    for (Iterator<Node> iter2 = model.nodeIterator(); iter2.hasNext();) {
                        Node child2 = (Node) iter2.next();
                        String id = child2.getName();
                        if (id != null) {
                            //System.out.println("JUMPER="+sid+" "+id+" "+child2.getText());
                            LouServlet.addUrlTrigger(sid + "," + child2.getText(), "newscreen");

                        }
                    }
                    //   putNode("/app/component",modelnode);
                    //   System.out.println("MIDELNODE="+modelnode.asXML());
                } else if (child.getName() != null && child.getName().equals("jumpers")) {
                    Element model = (Element) child;
                    String sid = model.attributeValue("id");

                    //FsNode modelnode = new FsNode("model",modelid);
                    for (Iterator<Node> iter2 = model.nodeIterator(); iter2.hasNext();) {
                        Node child2 = (Node) iter2.next();
                        String id = child2.getName();
                        if (id != null) {
                            System.out.println("JUMPERS=" + sid + " " + id + " " + child2.getText());
                            FSList fslist = FSListManager.get(child2.getText(), false);
                            if (fslist != null) {
                                List<FsNode> nodes = fslist.getNodes();
                                if (nodes != null) {
                                    for (Iterator<FsNode> iter3 = nodes.iterator(); iter3.hasNext();) {
                                        FsNode node = (FsNode) iter3.next();
                                        String jumper = node.getId();
                                        String target = node.getProperty("target");
                                        String domain = node.getProperty("domain");
                                        System.out
                                                .println("JUMPER=/lou/" + domain + "/" + jumper + "," + target);
                                        LouServlet.addUrlTrigger("/lou/" + domain + "/" + jumper + "," + target,
                                                "newscreen");

                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

From source file:org.springfield.mojo.linkedtv.Episode.java

License:Open Source License

public FSList getAnnotations() {
    // try reading it from disk
    String readpath = "/springfield/lisa/data/linkedtv/" + mediaResourceId + "/annotations.xml";
    System.out.println("READPATH=" + readpath);
    String body = readFile(readpath);
    if (body == null) {
        Response response = HttpHelper.sendRequest("GET",
                MAGGIE + "&id=" + mediaResourceId + "&annotations&curated&renew");
        if (response.getStatusCode() != 200) {
            System.out.println("What? " + response.getStatusCode());
            return new FSList();
        } else {/*from   w ww . j av  a2 s .  c om*/
            body = response.toString();
        }
    } else {
        System.out.println("READING FROM LISA DISK CACHE " + readpath);
    }
    //Response response = HttpHelper.sendRequest("GET", MAGGIE+"&id="+mediaResourceId+"&annotations&curated&renew");
    this.annotations = new FSList();

    try {
        Document doc = DocumentHelper.parseText(body);
        List<Node> nodes = doc.selectNodes("//annotations/*");
        String presentationUri = doc.selectSingleNode("properties/presentation") == null ? ""
                : doc.selectSingleNode("properties/presentation").getText();
        presentationUri += "annotations";

        FSList annotations = new FSList(presentationUri);

        for (Node annotation : nodes) {
            Element a = (Element) annotation;
            FsNode result = new FsNode();

            result.setName(a.getName());
            result.setId(a.attribute("id").getText());
            result.setPath(presentationId + "/" + result.getName() + "/" + result.getId());
            result.setImageBaseUri(stillsUri);

            List<Node> properties = a.selectNodes("properties/*");
            for (Node property : properties) {
                //System.out.println("DANIEL2: "+property.getName()+"="+property.getText());
                result.setProperty(property.getName(), property.getText());
                if (property.getName().equals("locator")) {
                    loadEntityFromProxy(property.getName(), property.getText());
                }
            }
            annotations.addNode(result);
        }
        this.annotations = annotations;
        return annotations;

    } catch (DocumentException e) {
        System.out.println("What? " + e.getMessage());
        return new FSList();
    }
}

From source file:org.springfield.mojo.linkedtv.Episode.java

License:Open Source License

public FSList getChapters() {
    // try reading it from disk
    String readpath = "/springfield/lisa/data/linkedtv/" + mediaResourceId + "/chapters.xml";
    System.out.println("READPATH=" + readpath);
    String body = readFile(readpath);
    if (body == null) {
        Response response = HttpHelper.sendRequest("GET", MAGGIE + "&id=" + mediaResourceId + "&chapters");
        if (response.getStatusCode() != 200) {
            System.out.println("Statuscode = " + response.getStatusCode());
            return new FSList();
        } else {/*from ww w.  j ava2  s .c o  m*/
            body = response.toString();
        }
        //System.out.println("CHAPTERS="+response.toString());
    } else {
        System.out.println("READING FROM LISA DISK CACHE " + readpath);
    }
    this.chapters = new FSList();

    try {
        Document doc = DocumentHelper.parseText(body);
        List<Node> nodes = doc.selectNodes("//chapter");
        String presentationUri = doc.selectSingleNode("properties/presentation") == null ? ""
                : doc.selectSingleNode("properties/presentation").getText();
        presentationUri += "chapters";

        FSList chapters = new FSList(presentationUri);

        for (Node chapter : nodes) {
            Element c = (Element) chapter;
            FsNode result = new FsNode();

            result.setName(c.getName());
            result.setId(c.attribute("id").getText());
            result.setPath(presentationId + "/" + result.getName() + "/" + result.getId());
            result.setImageBaseUri(stillsUri);

            List<Node> properties = c.selectNodes("properties/*");
            for (Node property : properties) {
                //System.out.println("DANIEL: "+property.getName()+"="+property.getText());
                result.setProperty(property.getName(), property.getText());
            }
            chapters.addNode(result);
        }
        this.chapters = chapters;
        return chapters;

    } catch (DocumentException e) {
        System.out.println("What? " + e.getMessage());
        return new FSList();
    }
}

From source file:org.springfield.mojo.linkedtv.Episode.java

License:Open Source License

public FSList getEnrichmentsFromAnnotation(FsNode annotation) {
    if (annotation != null) {
        Response response = null;
        try {//from   w  w  w  . java2 s .  c  o m
            response = HttpHelper.sendRequest("GET", MAGGIE + "&id=" + annotation.getId() + "&enrichments");
        } catch (Exception e) {
            return new FSList();
        }
        if (response.getStatusCode() != 200) {
            System.out.println("Statuscode = " + response.getStatusCode());
            return new FSList();
        } else {
            try {
                Document doc = DocumentHelper.parseText(response.toString());
                List<Node> nodes = doc.selectNodes("//enrichment");

                FSList enrichments = new FSList("annotation/" + annotation.getId());

                for (Node enrichment : nodes) {
                    Element c = (Element) enrichment;
                    FsNode result = new FsNode();

                    result.setName(c.getName());
                    result.setId(c.attribute("id").getText());
                    result.setPath(presentationId + "/" + result.getName() + "/" + result.getId());
                    result.setImageBaseUri(stillsUri);

                    List<Node> properties = c.selectNodes("properties/*");
                    for (Node property : properties) {
                        result.setProperty(property.getName(), property.getText());
                    }
                    enrichments.addNode(result);
                }
                this.enrichments = new FSList();
                return enrichments;
            } catch (DocumentException e) {
                System.out.println("What? " + e.getMessage());
                return new FSList();
            }
        }
    } else {
        System.out.println("Empty annotation");
    }
    return new FSList();
}

From source file:org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobJavaScriptsWSManager.java

License:Open Source License

/**
 * DOC x Comment method "genWebInfoForder".
 * //from  w w w. ja v  a 2s  .  co m
 * @param list
 */
private void editWSDDFile(ProcessItem processItem) {
    String projectName = getCorrespondingProjectName(processItem);
    String selectedProcessVersion = processItem.getProperty().getVersion();
    if (!isMultiNodes() && this.getSelectedJobVersion() != null) {
        selectedProcessVersion = this.getSelectedJobVersion();
    }

    String jobFolderName = JavaResourcesHelper.getJobFolderName(escapeFileNameSpace(processItem),
            selectedProcessVersion);

    String deployFileName = getTmpFolder() + PATH_SEPARATOR + projectName + PATH_SEPARATOR + jobFolderName
            + PATH_SEPARATOR + "deploy.wsdd"; //$NON-NLS-1$
    String serverConfigFile = getTmpFolder() + PATH_SEPARATOR + "server-config.wsdd"; //$NON-NLS-1$

    File deployFile = new File(deployFileName);
    if (!deployFile.exists()) {
        log.error(org.talend.repository.i18n.Messages.getString("JobJavaScriptsWSManager.errorMessage")); //$NON-NLS-1$
        return;
    }
    // edit the server-config.wsdd file
    try {

        File wsddFile = new File(serverConfigFile);
        BufferedReader reader = new BufferedReader(new FileReader(wsddFile));

        SAXReader saxReader = new SAXReader();
        Document doc = saxReader.read(reader);

        BufferedReader wsdlreader = new BufferedReader(new FileReader(deployFile));
        SAXReader wsdlsaxReader = new SAXReader();
        Document wsdldoc = wsdlsaxReader.read(wsdlreader);
        Element wsdlroot = wsdldoc.getRootElement();
        Element element = wsdlroot.element("service"); //$NON-NLS-1$

        List<Element> elements = element.elements("arrayMapping"); //$NON-NLS-1$
        for (Element item : elements) {
            Attribute attribute = item.attribute("qname"); //$NON-NLS-1$
            item.remove(attribute);
            attribute.setValue(attribute.getValue().replaceFirst(">", "")); //$NON-NLS-1$ //$NON-NLS-2$
            item.add(attribute);
        }

        Element root = doc.getRootElement();
        List<Node> content = root.content();
        for (int i = 0; i < content.size(); i++) {
            Node n = content.get(i);
            if (n instanceof Element) {
                if (n.getName().equals("transport")) { //$NON-NLS-1$
                    content.add(i - 1, element);
                    break;
                }
            }
        }

        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(serverConfigFile), "UTF-8")); //$NON-NLS-1$

        OutputFormat format = OutputFormat.createPrettyPrint();
        XMLWriter output = new XMLWriter(writer, format);
        output.write(doc);
        output.flush();
        output.close();

    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}

From source file:org.uorm.serializer.DefaultPojoSerializer.java

License:Apache License

@Override
public <T> T deserialize(Class<T> cls, Element element) throws Exception {
    @SuppressWarnings("unchecked")
    List<Node> nodes = element.elements();
    Map<String, Method> setMethods = ObjectMappingCache.getInstance().getPojoSetMethod(cls);
    T instance = cls.newInstance();/*from w w  w  .j a v  a  2 s  .  c  o  m*/
    if (setMethods != null && !setMethods.isEmpty()) {
        for (Node node : nodes) {
            String strVal = node.getText();
            if (strVal != null) {
                Method setterMethod = setMethods.get(node.getName().toUpperCase());
                if (setterMethod != null) {
                    Class<?> memberType = setterMethod.getParameterTypes()[0];
                    if (memberType == String.class) {
                        setterMethod.invoke(instance, strVal);
                    } else {
                        if (strVal.length() > 0) {
                            Object val = converter.convert(strVal, memberType);
                            setterMethod.invoke(instance, val);
                        }
                    }
                }
            }
        }
    }
    return instance;
}

From source file:org.uorm.serializer.DefaultPojoSerializer.java

License:Apache License

@Override
public Map<String, Object> deserialize2(Class<?> refcls, Element element) throws Exception {
    @SuppressWarnings("unchecked")
    List<Node> nodes = element.elements();
    Map<String, PropertyDescriptor> propMap = ObjectMappingCache.getInstance().getObjectPropertyMap(refcls);
    Map<String, Object> instance = new HashMap<String, Object>();
    if (propMap != null && !propMap.isEmpty()) {
        for (Node node : nodes) {
            String strVal = node.getText();
            if (strVal != null) {
                String name = node.getName().toUpperCase();
                PropertyDescriptor descriptor = propMap.get(name);
                if (descriptor != null) {
                    Class<?> memberType = descriptor.getPropertyType();
                    if (memberType == String.class) {
                        instance.put(name, strVal);
                    } else {
                        if (strVal.length() > 0) {
                            Object val = converter.convert(strVal, memberType);
                            instance.put(name, val);
                        }//from  w  w w.  j  a  v a  2 s  . c o  m
                    }
                }
            }
        }
    }
    return instance;
}