/** * @param componentDefinition * @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. }
public static String getToXml(Map<String, String> paramMap) { Set localSet = paramMap.entrySet(); Iterator localIterator = localSet.iterator(); Document localDocument = DocumentHelper.createDocument(); localDocument.setXMLEncoding("GBK"); Element localElement1 = localDocument.addElement("root"); while (localIterator.hasNext()) { Map.Entry localObject = (Map.Entry) localIterator.next(); Element localElement2 = localElement1.addElement("keyValue"); Element localElement3 = localElement2.addElement("key"); localElement3.addCDATA(((String) ((Map.Entry) localObject).getKey()).toString()); Element localElement4 = localElement2.addElement("value"); localElement4.addCDATA(((String) ((Map.Entry) localObject).getValue()).toString()); } Object localObject = localDocument.asXML(); return (String) localObject; }
private Element addTextElement(Element parent, String name, String text, boolean escape) { Element element = parent.addElement(name); if (text != null) { if (escape) { element.addCDATA(text); } else { element.setText(text); } } return element; }
@Override // Implementation methods // ------------------------------------------------------------------------- protected Document parseDocument() throws DocumentException, IOException, XmlPullParserException { DocumentFactory df = getDocumentFactory(); Document document = df.createDocument(); Element parent = null; XmlPullParser pp = getXPPParser(); pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); while (true) { int type = pp.nextToken(); switch (type) { case XmlPullParser.PROCESSING_INSTRUCTION: { String text = pp.getText(); int loc = text.indexOf(' '); if (loc >= 0) { String target = text.substring(0, loc); String txt = text.substring(loc + 1); document.addProcessingInstruction(target, txt); } else { document.addProcessingInstruction(text, ""); } break; } case XmlPullParser.COMMENT: { if (parent != null) { parent.addComment(pp.getText()); } else { document.addComment(pp.getText()); } break; } case XmlPullParser.CDSECT: { if (parent != null) { parent.addCDATA(pp.getText()); } else { String msg = "Cannot have text content outside of the " + "root document"; throw new DocumentException(msg); } break; } case XmlPullParser.END_DOCUMENT: return document; case XmlPullParser.START_TAG: { QName qname = (pp.getPrefix() == null) ? df.createQName(pp.getName(), pp.getNamespace()) : df.createQName(pp.getName(), pp.getPrefix(), pp.getNamespace()); Element newElement = df.createElement(qname); int nsStart = pp.getNamespaceCount(pp.getDepth() - 1); int nsEnd = pp.getNamespaceCount(pp.getDepth()); for (int i = nsStart; i < nsEnd; i++) { if (pp.getNamespacePrefix(i) != null) { newElement.addNamespace(pp.getNamespacePrefix(i), pp.getNamespaceUri(i)); } } for (int i = 0; i < pp.getAttributeCount(); i++) { QName qa = (pp.getAttributePrefix(i) == null) ? df.createQName(pp.getAttributeName(i)) : df.createQName( pp.getAttributeName(i), pp.getAttributePrefix(i), pp.getAttributeNamespace(i)); newElement.addAttribute(qa, pp.getAttributeValue(i)); } if (parent != null) { parent.add(newElement); } else { document.add(newElement); } parent = newElement; break; } case XmlPullParser.END_TAG: { if (parent != null) { parent = parent.getParent(); } break; } case XmlPullParser.ENTITY_REF: case XmlPullParser.TEXT: { String text = pp.getText(); if (parent != null) { parent.addText(text); } else { String msg = "Cannot have text content outside of the " + "root document"; throw new DocumentException(msg); } break; } default: break; } } }
private static Element createSoapElement(String name, List value) { Element element = new DefaultElement(name); element.addCDATA(value.toString()); return element; }
private static Element createSoapFaultElement(List messages) { Element faultElement = new DefaultElement("SOAP-ENV:Fault"); // TODO mlowery begin hack: copied in getFirstError code from MessageFormatter // to avoid needing an IPentahoSession String message = null; String errorStart = PentahoMessenger.getUserString("ERROR"); // $NON-NLS-1$ int pos = errorStart.indexOf('{'); if (pos != -1) { errorStart = errorStart.substring(0, pos); } Iterator msgIterator = messages.iterator(); while (msgIterator.hasNext()) { String msg = (String) msgIterator.next(); if (msg.indexOf(errorStart) == 0) { message = msg; } } // TODO mlowery end hack if (message == null) { message = Messages.getInstance() .getErrorString("SoapHelper.ERROR_0001_UNKNOWN_ERROR"); // $NON-NLS-1$ } // Envelope envelope = new Envelope(); // Fault fault = new Fault( ); // TODO: Generate the following message using the envelope and fault objects // TODO determine if this is a reciever or a sender problem by examining // the error code boolean senderFault = (message.indexOf("SolutionEngine.ERROR_0002") != -1) || //$NON-NLS-1$ // solution not specifed (message.indexOf("SolutionEngine.ERROR_0003") != -1) || //$NON-NLS-1$ // Path not specifeid (message.indexOf("SolutionEngine.ERROR_0004") != -1) || //$NON-NLS-1$ // Action not specified (message.indexOf("SolutionEngine.ERROR_0005") != -1); // $NON-NLS-1$ // Action not found // send the error code // TODO parse out the error code faultElement .addElement("SOAP-ENV:Fault") .addElement("SOAP-ENV:Subcode") .addElement("SOAP-ENV:Value") .addCDATA(message); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (senderFault) { faultElement .addElement("SOAP-ENV:faultactor") .setText("SOAP-ENV:Client"); // $NON-NLS-1$ //$NON-NLS-2$ } else { faultElement .addElement("SOAP-ENV:faultactor") .setText("SOAP-ENV:Server"); // $NON-NLS-1$ //$NON-NLS-2$ } Element faultTextElement = faultElement.addElement("SOAP-ENV:faultstring").addElement("SOAP-ENV:Text"); faultTextElement.addAttribute("xml:lang", LocaleHelper.getDefaultLocale().toString()); faultTextElement.addCDATA(message); Element detailElement = faultElement.addElement("SOAP-ENV:Detail"); Iterator messageIterator = messages.iterator(); while (messageIterator.hasNext()) { detailElement .addElement("message") .addAttribute("name", "trace") .addCDATA((String) messageIterator.next()); } return faultElement; }
/** * @param document * @param props * @return */ private static Document updateDocument(final Document document, final HashMap props) { try { Element componentDefinition = null; Element actionOutput = null; Element actionSequenceOutput = null; Node actionSequence = document.selectSingleNode("/action-sequence"); // $NON-NLS-1$ if (actionSequence == null) { throw new InvalidDocumentException( Messages.getInstance() .getErrorString("ANALYSISSAVER.ERROR_0004_INVALID_ORIGIN_DOCUMENT")); // $NON-NLS-1$ } Element asElement = ((Element) actionSequence); Node title = null; String propertyTitle = (String) props.get(AnalysisSaver.TITLE_NODE_NAME); title = asElement.selectSingleNode(AnalysisSaver.TITLE_NODE_NAME); if ((title == null) && (propertyTitle != null)) { title = asElement.addElement(AnalysisSaver.TITLE_NODE_NAME); } if ((title != null) && (propertyTitle != null)) { // remove existing text if it's there title.setText(""); // $NON-NLS-1$ ((Element) title).addCDATA(propertyTitle); // adds CDATA } // Next, we need to retrieve the PivotViewComponent action and // process/update it.. there could possibly be more than one // PivotViewComponent in an action sequence, however, we have no idea // how to figure out which one to process, so we default to picking the last one we found. componentDefinition = (Element) document.selectSingleNode( "//action-definition[component-name='PivotViewComponent']/component-definition"); //$NON-NLS-1$ if (componentDefinition == null) { throw new InvalidDocumentException( Messages.getInstance() .getErrorString("ANALYSISSAVER.ERROR_0005_INVALID_NO_PIVOT_ACTION")); // $NON-NLS-1$ } AnalysisSaver.updateComponent(componentDefinition, props); // Get the action's root action-output node, in case we need to add the // appropriate outputs for the pivot view... actionOutput = (Element) document.selectSingleNode( "//action-definition[component-name='PivotViewComponent']/action-outputs"); //$NON-NLS-1$ AnalysisSaver.updateOutput(actionOutput, props); // Get the action's root action sequence output node, in case we need to add the // appropriate outputs for the pivot view... actionSequenceOutput = (Element) document.selectSingleNode("//action-sequence/outputs"); // $NON-NLS-1$ AnalysisSaver.updateOutput(actionSequenceOutput, props); } catch (Exception e) { e.printStackTrace(); } return document; }