List of usage examples for org.dom4j Node getName
String getName();
getName
returns the name of this node.
From source file:org.pentaho.platform.engine.services.actionsequence.SequenceDefinition.java
License:Open Source License
private int parseResourceDefinitions(final Node actionRootNode, final ILogger logger) { resourceDefinitions = new ListOrderedMap(); try {/*from w ww.ja va 2 s .c o m*/ List resources = actionRootNode.selectNodes("resources/*"); //$NON-NLS-1$ // TODO create objects to represent the types // TODO need source variable list Iterator resourcesIterator = resources.iterator(); Node resourceNode; String resourceName; String resourceTypeName; String resourceMimeType; int resourceType; ActionSequenceResource resource; Node typeNode, mimeNode; while (resourcesIterator.hasNext()) { resourceNode = (Node) resourcesIterator.next(); typeNode = resourceNode.selectSingleNode("./*"); //$NON-NLS-1$ if (typeNode != null) { resourceName = resourceNode.getName(); resourceTypeName = typeNode.getName(); resourceType = ActionSequenceResource.getResourceType(resourceTypeName); String resourceLocation = XmlDom4JHelper.getNodeText("location", typeNode); //$NON-NLS-1$ if ((resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE) || (resourceType == IActionSequenceResource.FILE_RESOURCE)) { if (resourceLocation == null) { logger.error(Messages.getInstance().getErrorString( "SequenceDefinition.ERROR_0008_RESOURCE_NO_LOCATION", resourceName)); //$NON-NLS-1$ continue; } } else if (resourceType == IActionSequenceResource.STRING) { resourceLocation = XmlDom4JHelper.getNodeText("string", resourceNode); //$NON-NLS-1$ } else if (resourceType == IActionSequenceResource.XML) { //resourceLocation = XmlHelper.getNodeText("xml", resourceNode); //$NON-NLS-1$ Node xmlNode = typeNode.selectSingleNode("./location/*"); //$NON-NLS-1$ // Danger, we have now lost the character encoding of the XML in this node // see BISERVER-895 resourceLocation = (xmlNode == null) ? "" : xmlNode.asXML(); //$NON-NLS-1$ } mimeNode = typeNode.selectSingleNode("mime-type"); //$NON-NLS-1$ if (mimeNode != null) { resourceMimeType = mimeNode.getText(); if ((resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE) || (resourceType == IActionSequenceResource.FILE_RESOURCE)) { resourceLocation = FilenameUtils.separatorsToUnix(resourceLocation); if (!resourceLocation.startsWith("/")) { //$NON-NLS-1$ String parentDir = FilenameUtils.getFullPathNoEndSeparator(xactionPath); if (parentDir.length() == 0) { parentDir = RepositoryFile.SEPARATOR; } resourceLocation = FilenameUtils .separatorsToUnix(FilenameUtils.concat(parentDir, resourceLocation)); } } resource = new ActionSequenceResource(resourceName, resourceType, resourceMimeType, resourceLocation); resourceDefinitions.put(resourceName, resource); } else { logger.error(Messages.getInstance().getErrorString( "SequenceDefinition.ERROR_0007_RESOURCE_NO_MIME_TYPE", resourceName)); //$NON-NLS-1$ } } // input = new ActionParameter( resourceName, resourceType, null // ); // resourceDefinitions.put( inputName, input ); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK; } catch (Exception e) { logger.error(Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"), //$NON-NLS-1$ e); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC; }
From source file:org.pentaho.platform.engine.services.actionsequence.SequenceDefinition.java
License:Open Source License
/** * sbarkdull: method appears to never be used anywhere * /*from ww w . j a v a 2 s .co m*/ * @param actionRootNode * @param logger * @param nodePath * @param mapTo * @return */ static int parseActionResourceDefinitions(final Node actionRootNode, final ILogger logger, final String nodePath, final Map mapTo) { try { List resources = actionRootNode.selectNodes(nodePath); // TODO create objects to represent the types // TODO need source variable list Iterator resourcesIterator = resources.iterator(); Node resourceNode; String resourceName; while (resourcesIterator.hasNext()) { resourceNode = (Node) resourcesIterator.next(); resourceName = resourceNode.getName(); if (mapTo != null) { mapTo.put(resourceName, XmlDom4JHelper.getNodeText("@mapping", resourceNode, resourceName)); //$NON-NLS-1$ } } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK; } catch (Exception e) { logger.error(Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"), //$NON-NLS-1$ e); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC; }
From source file:org.pentaho.platform.plugin.action.builtin.EmailComponent.java
License:Open Source License
@Override public boolean executeAction() { EmailAction emailAction = (EmailAction) getActionDefinition(); String messagePlain = emailAction.getMessagePlain().getStringValue(); String messageHtml = emailAction.getMessageHtml().getStringValue(); String subject = emailAction.getSubject().getStringValue(); String to = emailAction.getTo().getStringValue(); String cc = emailAction.getCc().getStringValue(); String bcc = emailAction.getBcc().getStringValue(); String from = emailAction.getFrom().getStringValue(defaultFrom); if (from.trim().length() == 0) { from = defaultFrom;//from w w w. ja va 2 s . c o m } /* * if( context.getInputNames().contains( "attach" ) ) { //$NON-NLS-1$ * Object attachParameter = context.getInputParameter( "attach" * ).getValue(); //$NON-NLS-1$ // We have a list of attachments, each * element of the list is the name of the parameter containing the * attachment // Use the parameter filename portion as the attachment * name. if ( attachParameter instanceof String ) { String attachName = * context.getInputParameter( "attach-name" ).getStringValue(); * //$NON-NLS-1$ AttachStruct attachData = getAttachData( context, * (String)attachParameter, attachName ); if ( attachData != null ) { * attachments.add( attachData ); } } else if ( attachParameter * instanceof List ) { for ( int i = 0; i < * ((List)attachParameter).size(); ++i ) { AttachStruct attachData = * getAttachData( context, ((List)attachParameter).get( i ).toString(), * null ); if ( attachData != null ) { attachments.add( attachData ); } } } * else if ( attachParameter instanceof Map ) { for ( Iterator it = * ((Map)attachParameter).entrySet().iterator(); it.hasNext(); ) { * Map.Entry entry = (Map.Entry)it.next(); AttachStruct attachData = * getAttachData( context, (String)entry.getValue(), * (String)entry.getKey() ); if ( attachData != null ) { * attachments.add( attachData ); } } } } * * int maxSize = Integer.MAX_VALUE; try { maxSize = new Integer( * props.getProperty( "mail.max.attach.size" ) ).intValue(); } catch( * Throwable t ) { //ignore if not set to a valid value } * * if ( totalAttachLength > maxSize ) { // Sort them in order TreeMap tm = * new TreeMap(); for( int idx=0; idx<attachments.size(); idx++ ) { // * tm.put( new Integer( )) } } */ if (ComponentBase.debug) { debug(Messages.getString("Email.DEBUG_TO_FROM", to, from)); //$NON-NLS-1$ debug(Messages.getString("Email.DEBUG_CC_BCC", cc, bcc)); //$NON-NLS-1$ debug(Messages.getString("Email.DEBUG_SUBJECT", subject)); //$NON-NLS-1$ debug(Messages.getString("Email.DEBUG_PLAIN_MESSAGE", messagePlain)); //$NON-NLS-1$ debug(Messages.getString("Email.DEBUG_HTML_MESSAGE", messageHtml)); //$NON-NLS-1$ } if ((to == null) || (to.trim().length() == 0)) { // Get the output stream that the feedback is going into OutputStream feedbackStream = getFeedbackOutputStream(); if (feedbackStream != null) { createFeedbackParameter("to", Messages.getString("Email.USER_ENTER_EMAIL_ADDRESS"), "", "", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ setFeedbackMimeType("text/html"); //$NON-NLS-1$ return true; } else { return false; } } if (subject == null) { error(Messages.getErrorString("Email.ERROR_0005_NULL_SUBJECT", getActionName())); //$NON-NLS-1$ return false; } if ((messagePlain == null) && (messageHtml == null)) { error(Messages.getErrorString("Email.ERROR_0006_NULL_BODY", getActionName())); //$NON-NLS-1$ return false; } if (getRuntimeContext().isPromptPending()) { return true; } try { Properties props = new Properties(); try { Document configDocument = PentahoSystem.getSystemSettings() .getSystemSettingsDocument("smtp-email/email_config.xml"); //$NON-NLS-1$ List properties = configDocument.selectNodes("/email-smtp/properties/*"); //$NON-NLS-1$ Iterator propertyIterator = properties.iterator(); while (propertyIterator.hasNext()) { Node propertyNode = (Node) propertyIterator.next(); String propertyName = propertyNode.getName(); String propertyValue = propertyNode.getText(); props.put(propertyName, propertyValue); } } catch (Exception e) { error(Messages.getString("Email.ERROR_0013_CONFIG_FILE_INVALID"), e); //$NON-NLS-1$ return false; } boolean authenticate = "true".equalsIgnoreCase(props.getProperty("mail.smtp.auth")); //$NON-NLS-1$//$NON-NLS-2$ // Get a Session object Session session; if (authenticate) { 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 (ComponentBase.debug && !props.containsKey("mail.debug")) { //$NON-NLS-1$ session.setDebug(true); } // construct the message MimeMessage msg = new MimeMessage(session); if (from != null) { msg.setFrom(new InternetAddress(from)); } else { // There should be no way to get here error(Messages.getString("Email.ERROR_0012_FROM_NOT_DEFINED")); //$NON-NLS-1$ } if ((to != null) && (to.trim().length() > 0)) { msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false)); } if ((cc != null) && (cc.trim().length() > 0)) { msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc, false)); } if ((bcc != null) && (bcc.trim().length() > 0)) { msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc, false)); } if (subject != null) { msg.setSubject(subject, LocaleHelper.getSystemEncoding()); } EmailAttachment[] emailAttachments = emailAction.getAttachments(); if ((messagePlain != null) && (messageHtml == null) && (emailAttachments.length == 0)) { msg.setText(messagePlain, LocaleHelper.getSystemEncoding()); } else if (emailAttachments.length == 0) { if (messagePlain != null) { msg.setContent(messagePlain, "text/plain; charset=" + LocaleHelper.getSystemEncoding()); //$NON-NLS-1$ } if (messageHtml != null) { msg.setContent(messageHtml, "text/html; charset=" + LocaleHelper.getSystemEncoding()); //$NON-NLS-1$ } } else { // need to create a multi-part message... // create the Multipart and add its parts to it Multipart multipart = new MimeMultipart(); // create and fill the first message part if (messageHtml != null) { // create and fill the first message part MimeBodyPart htmlBodyPart = new MimeBodyPart(); htmlBodyPart.setContent(messageHtml, "text/html; charset=" + LocaleHelper.getSystemEncoding()); //$NON-NLS-1$ multipart.addBodyPart(htmlBodyPart); } if (messagePlain != null) { MimeBodyPart textBodyPart = new MimeBodyPart(); textBodyPart.setContent(messagePlain, "text/plain; charset=" + LocaleHelper.getSystemEncoding()); //$NON-NLS-1$ multipart.addBodyPart(textBodyPart); } for (EmailAttachment element : emailAttachments) { IPentahoStreamSource source = element.getContent(); if (source == null) { error(Messages.getErrorString("Email.ERROR_0015_ATTACHMENT_FAILED")); //$NON-NLS-1$ return false; } DataSource dataSource = new ActivationHelper.PentahoStreamSourceWrapper(source); String attachmentName = element.getName(); if (ComponentBase.debug) { debug(Messages.getString("Email.DEBUG_ADDING_ATTACHMENT", attachmentName)); //$NON-NLS-1$ } // create the second message part MimeBodyPart attachmentBodyPart = new MimeBodyPart(); // attach the file to the message attachmentBodyPart.setDataHandler(new DataHandler(dataSource)); attachmentBodyPart.setFileName(attachmentName); if (ComponentBase.debug) { debug(Messages.getString("Email.DEBUG_ATTACHMENT_SOURCE", dataSource.getName())); //$NON-NLS-1$ } multipart.addBodyPart(attachmentBodyPart); } // add the Multipart to the message msg.setContent(multipart); } msg.setHeader("X-Mailer", EmailComponent.MAILER); //$NON-NLS-1$ msg.setSentDate(new Date()); Transport.send(msg); if (ComponentBase.debug) { debug(Messages.getString("Email.DEBUG_EMAIL_SUCCESS")); //$NON-NLS-1$ } return true; // TODO: persist the content set for a while... } catch (SendFailedException e) { error(Messages.getErrorString("Email.ERROR_0011_SEND_FAILED", to), e); //$NON-NLS-1$ /* Exception ne; MessagingException sfe = e; while ((ne = sfe.getNextException()) != null && ne instanceof MessagingException) { sfe = (MessagingException) ne; error(Messages.getErrorString("Email.ERROR_0011_SEND_FAILED", sfe.toString()), sfe); //$NON-NLS-1$ } */ } catch (AuthenticationFailedException e) { error(Messages.getString("Email.ERROR_0014_AUTHENTICATION_FAILED", to), e); //$NON-NLS-1$ } catch (Throwable e) { error(Messages.getErrorString("Email.ERROR_0011_SEND_FAILED", to), e); //$NON-NLS-1$ } return false; }
From source file:org.pentaho.platform.plugin.action.builtin.SecureFilterComponent.java
License:Open Source License
@Override public boolean validateAction() { Node compDef = getComponentDefinition(); List selNodes = compDef.selectNodes("selections/*"); //$NON-NLS-1$ String inputName = null;/* w w w.ja va2 s. c o m*/ boolean isOk = true; for (Iterator it = selNodes.iterator(); it.hasNext();) { Node node = (Node) it.next(); try { inputName = node.getName(); // Get the Data Node IActionParameter inputParam = getInputParameter(inputName); String filterType = XmlDom4JHelper.getNodeText("@filter", node, null); //$NON-NLS-1$ // BISERVER-149 Changed isOptional param to default to false in order to // enable prompting when no default value AND no selection list is given... // This is also the default that Design Studio presumes. String optionalParm = XmlDom4JHelper.getNodeText("@optional", node, "false"); //$NON-NLS-1$ //$NON-NLS-2$ boolean isOptional = "true".equals(optionalParm); //$NON-NLS-1$ if ("none".equalsIgnoreCase(filterType)) { //$NON-NLS-1$ IActionParameter selectParam = getInputParameter(inputName); String title = XmlDom4JHelper.getNodeText("title", node, inputName); //$NON-NLS-1$ String valueCol = ""; //$NON-NLS-1$ String dispCol = ""; //$NON-NLS-1$ String displayStyle = XmlDom4JHelper.getNodeText("@style", node, null); //$NON-NLS-1$ boolean promptOne = "true" //$NON-NLS-1$ .equalsIgnoreCase(XmlDom4JHelper.getNodeText("@prompt-if-one-value", node, "false")); //$NON-NLS-1$ //$NON-NLS-2$ if ("hidden".equals(displayStyle)) { //$NON-NLS-1$ hiddenList.add(new SelEntry(inputParam, selectParam, valueCol, dispCol, title, displayStyle, promptOne, isOptional)); } else { selList.add(new SelEntry(inputParam, selectParam, valueCol, dispCol, title, displayStyle, promptOne, isOptional)); } } else { Node filterNode = node.selectSingleNode("filter"); //$NON-NLS-1$ IActionParameter selectParam = getInputParameter(filterNode.getText().trim()); String valueCol = XmlDom4JHelper.getNodeText("@value-col-name", filterNode, null); //$NON-NLS-1$ String dispCol = XmlDom4JHelper.getNodeText("@display-col-name", filterNode, null); //$NON-NLS-1$ String title = XmlDom4JHelper.getNodeText("title", node, null); //$NON-NLS-1$ String displayStyle = XmlDom4JHelper.getNodeText("@style", node, null); //$NON-NLS-1$ boolean promptOne = "true" //$NON-NLS-1$ .equalsIgnoreCase(XmlDom4JHelper.getNodeText("@prompt-if-one-value", node, "false")); //$NON-NLS-1$ //$NON-NLS-2$ selList.add(new SelEntry(inputParam, selectParam, valueCol, dispCol, title, displayStyle, promptOne, isOptional)); } } catch (Exception e) { // Catch the exception to let us test all // the params isOk = false; error(Messages.getInstance().getErrorString("SecureFilterComponent.ERROR_0001_PARAM_MISSING", //$NON-NLS-1$ inputName)); } } return (isOk); }
From source file:org.pentaho.platform.plugin.adhoc.AdhocContentGenerator.java
License:Open Source License
public void createContent(OutputStream outputStream, IContentItem contentItem) throws Exception { IParameterProvider requestParams = parameterProviders.get(IParameterProvider.SCOPE_REQUEST); IParameterProvider pathParams = parameterProviders.get("path"); //$NON-NLS-1$ String responseEncoding = PentahoSystem.getSystemSetting("web-service-encoding", "utf-8"); //$NON-NLS-1$ //$NON-NLS-2$ PentahoSystem.systemEntryPoint();// w w w . jav a 2s.com try { boolean wrapWithSoap = "false".equals(requestParams.getParameter("ajax")); //$NON-NLS-1$ //$NON-NLS-2$ String solutionName = requestParams.getStringParameter("solution", null); //$NON-NLS-1$ String actionPath = requestParams.getStringParameter("path", null); //$NON-NLS-1$ String actionName = requestParams.getStringParameter("action", null); //$NON-NLS-1$ String component = requestParams.getStringParameter("component", null); //$NON-NLS-1$ String content = null; try { content = getPayloadAsString(pathParams); } 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()), //$NON-NLS-1$ outputStream, responseEncoding, false); } 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), outputStream, responseEncoding, false); } 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", actionPath); //$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 = requestParams; } HttpServletResponse response = (HttpServletResponse) pathParams.getParameter("httpresponse"); //$NON-NLS-1$ if (!"generatePreview".equals(component)) { //$NON-NLS-1$ contentItem.setMimeType("text/xml"); //$NON-NLS-1$ response.setCharacterEncoding(LocaleHelper.getSystemEncoding()); } // PentahoHttpSession userSession = new PentahoHttpSession( // request.getRemoteUser(), request.getSession(), // request.getLocale() ); // 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(component, parameterProvider, outputStream, wrapWithSoap, contentItem); } 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), outputStream, responseEncoding, false); } catch (AdhocWebServiceException ex) { String msg = ex.getLocalizedMessage(); error(msg, ex); XmlDom4JHelper.saveDom(WebServiceUtil.createErrorDocument(msg), outputStream, responseEncoding, false); } catch (PentahoMetadataException ex) { String msg = ex.getLocalizedMessage(); error(msg, ex); XmlDom4JHelper.saveDom(WebServiceUtil.createErrorDocument(msg), outputStream, responseEncoding, false); } catch (PentahoAccessControlException ex) { String msg = ex.getLocalizedMessage(); error(msg, ex); XmlDom4JHelper.saveDom(WebServiceUtil.createErrorDocument(msg), outputStream, responseEncoding, false); } finally { PentahoSystem.systemExitPoint(); } if (ServletBase.debug) { debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_END")); //$NON-NLS-1$ } }
From source file:org.pentaho.platform.plugin.adhoc.AdhocWebService.java
License:Open Source License
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { String responseEncoding = PentahoSystem.getSystemSetting("web-service-encoding", "utf-8"); request.setCharacterEncoding("UTF-8"); PentahoSystem.systemEntryPoint();/*from w w w. jav a2 s . c o m*/ OutputStream outputStream = response.getOutputStream(); try { boolean wrapWithSoap = "false".equals(request.getParameter("ajax")); //$NON-NLS-1$ //$NON-NLS-2$ String solutionName = request.getParameter("solution"); //$NON-NLS-1$ String actionPath = request.getParameter("path"); //$NON-NLS-1$ String actionName = request.getParameter("action"); //$NON-NLS-1$ String component = request.getParameter("component"); //$NON-NLS-1$ String content = getPayloadAsString(request); IParameterProvider parameterProvider = null; HashMap parameters = new HashMap(); if (!StringUtils.isEmpty(content)) { 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(); parameters.put("solution", solutionName); //$NON-NLS-1$ parameters.put("path", actionPath); //$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, outputStream, responseEncoding, userSession, wrapWithSoap); } catch (IOException ioEx) { String msg = Messages.getInstance() .getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"); //$NON-NLS-1$ error(msg, ioEx); response.setCharacterEncoding(responseEncoding); XmlDom4JHelper.saveDom(WebServiceUtil.createErrorDocument(msg), outputStream, responseEncoding, true); } catch (XmlParseException e) { String msg = Messages.getInstance() .getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"); //$NON-NLS-1$ error(msg, e); response.setCharacterEncoding(responseEncoding); XmlDom4JHelper.saveDom(WebServiceUtil.createErrorDocument(msg), outputStream, responseEncoding, true); } catch (Exception ex) { String msg = ex.getLocalizedMessage(); error(msg, ex); response.setCharacterEncoding(responseEncoding); XmlDom4JHelper.saveDom(WebServiceUtil.createErrorDocument(msg), outputStream, responseEncoding, true); } finally { PentahoSystem.systemExitPoint(); } if (ServletBase.debug) { debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_END")); //$NON-NLS-1$ } }
From source file:org.pentaho.platform.plugin.adhoc.AdhocWebServiceInteractXml.java
License:Open Source License
public static Document convertXml(final Document reportXml) { // get the list of headers List<String> headerList = new ArrayList<String>(); List<?> nodes = reportXml.selectNodes("/report/groupheader/@name"); //$NON-NLS-1$ // find all the unique group header names Iterator<?> it = nodes.iterator(); Attribute attr;/* w w w . java2s. c o m*/ String name; while (it.hasNext()) { // we only need to go until we get the first duplicate attr = (Attribute) it.next(); name = attr.getText(); if (!"dummy".equals(name)) { //$NON-NLS-1$ if (!headerList.contains(name)) { headerList.add(name); System.out.println(name); } else { break; } } } String headerNames[] = new String[headerList.size()]; String headerValues[] = new String[headerList.size()]; Element headerNodes[] = new Element[headerList.size()]; String columnHeaders[] = new String[0]; Element columnHeaderNodes[] = new Element[0]; headerList.toArray(headerNames); for (int idx = 0; idx < headerValues.length; idx++) { headerValues[idx] = ""; //$NON-NLS-1$ } Document reportDoc = DocumentHelper.createDocument(); Element reportNode = DocumentHelper.createElement("report"); //$NON-NLS-1$ reportDoc.setRootElement(reportNode); // process the top-level nodes nodes = reportXml.selectNodes("/report/*"); //$NON-NLS-1$ Node node; // go thru all the nodes it = nodes.iterator(); while (it.hasNext()) { node = (Node) it.next(); name = node.getName(); if ("groupheader".equals(name)) { //$NON-NLS-1$ // process the group headers // get the group header name String headerName = node.selectSingleNode("@name").getText(); //$NON-NLS-1$ if (!"dummy".equals(headerName)) { //$NON-NLS-1$ // find the header index String headerValue = node.selectSingleNode("element[1]").getText();//$NON-NLS-1$ int headerIdx = -1; for (int idx = 0; idx < headerNames.length; idx++) { if (headerNames[idx].equals(headerName)) { headerIdx = idx; break; } } if (!headerValues[headerIdx].equals(headerValue)) { // this is a new header value headerValues[headerIdx] = headerValue; // find the parent node Element parentNode; if (headerIdx == 0) { parentNode = reportNode; } else { parentNode = headerNodes[headerIdx - 1]; } // create a group header node for this Element headerNode = DocumentHelper.createElement("groupheader");//$NON-NLS-1$ parentNode.add(headerNode); headerNodes[headerIdx] = headerNode; // create the name attribute attr = DocumentHelper.createAttribute(headerNode, "name", headerName);//$NON-NLS-1$ headerNode.add(attr); // create the value node Element elementNode = DocumentHelper.createElement("element");//$NON-NLS-1$ headerNode.add(elementNode); attr = DocumentHelper.createAttribute(elementNode, "name", headerName);//$NON-NLS-1$ elementNode.add(attr); elementNode.setText(headerValue); } } // see if there are any column headers List<?> elements = node.selectNodes("element");//$NON-NLS-1$ if (elements.size() == 0) { elements = node.selectNodes("band/element");//$NON-NLS-1$ } if (elements.size() > 1) { // there are column headers here, get them and store them for the next set of rows columnHeaders = new String[elements.size() - 1]; columnHeaderNodes = new Element[elements.size() - 1]; for (int idx = 1; idx < elements.size(); idx++) { columnHeaders[idx - 1] = ((Element) elements.get(idx)).getText(); } } } else if ("items".equals(name)) {//$NON-NLS-1$ // process items (rows) // get the parent node, this should always be the last one on the list Element parentNode; if (headerNodes.length == 0) { parentNode = reportNode; } else { parentNode = headerNodes[headerNodes.length - 1]; } // create the items node Element itemsNode = DocumentHelper.createElement("items");//$NON-NLS-1$ parentNode.add(itemsNode); // create the headers node Element headersNode = DocumentHelper.createElement("headers");//$NON-NLS-1$ itemsNode.add(headersNode); // create the rows node Element itemBandsNode = DocumentHelper.createElement("itembands");//$NON-NLS-1$ itemsNode.add(itemBandsNode); for (int idx = 0; idx < columnHeaders.length; idx++) { Element headerNode = DocumentHelper.createElement("header");//$NON-NLS-1$ headerNode.setText(columnHeaders[idx]); headersNode.add(headerNode); columnHeaderNodes[idx] = headerNode; } // now copy the item bands over List<?> itembands = node.selectNodes("itemband");//$NON-NLS-1$ Iterator<?> bands = itembands.iterator(); boolean first = true; while (bands.hasNext()) { Element itemband = (Element) bands.next(); Element itemBandNode = DocumentHelper.createElement("itemband");//$NON-NLS-1$ itemBandsNode.add(itemBandNode); List<?> elementList = itemband.selectNodes("element");//$NON-NLS-1$ Iterator<?> elements = elementList.iterator(); int idx = 0; while (elements.hasNext()) { Element element = (Element) elements.next(); Element elementNode = DocumentHelper.createElement("element");//$NON-NLS-1$ itemBandNode.add(elementNode); elementNode.setText(element.getText()); name = element.selectSingleNode("@name").getText();//$NON-NLS-1$ if (name.endsWith("Element")) {//$NON-NLS-1$ name = name.substring(0, name.length() - "Element".length());//$NON-NLS-1$ } attr = DocumentHelper.createAttribute(elementNode, "name", name);//$NON-NLS-1$ elementNode.add(attr); if (first) { // copy the item name over to the column header attr = DocumentHelper.createAttribute(columnHeaderNodes[idx], "name", name);//$NON-NLS-1$ columnHeaderNodes[idx].add(attr); } idx++; } first = false; } } } return reportDoc; }
From source file:org.pentaho.platform.repository.subscription.SubscriptionEmailContent.java
License:Open Source License
public void setup() { try {//from w w w . ja v a2s . c o m Document configDocument = PentahoSystem.getSystemSettings() .getSystemSettingsDocument("smtp-email/email_config.xml"); //$NON-NLS-1$ List properties = configDocument.selectNodes("/email-smtp/properties/*"); //$NON-NLS-1$ Iterator propertyIterator = properties.iterator(); while (propertyIterator.hasNext()) { Node propertyNode = (Node) propertyIterator.next(); String propertyName = propertyNode.getName(); String propertyValue = propertyNode.getText(); props.put(propertyName, propertyValue); } props.put("mail.from.default", PentahoSystem.getSystemSetting("smtp-email/email_config.xml", "mail.from.default", "")); } catch (Exception e) { logger.error("Email.ERROR_0013_CONFIG_FILE_INVALID", e); //$NON-NLS-1$ } }
From source file:org.pentaho.platform.web.servlet.AdhocWebService.java
License:Open Source License
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { PentahoSystem.systemEntryPoint();//ww w . j av a 2 s . co m OutputStream outputStream = response.getOutputStream(); try { boolean wrapWithSoap = "false".equals(request.getParameter("ajax")); //$NON-NLS-1$ //$NON-NLS-2$ String solutionName = request.getParameter("solution"); //$NON-NLS-1$ String actionPath = request.getParameter("path"); //$NON-NLS-1$ String actionName = request.getParameter("action"); //$NON-NLS-1$ String component = request.getParameter("component"); //$NON-NLS-1$ String content = null; try { content = getPayloadAsString(request); } catch (IOException ioEx) { String msg = Messages .getErrorString("AdhocWebService.ERROR_0006_FAILED_TO_GET_PAYLOAD_FROM_REQUEST"); //$NON-NLS-1$ error(msg, ioEx); WebServiceUtil.writeString(outputStream, WebServiceUtil.getErrorXml(msg + " " + ioEx.getLocalizedMessage()), false); //$NON-NLS-1$ } 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.getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"); //$NON-NLS-1$ error(msg, e); WebServiceUtil.writeString(response.getOutputStream(), WebServiceUtil.getErrorXml(msg), false); } 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", actionPath); //$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(LocaleHelper.getSystemEncoding()); } // 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, outputStream, userSession, wrapWithSoap); } catch (IOException ioEx) { String msg = Messages.getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"); //$NON-NLS-1$ error(msg, ioEx); WebServiceUtil.writeString(outputStream, WebServiceUtil.getErrorXml(msg), false); } catch (AdhocWebServiceException ex) { String msg = ex.getLocalizedMessage(); error(msg, ex); WebServiceUtil.writeString(outputStream, WebServiceUtil.getErrorXml(msg), false); } catch (PentahoMetadataException ex) { String msg = ex.getLocalizedMessage(); error(msg, ex); WebServiceUtil.writeString(outputStream, WebServiceUtil.getErrorXml(msg), false); } catch (PentahoAccessControlException ex) { String msg = ex.getLocalizedMessage(); error(msg, ex); WebServiceUtil.writeString(outputStream, WebServiceUtil.getErrorXml(msg), false); } finally { PentahoSystem.systemExitPoint(); } if (ServletBase.debug) { debug(Messages.getString("HttpWebService.DEBUG_WEB_SERVICE_END")); //$NON-NLS-1$ } }
From source file:org.pentaho.platform.web.servlet.AnalysisViewService.java
License:Open Source License
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { 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 ww . ja v a2 s .c o m } PentahoSystem.systemEntryPoint(); try { boolean wrapWithSoap = "false".equals(request.getParameter("ajax")); //$NON-NLS-1$ //$NON-NLS-2$ String solutionName = request.getParameter("solution"); //$NON-NLS-1$ String actionPath = request.getParameter("path"); //$NON-NLS-1$ String actionName = request.getParameter("action"); //$NON-NLS-1$ String content = null; try { content = getPayloadAsString(request); } catch (IOException ioEx) { String msg = Messages .getErrorString("AdhocWebService.ERROR_0006_FAILED_TO_GET_PAYLOAD_FROM_REQUEST"); //$NON-NLS-1$ error(msg, ioEx); WebServiceUtil.writeString(response.getOutputStream(), WebServiceUtil.getErrorXml(msg + " " + ioEx.getLocalizedMessage()), false); //$NON-NLS-1$ } 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.getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"); //$NON-NLS-1$ error(msg, e); WebServiceUtil.writeString(response.getOutputStream(), WebServiceUtil.getErrorXml(msg), false); } 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", actionPath); //$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(LocaleHelper.getSystemEncoding()); } // 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.getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"); //$NON-NLS-1$ error(msg, ioEx); WebServiceUtil.writeString(response.getOutputStream(), WebServiceUtil.getErrorXml(msg), false); } catch (PentahoSystemException ex) { String msg = ex.getLocalizedMessage(); error(msg, ex); WebServiceUtil.writeString(response.getOutputStream(), WebServiceUtil.getErrorXml(msg), false); } catch (PentahoAccessControlException ex) { String msg = ex.getLocalizedMessage(); error(msg, ex); WebServiceUtil.writeString(response.getOutputStream(), WebServiceUtil.getErrorXml(msg), false); } finally { PentahoSystem.systemExitPoint(); } }