Java Utililty Methods XML String Transform

List of utility methods to do XML String Transform

Description

The list of methods to do XML String Transform are organized into topic(s).

Method

voidcreateOrUpdateConnection(String fileName, String directory, String communityId, String serviceName, String serviceUrl, String defaultVersion, Logger log)
Creates or edits an endpoint in the given connection info file in the given CONNECT config directory.
log.info("begin CreateOrUpdateConnection; directory='" + directory + "';community id='" + communityId
        + "';service name='" + serviceName + "';service url='" + serviceUrl + "';");
String fullPath = directory + "/" + fileName;
log.info("Path to connection info file: " + fullPath);
boolean serviceNodeFound = false;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document doc = null;
...
StringcreateSettingsXml(Map props)
Creates a settings xml with a sonar profile, containing all the given properties Also adds repox to continue to use QAed artifacts
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element settings = doc.createElement("settings");
Element profiles = doc.createElement("profiles");
Element profile = doc.createElement("profile");
Element id = doc.createElement("id");
id.setTextContent("sonar");
Element properties = doc.createElement("properties");
...
SourcecreateSource(final String message)
create Source
String charsetEncoding = Charset.defaultCharset().displayName();
return createSource(message, charsetEncoding);
SourcecreateSource(String msg)
Creates a source from a string representing a XML document.
StreamSource source = new StreamSource();
source.setInputStream(new ByteArrayInputStream(msg.getBytes("UTF-8")));
return source;
StringcreateString(Element element)
create String
try {
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    DOMSource source = new DOMSource(element);
    Writer writer = new StringWriter();
    Result result = new StreamResult(writer);
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
...
voidcreateXml(ArrayList nameList, ArrayList stringList, ArrayList stringArrayNameList, HashMap> stringArrayContentMap)
create Xml
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
    builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();
    Element mainRootElement = document
            .createElementNS("xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\"", "resources");
    document.appendChild(mainRootElement);
...
StringcreateXmlError(String message, String details)
create Xml Error
try {
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document document = docBuilder.newDocument();
    Element rootElement = document.createElement("error");
    Element messageElement = document.createElement("message");
    if (message != null) {
        messageElement.setTextContent(message);
...
XMLEventReadercreateXmlEventReaderOnXmlString(String xml, String docBaseUri)
create Xml Event Reader On Xml String
Reader stringReader = new StringReader(xml);
Source source = new StreamSource(stringReader, docBaseUri.toString());
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty("javax.xml.stream.isCoalescing", Boolean.TRUE);
factory.setProperty("javax.xml.stream.supportDTD", Boolean.FALSE);
return factory.createXMLEventReader(source);
byte[]decodeHex(String hex)
Turns a hex encoded string into a byte array.
return DatatypeConverter.parseHexBinary(hex);
StringelementToXMLString(Object aElement)
element To XML String
DOMSource source = new DOMSource((Node) aElement);
StringWriter stringWriter = new StringWriter();
StreamResult result = new StreamResult(stringWriter);
TransformerFactory tfactory = TransformerFactory.newInstance();
if (tfactory.getFeature(DOMSource.FEATURE) && tfactory.getFeature(StreamResult.FEATURE)) {
    Transformer transformer = tfactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
...