1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44:
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51:
52:
57: public class XMLOutputFactoryImpl
58: extends XMLOutputFactory
59: {
60:
61: protected boolean prefixDefaulting = false;
62:
63: public XMLOutputFactoryImpl()
64: {
65: }
66:
67: public XMLStreamWriter createXMLStreamWriter(Writer stream)
68: throws XMLStreamException
69: {
70:
71: return new XMLStreamWriterImpl(stream, null, prefixDefaulting);
72: }
73:
74: public XMLStreamWriter createXMLStreamWriter(OutputStream stream)
75: throws XMLStreamException
76: {
77: return createXMLStreamWriter(stream, "UTF-8");
78: }
79:
80: public XMLStreamWriter createXMLStreamWriter(OutputStream stream,
81: String encoding)
82: throws XMLStreamException
83: {
84: if (encoding == null)
85: encoding = "UTF-8";
86: try
87: {
88: Writer writer = new OutputStreamWriter(stream, encoding);
89: return new XMLStreamWriterImpl(writer, encoding, prefixDefaulting);
90: }
91: catch (UnsupportedEncodingException e)
92: {
93: XMLStreamException e2 = new XMLStreamException(e);
94: e2.initCause(e);
95: throw e2;
96: }
97: }
98:
99: public XMLStreamWriter createXMLStreamWriter(Result result)
100: throws XMLStreamException
101: {
102: if (result instanceof StreamResult)
103: {
104: StreamResult sr = (StreamResult) result;
105: OutputStream out = sr.getOutputStream();
106: if (out != null)
107: return createXMLStreamWriter(out);
108: Writer writer = sr.getWriter();
109: if (writer != null)
110: return createXMLStreamWriter(writer);
111: }
112: throw new UnsupportedOperationException();
113: }
114:
115: public XMLEventWriter createXMLEventWriter(OutputStream stream)
116: throws XMLStreamException
117: {
118: XMLStreamWriter writer = createXMLStreamWriter(stream);
119: return new XMLEventWriterImpl(writer);
120: }
121:
122: public XMLEventWriter createXMLEventWriter(OutputStream stream,
123: String encoding)
124: throws XMLStreamException
125: {
126: XMLStreamWriter writer = createXMLStreamWriter(stream, encoding);
127: return new XMLEventWriterImpl(writer);
128: }
129:
130: public XMLEventWriter createXMLEventWriter(Writer stream)
131: throws XMLStreamException
132: {
133: XMLStreamWriter writer = createXMLStreamWriter(stream);
134: return new XMLEventWriterImpl(writer);
135: }
136:
137: public XMLEventWriter createXMLEventWriter(Result result)
138: throws XMLStreamException
139: {
140: if (result instanceof StreamResult)
141: {
142: StreamResult sr = (StreamResult) result;
143: OutputStream out = sr.getOutputStream();
144: if (out != null)
145: return createXMLEventWriter(out);
146: Writer writer = sr.getWriter();
147: if (writer != null)
148: return createXMLEventWriter(writer);
149: }
150: throw new UnsupportedOperationException();
151: }
152:
153: public void setProperty(String name, Object value)
154: throws IllegalArgumentException
155: {
156: if (IS_REPAIRING_NAMESPACES.equals(name))
157: prefixDefaulting = ((Boolean) value).booleanValue();
158: else
159: throw new IllegalArgumentException(name);
160: }
161:
162: public Object getProperty(String name)
163: throws IllegalArgumentException
164: {
165: if (IS_REPAIRING_NAMESPACES.equals(name))
166: return new Boolean(prefixDefaulting);
167: throw new IllegalArgumentException(name);
168: }
169:
170: public boolean isPropertySupported(String name)
171: {
172: if (IS_REPAIRING_NAMESPACES.equals(name))
173: return true;
174: return false;
175: }
176:
177: public boolean isPrefixDefaulting()
178: {
179: return prefixDefaulting;
180: }
181:
182: public void setPrefixDefaulting(boolean value)
183: {
184: prefixDefaulting = value;
185: }
186:
187: }