Search in sources :

Example 31 with Node

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

the class WebXmlTest method testGetContextParamValue_nullSubNode.

@Test
public void testGetContextParamValue_nullSubNode() throws Exception {
    webXml = new WebXml(document);
    Node node = mock(Node.class);
    when(node.selectSingleNode("../param-value")).thenReturn(null);
    when(document.selectSingleNode(anyString())).thenReturn(node);
    String test = webXml.getContextParamValue("test");
    assertNull(test);
    verify(node).selectSingleNode("../param-value");
}
Also used : Node(org.dom4j.Node) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 32 with Node

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

the class HttpWebService method getParameterMapFromPayload.

protected Map getParameterMapFromPayload(final String xml) {
    Map parameters = new HashMap();
    Document doc = null;
    try {
        doc = XmlDom4JHelper.getDocFromString(xml, new PentahoEntityResolver());
    } catch (XmlParseException e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"), e);
        return parameters;
    }
    // $NON-NLS-1$
    List parameterNodes = doc.selectNodes("//SOAP-ENV:Body/*/*");
    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;
}
Also used : HashMap(java.util.HashMap) Node(org.dom4j.Node) ArrayList(java.util.ArrayList) List(java.util.List) XmlParseException(org.pentaho.platform.api.util.XmlParseException) Document(org.dom4j.Document) HashMap(java.util.HashMap) Map(java.util.Map) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver)

Example 33 with Node

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

the class HttpWebService method doGetFixMe.

public void doGetFixMe(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    try {
        // $NON-NLS-1$
        String actionPath = request.getParameter("path");
        String solutionName = actionPath.substring(0, actionPath.indexOf('/', 1));
        String actionName = actionPath.substring(actionPath.lastIndexOf('/'));
        String actionSeqPath = ActionInfo.buildSolutionPath(solutionName, actionPath, actionName);
        // $NON-NLS-1$
        String component = request.getParameter("component");
        String content = getPayloadAsString(request);
        IParameterProvider parameterProvider = null;
        HashMap parameters = new HashMap();
        if ((content != null) && (content.length() > 0)) {
            Document doc = XmlDom4JHelper.getDocFromString(content, new PentahoEntityResolver());
            // $NON-NLS-1$
            List parameterNodes = doc.selectNodes("//SOAP-ENV:Body/*/*");
            for (int i = 0; i < parameterNodes.size(); i++) {
                Node parameterNode = (Node) parameterNodes.get(i);
                String parameterName = parameterNode.getName();
                String parameterValue = parameterNode.getText();
                // 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);
        }
        // $NON-NLS-1$
        response.setContentType("text/xml");
        response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
        // PentahoHttpSession userSession = new PentahoHttpSession(
        // request.getRemoteUser(), request.getSession(),
        // request.getLocale() );
        IPentahoSession userSession = getPentahoSession(request);
        // $NON-NLS-1$
        String instanceId = request.getParameter("instance-id");
        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) {
                // $NON-NLS-1$
                debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_START"));
            }
            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) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"), t);
    }
    if (ServletBase.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_END"));
    }
}
Also used : HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Node(org.dom4j.Node) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ActionInfo(org.pentaho.platform.engine.core.solution.ActionInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpWebServiceRequestHandler(org.pentaho.platform.web.http.request.HttpWebServiceRequestHandler) Document(org.dom4j.Document) PentahoEntityResolver(org.pentaho.platform.engine.services.solution.PentahoEntityResolver) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HttpSessionParameterProvider(org.pentaho.platform.web.http.session.HttpSessionParameterProvider) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) ArrayList(java.util.ArrayList) List(java.util.List) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 34 with Node

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

the class TimeTableXYDatasetChartDefinition method setPaintSequence.

public void setPaintSequence(final Node paletteNode) {
    if (paletteNode != null) {
        List colorNodes = paletteNode.selectNodes(ChartDefinition.COLOR_NODE_NAME);
        Paint[] paints = new Paint[colorNodes.size()];
        for (int i = 0; i < colorNodes.size(); i++) {
            paints[i] = JFreeChartEngine.getPaint((Node) colorNodes.get(i));
        }
        setPaintSequence(paints);
    }
}
Also used : Node(org.dom4j.Node) ArrayList(java.util.ArrayList) List(java.util.List) Paint(java.awt.Paint) Paint(java.awt.Paint)

Example 35 with Node

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

the class TimeTableXYDatasetChartDefinition method setChartBackground.

public void setChartBackground(final Node chartBackgroundNode) {
    if (chartBackgroundNode != null) {
        Node backgroundTypeNode = chartBackgroundNode.selectSingleNode(ChartDefinition.BACKGROUND_TYPE_ATTRIBUTE_NAME);
        if (backgroundTypeNode != null) {
            String backgroundTypeStr = backgroundTypeNode.getText();
            if (ChartDefinition.COLOR_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) {
                setChartBackgroundPaint(JFreeChartEngine.getPaint(chartBackgroundNode));
                setChartBackgroundImage((Image) null);
            } else if (ChartDefinition.IMAGE_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) {
                setChartBackgroundImage(chartBackgroundNode);
                setChartBackgroundPaint(null);
            } else if (ChartDefinition.TEXTURE_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) {
                setChartBackgroundPaint(JFreeChartEngine.getTexturePaint(chartBackgroundNode, getWidth(), getHeight(), getSession()));
                setChartBackgroundImage((Image) null);
            } else if (ChartDefinition.GRADIENT_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) {
                setChartBackgroundPaint(JFreeChartEngine.getGradientPaint(chartBackgroundNode, getWidth(), getHeight()));
                setChartBackgroundImage((Image) null);
            }
        }
    }
}
Also used : Node(org.dom4j.Node) Image(java.awt.Image)

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