List of usage examples for org.dom4j DocumentHelper parseText
public static Document parseText(String text) throws DocumentException
parseText
parses the given text as an XML document and returns the newly created Document.
From source file:org.orbeon.oxf.main.OPS.java
License:Open Source License
public void init() { // Initialize a basic logging configuration until the resource manager is setup LoggerFactory.initBasicLogger();//w w w. j a va 2 s .co m // 2. Initialize resource manager // Resources are first searched in a file hierarchy, then from the classloader final Map<String, Object> props = new LinkedHashMap<String, Object>(); props.put("oxf.resources.factory", "org.orbeon.oxf.resources.PriorityResourceManagerFactory"); if (resourceManagerSandbox != null) { // Use a sandbox props.put("oxf.resources.filesystem.sandbox-directory", resourceManagerSandbox); } props.put("oxf.resources.priority.1", "org.orbeon.oxf.resources.FilesystemResourceManagerFactory"); props.put("oxf.resources.priority.2", "org.orbeon.oxf.resources.ClassLoaderResourceManagerFactory"); if (logger.isInfoEnabled()) logger.info("Initializing Resource Manager with: " + props); ResourceManagerWrapper.init(props); // 3. Initialize properties with default properties file. Properties.init(Properties.DEFAULT_PROPERTIES_URI); // 4. Initialize log4j (using the properties this time) LoggerFactory.initLogger(); // 5. Build processor definition from command-line parameters if (otherArgs != null && otherArgs.length == 1) { // Assume the pipeline processor and a config input processorDefinition = new ProcessorDefinition(); processorDefinition.setName(new QName("pipeline", XMLConstants.OXF_PROCESSORS_NAMESPACE)); final String configURL; if (!NetUtils.urlHasProtocol(otherArgs[0])) { // URL is considered relative to current directory try { // Create absolute URL, and switch to the oxf: protocol String fileURL = new URL(new File(".").toURI().toURL(), otherArgs[0]).toExternalForm(); configURL = "oxf:" + fileURL.substring(fileURL.indexOf(':') + 1); } catch (MalformedURLException e) { throw new OXFException(e); } } else { configURL = otherArgs[0]; } processorDefinition.addInput("config", configURL); // Add additional inputs if any for (int i = 0; inputs != null && i < inputs.length; i++) { String input = inputs[i]; int iEqual = input.indexOf("="); if (iEqual <= 0 || iEqual >= input.length() - 1) { throw new OXFException("Input \"" + input + "\" doesn't follow the syntax <name>=<url>"); } String inputName = input.substring(0, iEqual); String inputValue = input.substring(iEqual + 1); if (inputValue.startsWith("<")) { // XML document try { processorDefinition.addInput(inputName, DocumentHelper.parseText(inputValue).getRootElement()); } catch (DocumentException e) { throw new OXFException(e); } } else { // URL processorDefinition.addInput(inputName, inputValue); } } } else { throw new OXFException("No main processor definition found."); } }
From source file:org.pentaho.actionsequence.dom.actions.ActionDefinition.java
License:Open Source License
/** * Renames the named action input. No operation is performed if the input does not exist. Any inputs defined in the * component definition section that refer to the input using the {oldName} parameter reference are also modified to * refer to {newName}./*from ww w . j a v a 2 s.co m*/ * * @param oldName * the name of the input to be renamed. * @param newName * the new input name. */ public void renameInput(String oldName, String newName) { if (!oldName.equals(newName)) { ActionInput actionInput = getInputParam(oldName); if (actionInput != null) { Element componentDefElement = actionDefElement.element(ActionSequenceDocument.COMPONENT_DEF_NAME); try { if (componentDefElement != null) { String xmlString = componentDefElement.asXML(); if (xmlString.indexOf("{" + oldName + "}") >= 0) { //$NON-NLS-1$ //$NON-NLS-2$ xmlString = xmlString.replaceAll("\\{" + oldName + "\\}", "{" + newName + "}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ Document document = DocumentHelper.parseText(xmlString); actionDefElement.remove(componentDefElement); actionDefElement.add(document.getRootElement()); } } actionInput.setName(newName); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:org.pentaho.actionsequence.dom.actions.JFreeReportGenAction.java
License:Open Source License
private IActionInput getComponentValue(String elementName) { IActionInput value = getInput(elementName); try {/*from w w w.j a va 2 s.com*/ if (value == ActionInputConstant.NULL_INPUT) { value = getInput(COMPONENT_SETTINGS_ELEMENT); Document doc = DocumentHelper.parseText(value.getStringValue()); Node componentNode = doc.getRootElement(); value = new ActionInputConstant(componentNode.selectSingleNode(elementName).getText(), this.actionParameterMgr); } } catch (Exception e) { value = ActionInputConstant.NULL_INPUT; } return value; }
From source file:org.pentaho.actionsequence.dom.actions.MQLAction.java
License:Open Source License
public IActionInput getQuery() { IActionInput query = super.getQuery(); // The following condition covers an alternative way to store the mql // within the action definition. This class does not use this method when // writing to the dom. if (query == IActionInput.NULL_INPUT) { Element element = getComponentDefElement(MQL_ELEMENT); if (element != null) { try { query = new ActionInputConstant( prettyPrint(DocumentHelper.parseText(element.asXML())).getRootElement().asXML(), actionParameterMgr); } catch (DocumentException e) { query = new ActionInputConstant(element.asXML(), actionParameterMgr); }//w w w.j av a 2 s. co m } } return query; }
From source file:org.pentaho.actionsequence.dom.actions.MQLAction.java
License:Open Source License
private Document prettyPrint(Document document) { try {//from ww w .j a v a2s . c o m OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(document.getXMLEncoding()); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); // XMLWriter has a bug that is avoided if we reparse the document // prior to calling XMLWriter.write() writer.write(DocumentHelper.parseText(document.asXML())); writer.close(); document = DocumentHelper.parseText(stringWriter.toString()); } catch (Exception e) { e.printStackTrace(); return (null); } return (document); }
From source file:org.pentaho.actionsequence.dom.ActionSequenceDocument.java
License:Open Source License
public static Document prettyPrint(Document document) { try {//ww w. ja v a 2s.co m OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(document.getXMLEncoding()); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); // XMLWriter has a bug that is avoided if we reparse the document // prior to calling XMLWriter.write() writer.write(DocumentHelper.parseText(document.asXML())); writer.close(); document = DocumentHelper.parseText(stringWriter.toString()); } catch (Exception e) { e.printStackTrace(); return (null); } return (document); }
From source file:org.pentaho.actionsequence.dom.ActionSequenceDocument.java
License:Open Source License
public String toString() { String string = null;//from w ww. j av a 2 s . c o m try { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(document.getXMLEncoding()); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); // XMLWriter has a bug that is avoided if we reparse the document // prior to calling XMLWriter.write() writer.write(DocumentHelper.parseText(document.asXML())); writer.close(); Document tempDocument = DocumentHelper.parseText(stringWriter.toString()); string = tempDocument.getRootElement().asXML(); } catch (Exception e) { string = super.toString(); } return string; }
From source file:org.pentaho.actionsequence.dom.ActionSequenceResource.java
License:Open Source License
public void setXml(String xml) throws DocumentException { setType(XML_RESOURCE_TYPE);//from ww w.ja v a 2 s . co m Document document = DocumentHelper.parseText(xml); Element locationElement = (Element) ioElement.selectSingleNode(XML_RESOURCE_TYPE + "/" + RES_LOCATION_NAME); //$NON-NLS-1$ List elements = locationElement.elements(); for (Object obj : elements) { ((Element) obj).detach(); } locationElement.add(document.getRootElement()); }
From source file:org.pentaho.agilebi.spoon.perspective.AgileBiModelerPerspective.java
License:Open Source License
public void exportSchema() { try {/*from w ww. j av a2s. com*/ if (this.model.isValid()) { this.model.getWorkspaceHelper().populateDomain(this.model); LogicalModel lModel = this.model.getLogicalModel(ModelerPerspective.ANALYSIS); FileDialog fileDialog = new FileDialog(Spoon.getInstance().getShell(), SWT.SAVE); String[] theExtensions = { "*.xml" }; fileDialog.setFilterExtensions(theExtensions); String theFile = fileDialog.open(); if (theFile != null) { MondrianModelExporter exporter = new MondrianModelExporter(lModel, LocalizedString.DEFAULT_LOCALE); String mondrianSchema = exporter.createMondrianModelXML(); logger.info(mondrianSchema); org.dom4j.Document schemaDoc = DocumentHelper.parseText(mondrianSchema); byte schemaBytes[] = schemaDoc.asXML().getBytes(); File modelFile = new File(theFile); OutputStream out = new FileOutputStream(modelFile); out.write(schemaBytes); out.flush(); out.close(); } } else { StringBuffer validationErrors = new StringBuffer(); for (String msg : this.model.getValidationMessages()) { validationErrors.append(msg); validationErrors.append("\n"); logger.info(msg); } MessageDialog.openError(Spoon.getInstance().getShell(), "", validationErrors.toString()); } } catch (Exception e) { logger.error("Error exporting Schema", e); MessageDialog.openError(Spoon.getInstance().getShell(), "", e.getMessage()); } }
From source file:org.pentaho.agilebi.spoon.perspective.AgileBiModelerPerspectiveController.java
License:Open Source License
public void exportSchema() { try {/*from w ww.j a v a 2 s. c o m*/ ModelerWorkspace model = this.meta.getController().getModel(); if (model.isValid()) { model.getWorkspaceHelper().populateDomain(model); LogicalModel lModel = model.getLogicalModel(ModelerPerspective.ANALYSIS); FileDialog fileDialog = new FileDialog(Spoon.getInstance().getShell(), SWT.SAVE); String[] theExtensions = { "*.xml" }; fileDialog.setFilterExtensions(theExtensions); String theFile = fileDialog.open(); if (theFile != null) { MondrianModelExporter exporter = new MondrianModelExporter(lModel, LocalizedString.DEFAULT_LOCALE); String mondrianSchema = exporter.createMondrianModelXML(); logger.info(mondrianSchema); org.dom4j.Document schemaDoc = DocumentHelper.parseText(mondrianSchema); byte schemaBytes[] = schemaDoc.asXML().getBytes(); File modelFile = new File(theFile); OutputStream out = new FileOutputStream(modelFile); out.write(schemaBytes); out.flush(); out.close(); } } else { StringBuffer validationErrors = new StringBuffer(); for (String msg : model.getValidationMessages()) { validationErrors.append(msg); validationErrors.append("\n"); logger.info(msg); } MessageDialog.openError(Spoon.getInstance().getShell(), "", validationErrors.toString()); } } catch (Exception e) { logger.error("Error exporting schema", e); MessageDialog.openError(Spoon.getInstance().getShell(), "", e.getMessage()); } }