1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
419 xw.setHeader(header);
420 return new SAXOutput(xw); // TODO: don't we need a better writer?
421 }
422
423 public XmlOutput createWriter(Writer w) {
424 return createWriter(w, getEncoding());
425 }
426
427 public XmlOutput createWriter( OutputStream os ) throws JAXBException {
428 return createWriter(os, getEncoding());
429 }
430
431 public XmlOutput createWriter( OutputStream os, String encoding ) throws JAXBException {
432 // UTF8XmlOutput does buffering on its own, and
433 // otherwise createWriter(Writer) inserts a buffering,
434 // so no point in doing a buffering here.
435
436 if(encoding.equals("UTF-8")) {
437 Encoded[] table = context.getUTF8NameTable();
438 final UTF8XmlOutput out;
439 if(isFormattedOutput())
440 out = new IndentingUTF8XmlOutput(os, indent, table, escapeHandler);
441 else {
442 if(c14nSupport)
443 out = new C14nXmlOutput(os, table, context.c14nSupport, escapeHandler);
444 else
445 out = new UTF8XmlOutput(os, table, escapeHandler);
446 }
447 if(header!=null)
448 out.setHeader(header);
449 return out;
450 }
451
452 try {
453 return createWriter(
454 new OutputStreamWriter(os,getJavaEncoding(encoding)),
455 encoding );
456 } catch( UnsupportedEncodingException e ) {
457 throw new MarshalException(
458 Messages.UNSUPPORTED_ENCODING.format(encoding),
459 e );
460 }
461 }
462
463
464 @Override
465 public Object getProperty(String name) throws PropertyException {
|
1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
419 xw.setHeader(header);
420 return new SAXOutput(xw); // TODO: don't we need a better writer?
421 }
422
423 public XmlOutput createWriter(Writer w) {
424 return createWriter(w, getEncoding());
425 }
426
427 public XmlOutput createWriter( OutputStream os ) throws JAXBException {
428 return createWriter(os, getEncoding());
429 }
430
431 public XmlOutput createWriter( OutputStream os, String encoding ) throws JAXBException {
432 // UTF8XmlOutput does buffering on its own, and
433 // otherwise createWriter(Writer) inserts a buffering,
434 // so no point in doing a buffering here.
435
436 if(encoding.equals("UTF-8")) {
437 Encoded[] table = context.getUTF8NameTable();
438 final UTF8XmlOutput out;
439 CharacterEscapeHandler ceh = createEscapeHandler(encoding);
440 if(isFormattedOutput())
441 out = new IndentingUTF8XmlOutput(os, indent, table, ceh);
442 else {
443 if(c14nSupport)
444 out = new C14nXmlOutput(os, table, context.c14nSupport, ceh);
445 else
446 out = new UTF8XmlOutput(os, table, ceh);
447 }
448 if(header!=null)
449 out.setHeader(header);
450 return out;
451 }
452
453 try {
454 return createWriter(
455 new OutputStreamWriter(os,getJavaEncoding(encoding)),
456 encoding );
457 } catch( UnsupportedEncodingException e ) {
458 throw new MarshalException(
459 Messages.UNSUPPORTED_ENCODING.format(encoding),
460 e );
461 }
462 }
463
464
465 @Override
466 public Object getProperty(String name) throws PropertyException {
|