1 29 30 package com.caucho.xml.stream; 31 import com.caucho.util.L10N; 32 import com.caucho.vfs.Vfs; 33 34 import javax.xml.stream.XMLEventWriter; 35 import javax.xml.stream.XMLOutputFactory; 36 import javax.xml.stream.XMLStreamException; 37 import javax.xml.stream.XMLStreamWriter; 38 import javax.xml.transform.Result ; 39 import javax.xml.transform.dom.DOMResult ; 40 import javax.xml.transform.stream.StreamResult ; 41 import java.io.IOException ; 42 import java.io.OutputStream ; 43 import java.io.OutputStreamWriter ; 44 import java.io.Writer ; 45 46 public class XMLOutputFactoryImpl extends XMLOutputFactory { 47 private static final L10N L = new L10N(XMLOutputFactoryImpl.class); 48 49 private boolean _repair = false; 50 51 public XMLOutputFactoryImpl() 52 { 53 } 54 55 56 60 public XMLEventWriter createXMLEventWriter(OutputStream stream) 61 throws XMLStreamException 62 { 63 return new XMLEventWriterImpl(createXMLStreamWriter(stream)); 64 } 65 66 public XMLEventWriter createXMLEventWriter(OutputStream stream, 67 String encoding) 68 throws XMLStreamException 69 { 70 return new XMLEventWriterImpl(createXMLStreamWriter(stream, encoding)); 71 } 72 73 76 public XMLEventWriter createXMLEventWriter(Result result) 77 throws XMLStreamException 78 { 79 throw new JAXPNotSupportedInStAXException(); 80 } 81 82 public XMLEventWriter createXMLEventWriter(Writer stream) 83 throws XMLStreamException 84 { 85 return new XMLEventWriterImpl(createXMLStreamWriter(stream)); 86 } 87 88 92 public XMLStreamWriter createXMLStreamWriter(OutputStream stream) 93 throws XMLStreamException 94 { 95 return new XMLStreamWriterImpl(Vfs.openWrite(stream), _repair); 96 } 97 98 public XMLStreamWriter createXMLStreamWriter(OutputStream stream, 99 String encoding) 100 throws XMLStreamException 101 { 102 try { 103 OutputStreamWriter osw = new OutputStreamWriter (stream, encoding); 104 return new XMLStreamWriterImpl(Vfs.openWrite(osw), _repair); 105 } 106 catch (IOException e) { 107 throw new XMLStreamException(e); 108 } 109 } 110 111 114 public XMLStreamWriter createXMLStreamWriter(Result result) 115 throws XMLStreamException 116 { 117 if (result instanceof DOMResult ) { 118 return new DOMResultXMLStreamWriterImpl((DOMResult ) result); 119 } 120 else if (result instanceof StreamResult ) { 121 Writer writer = ((StreamResult ) result).getWriter(); 122 return createXMLStreamWriter(writer); 123 } 124 125 throw new UnsupportedOperationException (L.l("Results of type {0} are not supported", result.getClass().getName())); 126 } 127 128 public XMLStreamWriter createXMLStreamWriter(Writer stream) 129 throws XMLStreamException 130 { 131 return new XMLStreamWriterImpl(Vfs.openWrite(stream), _repair); 132 } 133 134 public Object getProperty(String name) 135 throws IllegalArgumentException 136 { 137 throw new IllegalArgumentException ("property \""+name+"\" not supported"); 138 } 139 140 public boolean isPropertySupported(String name) 141 { 142 return false; 143 } 144 145 public void setProperty(String name, Object value) 146 throws IllegalArgumentException 147 { 148 if ("javax.xml.stream.isRepairingNamespaces".equals(name)) { 149 if (value instanceof Boolean ) 150 _repair = ((Boolean ) value).booleanValue(); 151 else 152 throw new IllegalArgumentException ("value of " + name + " must be Boolean, not " + value); 153 } 154 else 155 throw new IllegalArgumentException ("property \""+name+"\" not supported"); 156 } 157 } 158 | Popular Tags |