示例#1
0
    protected ConfigSaveState updatePartial(String xmlPartial, final String md5) throws Exception {
      LOGGER.debug("[Config Save] Updating partial");
      org.dom4j.Document document = documentRoot();
      Element root = document.getRootElement();

      Element configElement = ((Element) root.selectSingleNode(getXpath()));
      List nodes = configElement.getParent().content();
      int index = nodes.indexOf(configElement);

      LOGGER.debug("[Config Save] Converting to object");
      Element newConfigElement = reader.read(new StringReader(xmlPartial)).getRootElement();
      nodes.set(index, newConfigElement);

      return saveConfig(document.asXML(), md5);
    }
示例#2
0
  public static org.dom4j.Document cleanXML(org.dom4j.Document doc, String stylesheetURL) {
    try {
      final org.dom4j.Element element = doc.getRootElement();
      final String systemId = Dom4jUtils.makeSystemId(element);
      // The date to clean
      final DOMGenerator dataToClean =
          new DOMGenerator(doc, "clean xml", DOMGenerator.ZeroValidity, systemId);
      // The stylesheet
      URLGenerator stylesheetGenerator = new URLGenerator(stylesheetURL);
      // The transformation
      // Define the name of the processor (this is a QName)
      final QName processorName = new QName("xslt", XMLConstants.OXF_PROCESSORS_NAMESPACE);
      // Get a factory for this processor
      final ProcessorFactory processorFactory = ProcessorFactoryRegistry.lookup(processorName);
      if (processorFactory == null)
        throw new OXFException(
            "Cannot find processor factory with name '"
                + processorName.getNamespacePrefix()
                + ":"
                + processorName.getName()
                + "'");

      // Create processor
      final Processor xsltProcessor = processorFactory.createInstance();
      // Where the result goes
      DOMSerializer transformationOutput = new DOMSerializer();

      // Connect
      PipelineUtils.connect(stylesheetGenerator, "data", xsltProcessor, "config");
      PipelineUtils.connect(dataToClean, "data", xsltProcessor, "data");
      PipelineUtils.connect(xsltProcessor, "data", transformationOutput, "data");

      // Run the pipeline
      // Candidate for Scala withPipelineContext
      final PipelineContext pipelineContext = new PipelineContext();
      boolean success = false;
      try {
        transformationOutput.start(pipelineContext);
        success = true;
        return transformationOutput.getDocument(pipelineContext);
      } finally {
        pipelineContext.destroy(success);
      }
    } catch (Exception e) {
      throw new OXFException(e);
    }
  }