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