# HG changeset patch # User asaha # Date 1500914183 25200 # Node ID 3daeca3e0cc20f90e1141038d990778956e2e149 # Parent f58a192400121e6285f5df2d900b9f4518e20ccd# Parent 685c4e3bfe4dfe9c4c07ea0eeabea835c36f3303 Merge diff -r f58a19240012 -r 3daeca3e0cc2 .hgtags --- a/.hgtags Fri Jul 21 20:32:41 2017 -0700 +++ b/.hgtags Mon Jul 24 09:36:23 2017 -0700 @@ -660,6 +660,8 @@ 5f84e87f91d5bc36ed026b88d183821e5109d730 jdk8u112-b15 d82dd7a24a496e26987caa328d1fb4fc794a4770 jdk8u112-b16 021da5d50285a523d4622a727ea1a7019f2b52e4 jdk8u112-b31 +4d1398900b3745c3181450e981ed45696a1c97fc jdk8u112-b32 +424b6ee9ade3f63228867933fe8a995880379b97 jdk8u112-b33 452662a83e5bc6dc7e9425ddd10f6c8fc98d50d8 jdk8u121-b00 9cd16be39ca6f2c8f7cc99ad07a77bb9d0696c75 jdk8u121-b01 f092b9a890ceeca4a2f4d55cf7d6f3f113cdb462 jdk8u121-b02 @@ -674,6 +676,12 @@ 89aa912be940d6c30f59b80c826f212541912a56 jdk8u121-b11 52b3f9fb54ee4304a9c34a2fe07f0c9a49472185 jdk8u121-b12 5b8834cc3bb9e24153319c766e04e194945a61b9 jdk8u121-b13 +33c7a7def0d76bf508fe4d0a5261027d60bc272f jdk8u121-b31 +c946a5cc042f78c054943783d94cdb403c470e8f jdk8u121-b32 +159698a1ab4171fc9aa11dc43068390a7938c8dd jdk8u121-b33 +69fb2260636bf93b9d47c1699e899cd6e4e62bde jdk8u121-b34 +55de76c196f3efa65b86d4daae842837c9c86d4e jdk8u121-b35 +9e1b967463b26fb48a72fdb016f781d7b607d863 jdk8u121-b36 2359a73f36ca99ba30aef88a38936f6f4e18e65c jdk8u131-b00 bc5500cde753aed78c92e7301548fa1450c9b104 jdk8u131-b01 c146d8a61d677fd4d07778d0295b4e88e16a7dd3 jdk8u131-b02 @@ -686,6 +694,10 @@ 548546d23a924ff0962df885468ce49816ae48a9 jdk8u131-b09 bc74b4850d97ff1986bf551c752ce212f97f4b0e jdk8u131-b10 7817f0d2519573e42405ef96a7c7ff1d768f92ec jdk8u131-b11 +a432391b6d676847cf83ddacc1d6e42fc6435ac4 jdk8u131-b31 +cede0cc0bbe9641d70171e062d6b1ed9e52f2ebb jdk8u131-b32 +46788dc162ad09e11da8c4368d3371b06fb7ec63 jdk8u131-b33 +d5c5a205d7fb0a0b906d23e4aaf9dcdbb9ecfe7c jdk8u131-b34 74aa403ef03d56469e9364cc45c2ec18c6e50e33 jdk8u141-b00 b1138396b99b1f8ebdb7d28c7143c96eb5b4f991 jdk8u141-b01 a7b9281956f9616eab0498386b9605853db7b408 jdk8u141-b02 @@ -702,5 +714,7 @@ 27d35df45162afdf75b76983fcf11e1cbf2e3001 jdk8u141-b13 65d3b0e445513e024157635b970660b1e7211937 jdk8u141-b14 c62448650df40092f0324e34f35aa9f3940e9928 jdk8u141-b15 +c5788159081fc767d8c73fefde96bc0ad99eee65 jdk8u141-b31 +e6c85f5c962a5039101cd045b5251f2e92312a5f jdk8u141-b32 c57e086660a37470793e38b94d7abedb79489ce3 jdk8u144-b00 d2226ba553ca545f9bf9ffa66254478faca378a2 jdk8u144-b01 diff -r f58a19240012 -r 3daeca3e0cc2 src/share/jaxws_classes/com/sun/xml/internal/bind/marshaller/NoEscapeHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/marshaller/NoEscapeHandler.java Mon Jul 24 09:36:23 2017 -0700 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.xml.internal.bind.marshaller; + +import java.io.IOException; +import java.io.Writer; + +/** + * Performs no character escaping. + * + * @author + * Roman Grigoriadi (roman.grigoriadi@oracle.com) + */ +public class NoEscapeHandler implements CharacterEscapeHandler { + + public static final NoEscapeHandler theInstance = new NoEscapeHandler(); + + @Override + public void escape(char[] ch, int start, int length, boolean isAttVal, Writer out) throws IOException { + out.write(ch, start, length); + } +} diff -r f58a19240012 -r 3daeca3e0cc2 src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/BridgeImpl.java --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/BridgeImpl.java Fri Jul 21 20:32:41 2017 -0700 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/BridgeImpl.java Mon Jul 24 09:36:23 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -76,7 +76,7 @@ public void marshal(Marshaller _m, T t, XMLStreamWriter output) throws JAXBException { MarshallerImpl m = (MarshallerImpl)_m; - m.write(tagName,bi,t,XMLStreamWriterOutput.create(output,context),new StAXPostInitAction(output,m.serializer)); + m.write(tagName,bi,t,XMLStreamWriterOutput.create(output,context, m.getEscapeHandler()),new StAXPostInitAction(output,m.serializer)); } public void marshal(Marshaller _m, T t, OutputStream output, NamespaceContext nsContext) throws JAXBException { diff -r f58a19240012 -r 3daeca3e0cc2 src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/MarshallerImpl.java --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/MarshallerImpl.java Fri Jul 21 20:32:41 2017 -0700 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/MarshallerImpl.java Mon Jul 24 09:36:23 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -160,7 +160,7 @@ @Override public void marshal(Object obj, XMLStreamWriter writer) throws JAXBException { - write(obj, XMLStreamWriterOutput.create(writer,context), new StAXPostInitAction(writer,serializer)); + write(obj, XMLStreamWriterOutput.create(writer,context, escapeHandler), new StAXPostInitAction(writer,serializer)); } @Override @@ -364,6 +364,15 @@ } + /** + * Returns escape handler provided with JAXB context parameters. + * + * @return escape handler + */ + CharacterEscapeHandler getEscapeHandler() { + return escapeHandler; + } + // // // create XMLWriter by specifing various type of output. diff -r f58a19240012 -r 3daeca3e0cc2 src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/FastInfosetStreamWriterOutput.java --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/FastInfosetStreamWriterOutput.java Fri Jul 21 20:32:41 2017 -0700 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/FastInfosetStreamWriterOutput.java Mon Jul 24 09:36:23 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ package com.sun.xml.internal.bind.v2.runtime.output; +import com.sun.xml.internal.bind.marshaller.NoEscapeHandler; import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl; import com.sun.xml.internal.bind.v2.runtime.Name; import com.sun.xml.internal.bind.v2.runtime.XMLSerializer; @@ -220,7 +221,7 @@ public FastInfosetStreamWriterOutput(StAXDocumentSerializer out, JAXBContextImpl context) { - super(out); + super(out, NoEscapeHandler.theInstance); this.fiout = out; this.localNames = context.getUTF8NameTable(); diff -r f58a19240012 -r 3daeca3e0cc2 src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/StAXExStreamWriterOutput.java --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/StAXExStreamWriterOutput.java Fri Jul 21 20:32:41 2017 -0700 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/StAXExStreamWriterOutput.java Mon Jul 24 09:36:23 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,7 @@ import javax.xml.stream.XMLStreamException; +import com.sun.xml.internal.bind.marshaller.NoEscapeHandler; import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data; import com.sun.xml.internal.org.jvnet.staxex.XMLStreamWriterEx; @@ -40,7 +41,7 @@ private final XMLStreamWriterEx out; public StAXExStreamWriterOutput(XMLStreamWriterEx out) { - super(out); + super(out, NoEscapeHandler.theInstance); this.out = out; } diff -r f58a19240012 -r 3daeca3e0cc2 src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java Fri Jul 21 20:32:41 2017 -0700 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java Mon Jul 24 09:36:23 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,15 +26,16 @@ package com.sun.xml.internal.bind.v2.runtime.output; import java.io.IOException; +import java.io.Writer; import java.lang.reflect.Constructor; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; +import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler; import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl; import com.sun.xml.internal.bind.v2.runtime.XMLSerializer; -import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl; import org.xml.sax.SAXException; /** @@ -53,7 +54,7 @@ * Creates a new {@link XmlOutput} from a {@link XMLStreamWriter}. * This method recognizes an FI StAX writer. */ - public static XmlOutput create(XMLStreamWriter out, JAXBContextImpl context) { + public static XmlOutput create(XMLStreamWriter out, JAXBContextImpl context, CharacterEscapeHandler escapeHandler) { // try optimized path final Class writerClass = out.getClass(); if (writerClass==FI_STAX_WRITER_CLASS) { @@ -69,17 +70,26 @@ } } + CharacterEscapeHandler xmlStreamEscapeHandler = escapeHandler != null ? + escapeHandler : NewLineEscapeHandler.theInstance; + // otherwise the normal writer. - return new XMLStreamWriterOutput(out); + return new XMLStreamWriterOutput(out, xmlStreamEscapeHandler); } private final XMLStreamWriter out; + private final CharacterEscapeHandler escapeHandler; + + private final XmlStreamOutWriterAdapter writerWrapper; + protected final char[] buf = new char[256]; - protected XMLStreamWriterOutput(XMLStreamWriter out) { + protected XMLStreamWriterOutput(XMLStreamWriter out, CharacterEscapeHandler escapeHandler) { this.out = out; + this.escapeHandler = escapeHandler; + this.writerWrapper = new XmlStreamOutWriterAdapter(out); } // not called if we are generating fragments @@ -137,7 +147,7 @@ public void text(String value, boolean needsSeparatingWhitespace) throws IOException, SAXException, XMLStreamException { if(needsSeparatingWhitespace) out.writeCharacters(" "); - out.writeCharacters(value); + escapeHandler.escape(value.toCharArray(), 0, value.length(), false, writerWrapper); } public void text(Pcdata value, boolean needsSeparatingWhitespace) throws IOException, SAXException, XMLStreamException { @@ -207,4 +217,82 @@ } } + + /** + * Performs character escaping only for new lines. + */ + private static class NewLineEscapeHandler implements CharacterEscapeHandler { + + public static final NewLineEscapeHandler theInstance = new NewLineEscapeHandler(); + + @Override + public void escape(char[] ch, int start, int length, boolean isAttVal, Writer out) throws IOException { + int limit = start+length; + int lastEscaped = start; + + for (int i = start; i < limit; i++) { + char c = ch[i]; + if (c == '\r' || c == '\n') { + if (i != lastEscaped) { + out.write(ch, lastEscaped, i - lastEscaped); + } + lastEscaped = i + 1; + if (out instanceof XmlStreamOutWriterAdapter) { + try { + ((XmlStreamOutWriterAdapter)out).writeEntityRef("#x" + Integer.toHexString(c)); + } catch (XMLStreamException e) { + throw new IOException("Error writing xml stream", e); + } + } else { + out.write("&#x"); + out.write(Integer.toHexString(c)); + out.write(';'); + } + } + } + if (lastEscaped != limit) { + out.write(ch, lastEscaped, length - lastEscaped); + } + } + } + + private static final class XmlStreamOutWriterAdapter extends Writer { + + private final XMLStreamWriter writer; + + private XmlStreamOutWriterAdapter(XMLStreamWriter writer) { + this.writer = writer; + } + + @Override + public void write(char[] cbuf, int off, int len) throws IOException { + try { + writer.writeCharacters(cbuf, off, len); + } catch (XMLStreamException e) { + throw new IOException("Error writing XML stream", e); + } + } + + public void writeEntityRef(String entityReference) throws XMLStreamException { + writer.writeEntityRef(entityReference); + } + + @Override + public void flush() throws IOException { + try { + writer.flush(); + } catch (XMLStreamException e) { + throw new IOException("Error flushing XML stream", e); + } + } + + @Override + public void close() throws IOException { + try { + writer.close(); + } catch (XMLStreamException e) { + throw new IOException("Error closing XML stream", e); + } + } + } }