Java Utililty Methods XML Transform Usage

List of utility methods to do XML Transform Usage

Description

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

Method

XMLStreamReadercreateSafeReader(InputStream inputStream)
create Safe Reader
if (inputStream == null) {
    throw new IllegalArgumentException("The provided input stream cannot be null");
return createSafeReader(new StreamSource(inputStream));
SourcecreateSource(InputStream is)
Creates a Source from an InputStream.
return new StreamSource(is);
ResultcreateStaxResult(XMLStreamWriter streamWriter)
Create a JAXP 1.4 StAXResult for the given XMLStreamWriter .
return new StAXResult(streamWriter);
SourcecreateStaxSource(XMLStreamReader streamReader)
Create a JAXP 1.4 javax.xml.transform.stax.StAXSource for the given javax.xml.stream.XMLStreamReader .
return new StAXSource(streamReader);
StreamResultcreateStreamResult(File outFile)
Creae a stream result based on a File.
final StreamResult result = new StreamResult(outFile);
result.setOutputStream(new FileOutputStream(outFile));
return result;
StreamResultcreateUnixStreamResultForEntry(OutputStream outputEntry)
Creates a StreamResult by wrapping the given outputEntry in an OutputStreamWriter that transforms Windows line endings (\r\n) into Unix line endings (\n) on Windows for consistency with Roo's templates.
final Writer writer;
if (System.getProperty("line.separator").equals("\r\n")) {
    writer = new OutputStreamWriter(outputEntry, "ISO-8859-1") {
        public void write(char[] cbuf, int off, int len) throws IOException {
            for (int i = off; i < off + len; i++) {
                if (cbuf[i] != '\r' || (i < cbuf.length - 1 && cbuf[i + 1] != '\n')) {
                    super.write(cbuf[i]);
        public void write(int c) throws IOException {
            if (c != '\r')
                super.write(c);
        public void write(String str, int off, int len) throws IOException {
            String orig = str.substring(off, off + len);
            String filtered = orig.replace("\r\n", "\n");
            int lengthDiff = orig.length() - filtered.length();
            if (filtered.endsWith("\r")) {
                super.write(filtered.substring(0, filtered.length() - 1), 0, len - lengthDiff - 1);
            } else {
                super.write(filtered, 0, len - lengthDiff);
    };
} else {
    writer = new OutputStreamWriter(outputEntry, "ISO-8859-1");
return new StreamResult(writer);
XMLGregorianCalendardateToGregorian(Date date)
Transform a date in Date to XMLGregorianCalendar
return longToGregorian(date.getTime());
XMLGregorianCalendarDateToXML(Date date)
Date To XML
GregorianCalendar c = new GregorianCalendar();
c.setTime(date);
XMLGregorianCalendar xmlDate = null;
try {
    xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
} catch (Exception e) {
    try {
        c.setTime(new Date());
...
voiddumpMetadata(IIOMetadata meta)
dump Metadata
String format = meta.getNativeMetadataFormatName();
Node node = meta.getAsTree(format);
dumpNode(node);
voiddumpMetadataToSystemOut(IIOMetadata iiometa)
Dumps the content of an IIOMetadata instance to System.out.
String[] metanames = iiometa.getMetadataFormatNames();
for (int j = 0; j < metanames.length; j++) {
    System.out.println("--->" + metanames[j]);
    dumpNodeToSystemOut(iiometa.getAsTree(metanames[j]));