Sun, 18 Jun 2017 23:18:45 +0100
8172297: In java 8, the marshalling with JAX-WS does not escape carriage return
Reviewed-by: lancea
aoqi@0 | 1 | /* |
aefimov@1443 | 2 | * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.bind.v2.runtime.output; |
aoqi@0 | 27 | |
aefimov@1443 | 28 | import com.sun.xml.internal.bind.marshaller.NoEscapeHandler; |
aoqi@0 | 29 | import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl; |
aoqi@0 | 30 | import com.sun.xml.internal.bind.v2.runtime.Name; |
aoqi@0 | 31 | import com.sun.xml.internal.bind.v2.runtime.XMLSerializer; |
aoqi@0 | 32 | import javax.xml.stream.XMLStreamException; |
aoqi@0 | 33 | |
aoqi@0 | 34 | import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data; |
aoqi@0 | 35 | import com.sun.xml.internal.fastinfoset.EncodingConstants; |
aoqi@0 | 36 | import com.sun.xml.internal.fastinfoset.stax.StAXDocumentSerializer; |
aoqi@0 | 37 | import java.io.IOException; |
aoqi@0 | 38 | import java.util.Collection; |
aoqi@0 | 39 | import java.util.Map; |
aoqi@0 | 40 | import java.util.WeakHashMap; |
aoqi@0 | 41 | import javax.xml.bind.JAXBContext; |
aoqi@0 | 42 | import com.sun.xml.internal.org.jvnet.fastinfoset.VocabularyApplicationData; |
aoqi@0 | 43 | import org.xml.sax.SAXException; |
aoqi@0 | 44 | |
aoqi@0 | 45 | /** |
aoqi@0 | 46 | * {@link XmlOutput} for {@link LowLevelStAXDocumentSerializer}. |
aoqi@0 | 47 | * <p> |
aoqi@0 | 48 | * This class is responsible for managing the indexing of elements, attributes |
aoqi@0 | 49 | * and local names that are known to JAXB by way of the JAXBContext (generated |
aoqi@0 | 50 | * from JAXB beans or schema). The pre-encoded UTF-8 representations of known |
aoqi@0 | 51 | * local names are also utilized. |
aoqi@0 | 52 | * <p> |
aoqi@0 | 53 | * The lookup of elements, attributes and local names with respect to a context |
aoqi@0 | 54 | * is very efficient. It relies on an incrementing base line so that look up is |
aoqi@0 | 55 | * performed in O(1) time and only uses static memory. When the base line reaches |
aoqi@0 | 56 | * a point where integer overflow will occur the arrays and base line are reset |
aoqi@0 | 57 | * (such an event is rare and will have little impact on performance). |
aoqi@0 | 58 | * <p> |
aoqi@0 | 59 | * A weak map of JAXB contexts to optimized tables for attributes, elements and |
aoqi@0 | 60 | * local names is utilized and stored on the LowLevel StAX serializer. Thus, |
aoqi@0 | 61 | * optimized serializing can work other multiple serializing of JAXB beans using |
aoqi@0 | 62 | * the same LowLevel StAX serializer instance. This approach works best when JAXB |
aoqi@0 | 63 | * contexts are only created once per schema or JAXB beans (which is the recommended |
aoqi@0 | 64 | * practice as the creation JAXB contexts are expensive, they are thread safe and |
aoqi@0 | 65 | * can be reused). |
aoqi@0 | 66 | * |
aoqi@0 | 67 | * @author Paul.Sandoz@Sun.Com |
aoqi@0 | 68 | */ |
aoqi@0 | 69 | public final class FastInfosetStreamWriterOutput extends XMLStreamWriterOutput { |
aoqi@0 | 70 | private final StAXDocumentSerializer fiout; |
aoqi@0 | 71 | private final Encoded[] localNames; |
aoqi@0 | 72 | private final TablesPerJAXBContext tables; |
aoqi@0 | 73 | |
aoqi@0 | 74 | /** |
aoqi@0 | 75 | * Holder for the optimzed element, attribute and |
aoqi@0 | 76 | * local name tables. |
aoqi@0 | 77 | */ |
aoqi@0 | 78 | final static class TablesPerJAXBContext { |
aoqi@0 | 79 | final int[] elementIndexes; |
aoqi@0 | 80 | final int[] elementIndexPrefixes; |
aoqi@0 | 81 | |
aoqi@0 | 82 | final int[] attributeIndexes; |
aoqi@0 | 83 | final int[] localNameIndexes; |
aoqi@0 | 84 | |
aoqi@0 | 85 | /** |
aoqi@0 | 86 | * The offset of the index |
aoqi@0 | 87 | */ |
aoqi@0 | 88 | int indexOffset; |
aoqi@0 | 89 | |
aoqi@0 | 90 | /** |
aoqi@0 | 91 | * The the maximum known value of an index |
aoqi@0 | 92 | */ |
aoqi@0 | 93 | int maxIndex; |
aoqi@0 | 94 | |
aoqi@0 | 95 | /** |
aoqi@0 | 96 | * True if the tables require clearing |
aoqi@0 | 97 | */ |
aoqi@0 | 98 | boolean requiresClear; |
aoqi@0 | 99 | |
aoqi@0 | 100 | /** |
aoqi@0 | 101 | * Create a new set of tables for a JAXB context. |
aoqi@0 | 102 | * <p> |
aoqi@0 | 103 | * @param content the JAXB context. |
aoqi@0 | 104 | * @param initialIndexOffset the initial index offset to calculate |
aoqi@0 | 105 | * the maximum possible index |
aoqi@0 | 106 | * |
aoqi@0 | 107 | */ |
aoqi@0 | 108 | TablesPerJAXBContext(JAXBContextImpl context, int initialIndexOffset) { |
aoqi@0 | 109 | elementIndexes = new int[context.getNumberOfElementNames()]; |
aoqi@0 | 110 | elementIndexPrefixes = new int[context.getNumberOfElementNames()]; |
aoqi@0 | 111 | attributeIndexes = new int[context.getNumberOfAttributeNames()]; |
aoqi@0 | 112 | localNameIndexes = new int[context.getNumberOfLocalNames()]; |
aoqi@0 | 113 | |
aoqi@0 | 114 | indexOffset = 1; |
aoqi@0 | 115 | maxIndex = initialIndexOffset + elementIndexes.length + attributeIndexes.length; |
aoqi@0 | 116 | } |
aoqi@0 | 117 | |
aoqi@0 | 118 | /** |
aoqi@0 | 119 | * Require that tables are cleared. |
aoqi@0 | 120 | */ |
aoqi@0 | 121 | public void requireClearTables() { |
aoqi@0 | 122 | requiresClear = true; |
aoqi@0 | 123 | } |
aoqi@0 | 124 | |
aoqi@0 | 125 | /** |
aoqi@0 | 126 | * Clear or reset the tables. |
aoqi@0 | 127 | * <p> |
aoqi@0 | 128 | * @param initialIndexOffset the initial index offset to calculate |
aoqi@0 | 129 | * the maximum possible index |
aoqi@0 | 130 | */ |
aoqi@0 | 131 | public void clearOrResetTables(int intialIndexOffset) { |
aoqi@0 | 132 | if (requiresClear) { |
aoqi@0 | 133 | requiresClear = false; |
aoqi@0 | 134 | |
aoqi@0 | 135 | // Increment offset to new position |
aoqi@0 | 136 | indexOffset += maxIndex; |
aoqi@0 | 137 | // Reset the maximum known value of an index |
aoqi@0 | 138 | maxIndex = intialIndexOffset + elementIndexes.length + attributeIndexes.length; |
aoqi@0 | 139 | // Check if there is enough free space |
aoqi@0 | 140 | // If overflow |
aoqi@0 | 141 | if ((indexOffset + maxIndex) < 0) { |
aoqi@0 | 142 | clearAll(); |
aoqi@0 | 143 | } |
aoqi@0 | 144 | } else { |
aoqi@0 | 145 | // Reset the maximum known value of an index |
aoqi@0 | 146 | maxIndex = intialIndexOffset + elementIndexes.length + attributeIndexes.length; |
aoqi@0 | 147 | // Check if there is enough free space |
aoqi@0 | 148 | // If overflow |
aoqi@0 | 149 | if ((indexOffset + maxIndex) < 0) { |
aoqi@0 | 150 | resetAll(); |
aoqi@0 | 151 | } |
aoqi@0 | 152 | } |
aoqi@0 | 153 | } |
aoqi@0 | 154 | |
aoqi@0 | 155 | private void clearAll() { |
aoqi@0 | 156 | clear(elementIndexes); |
aoqi@0 | 157 | clear(attributeIndexes); |
aoqi@0 | 158 | clear(localNameIndexes); |
aoqi@0 | 159 | indexOffset = 1; |
aoqi@0 | 160 | } |
aoqi@0 | 161 | |
aoqi@0 | 162 | private void clear(int[] array) { |
aoqi@0 | 163 | for (int i = 0; i < array.length; i++) { |
aoqi@0 | 164 | array[i] = 0; |
aoqi@0 | 165 | } |
aoqi@0 | 166 | } |
aoqi@0 | 167 | |
aoqi@0 | 168 | /** |
aoqi@0 | 169 | * Increment the maximum know index value |
aoqi@0 | 170 | * <p> |
aoqi@0 | 171 | * The indexes are preserved. |
aoqi@0 | 172 | */ |
aoqi@0 | 173 | public void incrementMaxIndexValue() { |
aoqi@0 | 174 | // Increment the maximum value of an index |
aoqi@0 | 175 | maxIndex++; |
aoqi@0 | 176 | // Check if there is enough free space |
aoqi@0 | 177 | // If overflow |
aoqi@0 | 178 | if ((indexOffset + maxIndex) < 0) { |
aoqi@0 | 179 | resetAll(); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | } |
aoqi@0 | 182 | |
aoqi@0 | 183 | private void resetAll() { |
aoqi@0 | 184 | clear(elementIndexes); |
aoqi@0 | 185 | clear(attributeIndexes); |
aoqi@0 | 186 | clear(localNameIndexes); |
aoqi@0 | 187 | indexOffset = 1; |
aoqi@0 | 188 | } |
aoqi@0 | 189 | |
aoqi@0 | 190 | private void reset(int[] array) { |
aoqi@0 | 191 | for (int i = 0; i < array.length; i++) { |
aoqi@0 | 192 | if (array[i] > indexOffset) { |
aoqi@0 | 193 | array[i] = array[i] - indexOffset + 1; |
aoqi@0 | 194 | } else { |
aoqi@0 | 195 | array[i] = 0; |
aoqi@0 | 196 | } |
aoqi@0 | 197 | } |
aoqi@0 | 198 | } |
aoqi@0 | 199 | |
aoqi@0 | 200 | } |
aoqi@0 | 201 | |
aoqi@0 | 202 | /** |
aoqi@0 | 203 | * Holder of JAXB contexts -> tables. |
aoqi@0 | 204 | * <p> |
aoqi@0 | 205 | * An instance will be registered with the |
aoqi@0 | 206 | * {@link LowLevelStAXDocumentSerializer}. |
aoqi@0 | 207 | */ |
aoqi@0 | 208 | final static class AppData implements VocabularyApplicationData { |
aoqi@0 | 209 | final Map<JAXBContext, TablesPerJAXBContext> contexts = |
aoqi@0 | 210 | new WeakHashMap<JAXBContext, TablesPerJAXBContext>(); |
aoqi@0 | 211 | final Collection<TablesPerJAXBContext> collectionOfContexts = contexts.values(); |
aoqi@0 | 212 | |
aoqi@0 | 213 | /** |
aoqi@0 | 214 | * Clear all the tables. |
aoqi@0 | 215 | */ |
aoqi@0 | 216 | public void clear() { |
aoqi@0 | 217 | for(TablesPerJAXBContext c : collectionOfContexts) |
aoqi@0 | 218 | c.requireClearTables(); |
aoqi@0 | 219 | } |
aoqi@0 | 220 | } |
aoqi@0 | 221 | |
aoqi@0 | 222 | public FastInfosetStreamWriterOutput(StAXDocumentSerializer out, |
aoqi@0 | 223 | JAXBContextImpl context) { |
aefimov@1443 | 224 | super(out, NoEscapeHandler.theInstance); |
aoqi@0 | 225 | |
aoqi@0 | 226 | this.fiout = out; |
aoqi@0 | 227 | this.localNames = context.getUTF8NameTable(); |
aoqi@0 | 228 | |
aoqi@0 | 229 | final VocabularyApplicationData vocabAppData = fiout.getVocabularyApplicationData(); |
aoqi@0 | 230 | AppData appData = null; |
aoqi@0 | 231 | if (vocabAppData == null || !(vocabAppData instanceof AppData)) { |
aoqi@0 | 232 | appData = new AppData(); |
aoqi@0 | 233 | fiout.setVocabularyApplicationData(appData); |
aoqi@0 | 234 | } else { |
aoqi@0 | 235 | appData = (AppData)vocabAppData; |
aoqi@0 | 236 | } |
aoqi@0 | 237 | |
aoqi@0 | 238 | final TablesPerJAXBContext tablesPerContext = appData.contexts.get(context); |
aoqi@0 | 239 | if (tablesPerContext != null) { |
aoqi@0 | 240 | tables = tablesPerContext; |
aoqi@0 | 241 | /** |
aoqi@0 | 242 | * Obtain the current local name index. Thus will be used to |
aoqi@0 | 243 | * calculate the maximum index value when serializing for this context |
aoqi@0 | 244 | */ |
aoqi@0 | 245 | tables.clearOrResetTables(out.getLocalNameIndex()); |
aoqi@0 | 246 | } else { |
aoqi@0 | 247 | tables = new TablesPerJAXBContext(context, out.getLocalNameIndex()); |
aoqi@0 | 248 | appData.contexts.put(context, tables); |
aoqi@0 | 249 | } |
aoqi@0 | 250 | } |
aoqi@0 | 251 | |
aoqi@0 | 252 | @Override |
aoqi@0 | 253 | public void startDocument(XMLSerializer serializer, boolean fragment, |
aoqi@0 | 254 | int[] nsUriIndex2prefixIndex, NamespaceContextImpl nsContext) |
aoqi@0 | 255 | throws IOException, SAXException, XMLStreamException { |
aoqi@0 | 256 | super.startDocument(serializer, fragment, nsUriIndex2prefixIndex, nsContext); |
aoqi@0 | 257 | |
aoqi@0 | 258 | if (fragment) |
aoqi@0 | 259 | fiout.initiateLowLevelWriting(); |
aoqi@0 | 260 | } |
aoqi@0 | 261 | |
aoqi@0 | 262 | @Override |
aoqi@0 | 263 | public void endDocument(boolean fragment) throws IOException, SAXException, XMLStreamException { |
aoqi@0 | 264 | super.endDocument(fragment); |
aoqi@0 | 265 | } |
aoqi@0 | 266 | |
aoqi@0 | 267 | @Override |
aoqi@0 | 268 | public void beginStartTag(Name name) throws IOException { |
aoqi@0 | 269 | fiout.writeLowLevelTerminationAndMark(); |
aoqi@0 | 270 | |
aoqi@0 | 271 | if (nsContext.getCurrent().count() == 0) { |
aoqi@0 | 272 | final int qNameIndex = tables.elementIndexes[name.qNameIndex] - tables.indexOffset; |
aoqi@0 | 273 | final int prefixIndex = nsUriIndex2prefixIndex[name.nsUriIndex]; |
aoqi@0 | 274 | |
aoqi@0 | 275 | if (qNameIndex >= 0 && |
aoqi@0 | 276 | tables.elementIndexPrefixes[name.qNameIndex] == prefixIndex) { |
aoqi@0 | 277 | fiout.writeLowLevelStartElementIndexed(EncodingConstants.ELEMENT, qNameIndex); |
aoqi@0 | 278 | } else { |
aoqi@0 | 279 | tables.elementIndexes[name.qNameIndex] = fiout.getNextElementIndex() + tables.indexOffset; |
aoqi@0 | 280 | tables.elementIndexPrefixes[name.qNameIndex] = prefixIndex; |
aoqi@0 | 281 | writeLiteral(EncodingConstants.ELEMENT | EncodingConstants.ELEMENT_LITERAL_QNAME_FLAG, |
aoqi@0 | 282 | name, |
aoqi@0 | 283 | nsContext.getPrefix(prefixIndex), |
aoqi@0 | 284 | nsContext.getNamespaceURI(prefixIndex)); |
aoqi@0 | 285 | } |
aoqi@0 | 286 | } else { |
aoqi@0 | 287 | beginStartTagWithNamespaces(name); |
aoqi@0 | 288 | } |
aoqi@0 | 289 | } |
aoqi@0 | 290 | |
aoqi@0 | 291 | public void beginStartTagWithNamespaces(Name name) throws IOException { |
aoqi@0 | 292 | final NamespaceContextImpl.Element nse = nsContext.getCurrent(); |
aoqi@0 | 293 | |
aoqi@0 | 294 | fiout.writeLowLevelStartNamespaces(); |
aoqi@0 | 295 | for (int i = nse.count() - 1; i >= 0; i--) { |
aoqi@0 | 296 | final String uri = nse.getNsUri(i); |
aoqi@0 | 297 | if (uri.length() == 0 && nse.getBase() == 1) |
aoqi@0 | 298 | continue; // no point in definint xmlns='' on the root |
aoqi@0 | 299 | fiout.writeLowLevelNamespace(nse.getPrefix(i), uri); |
aoqi@0 | 300 | } |
aoqi@0 | 301 | fiout.writeLowLevelEndNamespaces(); |
aoqi@0 | 302 | |
aoqi@0 | 303 | final int qNameIndex = tables.elementIndexes[name.qNameIndex] - tables.indexOffset; |
aoqi@0 | 304 | final int prefixIndex = nsUriIndex2prefixIndex[name.nsUriIndex]; |
aoqi@0 | 305 | |
aoqi@0 | 306 | if (qNameIndex >= 0 && |
aoqi@0 | 307 | tables.elementIndexPrefixes[name.qNameIndex] == prefixIndex) { |
aoqi@0 | 308 | fiout.writeLowLevelStartElementIndexed(0, qNameIndex); |
aoqi@0 | 309 | } else { |
aoqi@0 | 310 | tables.elementIndexes[name.qNameIndex] = fiout.getNextElementIndex() + tables.indexOffset; |
aoqi@0 | 311 | tables.elementIndexPrefixes[name.qNameIndex] = prefixIndex; |
aoqi@0 | 312 | writeLiteral(EncodingConstants.ELEMENT_LITERAL_QNAME_FLAG, |
aoqi@0 | 313 | name, |
aoqi@0 | 314 | nsContext.getPrefix(prefixIndex), |
aoqi@0 | 315 | nsContext.getNamespaceURI(prefixIndex)); |
aoqi@0 | 316 | } |
aoqi@0 | 317 | } |
aoqi@0 | 318 | |
aoqi@0 | 319 | @Override |
aoqi@0 | 320 | public void attribute(Name name, String value) throws IOException { |
aoqi@0 | 321 | fiout.writeLowLevelStartAttributes(); |
aoqi@0 | 322 | |
aoqi@0 | 323 | final int qNameIndex = tables.attributeIndexes[name.qNameIndex] - tables.indexOffset; |
aoqi@0 | 324 | if (qNameIndex >= 0) { |
aoqi@0 | 325 | fiout.writeLowLevelAttributeIndexed(qNameIndex); |
aoqi@0 | 326 | } else { |
aoqi@0 | 327 | tables.attributeIndexes[name.qNameIndex] = fiout.getNextAttributeIndex() + tables.indexOffset; |
aoqi@0 | 328 | |
aoqi@0 | 329 | final int namespaceURIId = name.nsUriIndex; |
aoqi@0 | 330 | if (namespaceURIId == -1) { |
aoqi@0 | 331 | writeLiteral(EncodingConstants.ATTRIBUTE_LITERAL_QNAME_FLAG, |
aoqi@0 | 332 | name, |
aoqi@0 | 333 | "", |
aoqi@0 | 334 | ""); |
aoqi@0 | 335 | } else { |
aoqi@0 | 336 | final int prefix = nsUriIndex2prefixIndex[namespaceURIId]; |
aoqi@0 | 337 | writeLiteral(EncodingConstants.ATTRIBUTE_LITERAL_QNAME_FLAG, |
aoqi@0 | 338 | name, |
aoqi@0 | 339 | nsContext.getPrefix(prefix), |
aoqi@0 | 340 | nsContext.getNamespaceURI(prefix)); |
aoqi@0 | 341 | } |
aoqi@0 | 342 | } |
aoqi@0 | 343 | |
aoqi@0 | 344 | fiout.writeLowLevelAttributeValue(value); |
aoqi@0 | 345 | } |
aoqi@0 | 346 | |
aoqi@0 | 347 | private void writeLiteral(int type, Name name, String prefix, String namespaceURI) throws IOException { |
aoqi@0 | 348 | final int localNameIndex = tables.localNameIndexes[name.localNameIndex] - tables.indexOffset; |
aoqi@0 | 349 | |
aoqi@0 | 350 | if (localNameIndex < 0) { |
aoqi@0 | 351 | tables.localNameIndexes[name.localNameIndex] = fiout.getNextLocalNameIndex() + tables.indexOffset; |
aoqi@0 | 352 | |
aoqi@0 | 353 | fiout.writeLowLevelStartNameLiteral( |
aoqi@0 | 354 | type, |
aoqi@0 | 355 | prefix, |
aoqi@0 | 356 | localNames[name.localNameIndex].buf, |
aoqi@0 | 357 | namespaceURI); |
aoqi@0 | 358 | } else { |
aoqi@0 | 359 | fiout.writeLowLevelStartNameLiteral( |
aoqi@0 | 360 | type, |
aoqi@0 | 361 | prefix, |
aoqi@0 | 362 | localNameIndex, |
aoqi@0 | 363 | namespaceURI); |
aoqi@0 | 364 | } |
aoqi@0 | 365 | } |
aoqi@0 | 366 | |
aoqi@0 | 367 | @Override |
aoqi@0 | 368 | public void endStartTag() throws IOException { |
aoqi@0 | 369 | fiout.writeLowLevelEndStartElement(); |
aoqi@0 | 370 | } |
aoqi@0 | 371 | |
aoqi@0 | 372 | @Override |
aoqi@0 | 373 | public void endTag(Name name) throws IOException { |
aoqi@0 | 374 | fiout.writeLowLevelEndElement(); |
aoqi@0 | 375 | } |
aoqi@0 | 376 | |
aoqi@0 | 377 | @Override |
aoqi@0 | 378 | public void endTag(int prefix, String localName) throws IOException { |
aoqi@0 | 379 | fiout.writeLowLevelEndElement(); |
aoqi@0 | 380 | } |
aoqi@0 | 381 | |
aoqi@0 | 382 | |
aoqi@0 | 383 | @Override |
aoqi@0 | 384 | public void text(Pcdata value, boolean needsSeparatingWhitespace) throws IOException { |
aoqi@0 | 385 | if (needsSeparatingWhitespace) |
aoqi@0 | 386 | fiout.writeLowLevelText(" "); |
aoqi@0 | 387 | |
aoqi@0 | 388 | /* |
aoqi@0 | 389 | * Check if the CharSequence is from a base64Binary data type |
aoqi@0 | 390 | */ |
aoqi@0 | 391 | if (!(value instanceof Base64Data)) { |
aoqi@0 | 392 | final int len = value.length(); |
aoqi@0 | 393 | if(len <buf.length) { |
aoqi@0 | 394 | value.writeTo(buf, 0); |
aoqi@0 | 395 | fiout.writeLowLevelText(buf, len); |
aoqi@0 | 396 | } else { |
aoqi@0 | 397 | fiout.writeLowLevelText(value.toString()); |
aoqi@0 | 398 | } |
aoqi@0 | 399 | } else { |
aoqi@0 | 400 | final Base64Data dataValue = (Base64Data)value; |
aoqi@0 | 401 | // Write out the octets using the base64 encoding algorithm |
aoqi@0 | 402 | fiout.writeLowLevelOctets(dataValue.get(), dataValue.getDataLen()); |
aoqi@0 | 403 | } |
aoqi@0 | 404 | } |
aoqi@0 | 405 | |
aoqi@0 | 406 | |
aoqi@0 | 407 | @Override |
aoqi@0 | 408 | public void text(String value, boolean needsSeparatingWhitespace) throws IOException { |
aoqi@0 | 409 | if (needsSeparatingWhitespace) |
aoqi@0 | 410 | fiout.writeLowLevelText(" "); |
aoqi@0 | 411 | |
aoqi@0 | 412 | fiout.writeLowLevelText(value); |
aoqi@0 | 413 | } |
aoqi@0 | 414 | |
aoqi@0 | 415 | |
aoqi@0 | 416 | @Override |
aoqi@0 | 417 | public void beginStartTag(int prefix, String localName) throws IOException { |
aoqi@0 | 418 | fiout.writeLowLevelTerminationAndMark(); |
aoqi@0 | 419 | |
aoqi@0 | 420 | int type = EncodingConstants.ELEMENT; |
aoqi@0 | 421 | if (nsContext.getCurrent().count() > 0) { |
aoqi@0 | 422 | final NamespaceContextImpl.Element nse = nsContext.getCurrent(); |
aoqi@0 | 423 | |
aoqi@0 | 424 | fiout.writeLowLevelStartNamespaces(); |
aoqi@0 | 425 | for (int i = nse.count() - 1; i >= 0; i--) { |
aoqi@0 | 426 | final String uri = nse.getNsUri(i); |
aoqi@0 | 427 | if (uri.length() == 0 && nse.getBase() == 1) |
aoqi@0 | 428 | continue; // no point in definint xmlns='' on the root |
aoqi@0 | 429 | fiout.writeLowLevelNamespace(nse.getPrefix(i), uri); |
aoqi@0 | 430 | } |
aoqi@0 | 431 | fiout.writeLowLevelEndNamespaces(); |
aoqi@0 | 432 | |
aoqi@0 | 433 | type= 0; |
aoqi@0 | 434 | } |
aoqi@0 | 435 | |
aoqi@0 | 436 | final boolean isIndexed = fiout.writeLowLevelStartElement( |
aoqi@0 | 437 | type, |
aoqi@0 | 438 | nsContext.getPrefix(prefix), |
aoqi@0 | 439 | localName, |
aoqi@0 | 440 | nsContext.getNamespaceURI(prefix)); |
aoqi@0 | 441 | |
aoqi@0 | 442 | if (!isIndexed) |
aoqi@0 | 443 | tables.incrementMaxIndexValue(); |
aoqi@0 | 444 | } |
aoqi@0 | 445 | |
aoqi@0 | 446 | @Override |
aoqi@0 | 447 | public void attribute(int prefix, String localName, String value) throws IOException { |
aoqi@0 | 448 | fiout.writeLowLevelStartAttributes(); |
aoqi@0 | 449 | |
aoqi@0 | 450 | boolean isIndexed; |
aoqi@0 | 451 | if (prefix == -1) |
aoqi@0 | 452 | isIndexed = fiout.writeLowLevelAttribute("", "", localName); |
aoqi@0 | 453 | else |
aoqi@0 | 454 | isIndexed = fiout.writeLowLevelAttribute( |
aoqi@0 | 455 | nsContext.getPrefix(prefix), |
aoqi@0 | 456 | nsContext.getNamespaceURI(prefix), |
aoqi@0 | 457 | localName); |
aoqi@0 | 458 | |
aoqi@0 | 459 | if (!isIndexed) |
aoqi@0 | 460 | tables.incrementMaxIndexValue(); |
aoqi@0 | 461 | |
aoqi@0 | 462 | fiout.writeLowLevelAttributeValue(value); |
aoqi@0 | 463 | } |
aoqi@0 | 464 | } |