Convert this source message to the ECXML format.
Typically you do not override this method, you override the getTransformer method
to supply a XSLT document to do the conversion.
@param source The source XML document.
544224
public int convertInternalToExternal(Object recordOwner)
    {
        if (this.getXSLTDocument() == null)
            return super.convertInternalToExternal(recordOwner);
        String strXML = this.getMessage().getXML(true);
        strXML = this.transformMessage(strXML, null);    // Now use the XSLT document to convert this XSL document.
        boolean bSuccess = this.setXML(strXML);
        return bSuccess ? DBConstants.NORMAL_RETURN : DBConstants.ERROR_RETURN;    // Success
    }
981767
public static String xmlToString(Document document) throws Exception {
        if (transformer == null) {
            throw new Exception("Transformer is null");
        }
        Source xmlSource = new DOMSource(document);
        StringWriter stringWriter = new StringWriter();
        Result result = new StreamResult(stringWriter);
        transformer.transform(xmlSource, result);
        return stringWriter.toString();
    }
356908
private static List<TransformationDescription> loadDescrtipionsFromXMLInputSource(InputSource source,
            String fileName) throws Exception {
        XMLReader xr = XMLReaderFactory.createXMLReader();
        TransformationDescriptionXMLReader reader = new TransformationDescriptionXMLReader(fileName);
        xr.setContentHandler(reader);
        xr.parse(source);
        return reader.getResult();
    }
477903
public static Element parse(InputSource source) throws IOException
   {
      try
      {
         Document doc;
         DocumentBuilder builder = getDocumentBuilder();
         synchronized (builder) //synchronize to prevent concurrent parsing on the same DocumentBuilder
         {
            doc = builder.parse(source);
         }
         return doc.getDocumentElement();
      }
      catch (SAXException se)
      {
         throw new IOException(se.toString());
      }
      finally
      {
         InputStream is = source.getByteStream();
         if (is != null)
         {
            is.close();
         }
         Reader r = source.getCharacterStream();
         if (r != null)
         {
            r.close();
         }
      }
   }
714758
public static void addNSdeclarations(Element source, Element target)
            throws Exception {
        NamedNodeMap sourceAttributes = source.getAttributes();
        Attr attribute;
        String attributeName;
        for (int i = 0; i <= sourceAttributes.getLength() - 1; i++) {
            attribute = (Attr) sourceAttributes.item(i);
            attributeName = attribute.getName();
            if (attributeName.startsWith("xmlns")
                    && !attributeName.startsWith("xmlns:soap-env")) {
                // System.out.println("XMLNS:" +
                // attributeName+":"+attribute.getValue());
                target.setAttribute(attributeName, attribute.getValue());
            }
        }
    }
1042209
public void fromXML(Document domdoc) throws DocumentException
    {
        this.encoding = domdoc.getXMLEncoding();

        Element rootElement = domdoc.getRootElement();

        this.reference = readDocumentReference(domdoc);

        this.locale = rootElement.attributeValue("locale");
        if (this.locale == null) {
            // Fallback on old <language> element
            this.locale = readElement(rootElement, "language");
        }

        this.defaultLanguage = readElement(rootElement, "defaultLanguage");
        this.creator = readElement(rootElement, "creator");
        this.author = readElement(rootElement, AUTHOR_TAG);
        this.contentAuthor = readElement(rootElement, "contentAuthor");
        this.version = readElement(rootElement, "version");
        this.parent = readElement(rootElement, "parent");
        this.comment = readElement(rootElement, "comment");
        this.minorEdit = readElement(rootElement, "minorEdit");
        this.attachmentData = readAttachmentData(rootElement);
        this.isHidden = Boolean.parseBoolean(readElement(rootElement, "hidden"));
        this.title = readElement(rootElement, "title");
        this.syntaxId = readElement(rootElement, "syntaxId");
        this.content = readElement(rootElement, "content");

        this.datePresent = isElementPresent(rootElement, "date");
        this.contentUpdateDatePresent = isElementPresent(rootElement, "contentUpdateDate");
        this.creationDatePresent = isElementPresent(rootElement, "creationDate");
        this.attachmentDatePresent = rootElement.selectSingleNode("//attachment/date") != null;

        // Does this document contain a XWiki.TranslationDocumentClass xobject?
        if (!rootElement.selectNodes("//object/className[text() = 'XWiki.TranslationDocumentClass']").isEmpty()) {
            this.containsTranslations = true;
            // Record the visibility
            for (Node node : rootElement
                .selectNodes("//object/className[text() = 'XWiki.TranslationDocumentClass']/../property/scope")) {
                this.translationVisibilities.add(node.getStringValue());
            }
        }
    }
424278
public static void convertDOMToXML(Node doc, Writer out)
    {
        try {
            // Use a Transformer for output
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();

            DOMSource source = new DOMSource(doc);

            StreamResult result = new StreamResult(out);
            transformer.transform(source, result);
        } catch (TransformerConfigurationException tce) {
            // Error generated by the parser
            tce.printStackTrace();
        } catch (TransformerException te) {
            // Error generated by the parser
            te.printStackTrace();
        }
    }
568593
public synchronized Node parse(InputSource source) throws IOException, SAXException
    {
//        _dtd=null;
        Handler handler = new Handler();
        XMLReader reader = _parser.getXMLReader();
        reader.setContentHandler(handler);
        reader.setErrorHandler(handler);
        reader.setEntityResolver(handler);
        if (logger.isDebugEnabled())
            logger.debug("parsing: sid=" + source.getSystemId() + ",pid=" + source.getPublicId());
        _parser.parse(source, handler);
        if (handler.error != null)
            throw handler.error;
        Node root = (Node)handler.root;
        handler.reset();
        return root;
    }
1316726
@SuppressWarnings("unchecked")
	public <T> T convertElement(ConversionContext context, Object source,
			TypeReference<T> destinationType) throws ConverterException {
		return (T) elementConverter.convert(context, source, destinationType);
	}
408611
public static void serializeXMLDocument (Document doc, Writer output) throws TransformerException {
        // serialize XML document using identity transformation
        Transformer trans = TransformerFactory.newInstance().newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(output);
        trans.transform(source, result);
    }
452189
public T deserialize(Source source) {
    try {
      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
      JAXBElement<T> jaxbElement = unmarshaller.unmarshal(source, clazz);
      return jaxbElement.getValue();
    } catch (JAXBException e) {
      throw new SerializationException(
          String.format("Could not deserialize %s object from source %s.", clazz, source), e);
    }
  }
1104147
public void updateByXml(Source source) throws IOException {
        checkPermission(CONFIGURE);
        XmlFile configXmlFile = getConfigFile();
        final AtomicFileWriter out = new AtomicFileWriter(configXmlFile.getFile());
        try {
            try {
                XMLUtils.safeTransform(source, new StreamResult(out));
                out.close();
            } catch (TransformerException | SAXException e) {
                throw new IOException("Failed to persist config.xml", e);
            }

            // try to reflect the changes by reloading
            Object o = new XmlFile(Items.XSTREAM, out.getTemporaryFile()).unmarshalNullingOut(this);
            if (o!=this) {
                // ensure that we've got the same job type. extending this code to support updating
                // to different job type requires destroying & creating a new job type
                throw new IOException("Expecting "+this.getClass()+" but got "+o.getClass()+" instead");
            }

            Items.whileUpdatingByXml(new NotReallyRoleSensitiveCallable<Void,IOException>() {
                @Override public Void call() throws IOException {
                    onLoad(getParent(), getRootDir().getName());
                    return null;
                }
            });
            Jenkins.getInstance().rebuildDependencyGraphAsync();

            // if everything went well, commit this new version
            out.commit();
            SaveableListener.fireOnChange(this, getConfigFile());

        } finally {
            out.abort(); // don't leave anything behind
        }
    }
1224451
public void xml(String xml) {
    if (LogLevel.DEBUG < logConfiguration.logLevel) {
      return;
    }
    printlnInternal(LogLevel.DEBUG, logConfiguration.xmlFormatter.format(xml));
  }
506730
public void printSource(Source src, PrintStream out)
    {
        TransformerFactory tFact = TransformerFactory.newInstance();
        try {
            Transformer transformer = tFact.newTransformer();

            Result result = new StreamResult( out );
            transformer.transform(src, result);
        } catch (TransformerConfigurationException ex)  {
            ex.printStackTrace();
        } catch (TransformerException ex)  {
            ex.printStackTrace();
        }
    }
714460
public static Node valueToNode(Object source) {
        if (source instanceof Node) {
            return (Node) source;
        } else {
            return converter.valueToNode(source);
        }
    }
908209
def cnxml_to_html(cnxml_source):
    """"""
    source = _string2io(cnxml_source)
    xml = etree.parse(source)
    # Run the CNXML to HTML transform
    xml = _transform('cnxml-to-html5.xsl', xml,
                     version='"{}"'.format(version))
    xml = XHTML_MODULE_BODY_XPATH(xml)
    return etree.tostring(xml[0])
470890
public static void format(final Source input, final Result output) {
        try {
            // Use an identity transformation to write the source to the result.
            final Transformer transformer = createTransformer(null);
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");

            transformer.transform(input, output);
        } catch (final Exception ex) {
            LOGGER.error("Problem formatting DOM representation.", ex);
        }
    }