Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/com/sun/xml/internal/stream/writers/XMLDOMWriterImpl.java
48527 views
1
/*
2
* Copyright (c) 2005, 2006, 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
23
* questions.
24
*/
25
26
package com.sun.xml.internal.stream.writers;
27
28
import java.lang.reflect.InvocationTargetException;
29
import java.lang.reflect.Method;
30
import javax.xml.XMLConstants;
31
import javax.xml.namespace.NamespaceContext;
32
import javax.xml.stream.XMLStreamException;
33
import javax.xml.stream.XMLStreamWriter;
34
import javax.xml.transform.dom.DOMResult;
35
import org.w3c.dom.Attr;
36
import org.w3c.dom.CDATASection;
37
import org.w3c.dom.Comment;
38
import org.w3c.dom.Document;
39
import org.w3c.dom.Element;
40
import org.w3c.dom.EntityReference;
41
import org.w3c.dom.Node;
42
import org.w3c.dom.ProcessingInstruction;
43
import org.w3c.dom.Text;
44
import org.xml.sax.helpers.NamespaceSupport;
45
46
/**
47
* This class provides support to build a DOM tree using XMLStreamWriter API's.
48
* @author [email protected]
49
*/
50
51
/*
52
* TODO : -Venu
53
* Internal NamespaceManagement
54
* setPrefix
55
* support for isRepairNamespace property.
56
* Some Unsupported Methods.
57
* Change StringBuffer to StringBuilder, when JDK 1.5 will be minimum requirement for SJSXP.
58
*/
59
60
public class XMLDOMWriterImpl implements XMLStreamWriter {
61
62
63
private Document ownerDoc = null;
64
private Node currentNode = null;
65
private Node node = null;
66
private NamespaceSupport namespaceContext = null;
67
private Method mXmlVersion = null;
68
private boolean [] needContextPop = null;
69
private StringBuffer stringBuffer = null;
70
private int resizeValue = 20;
71
private int depth = 0;
72
/**
73
* Creates a new instance of XMLDOMwriterImpl
74
* @param result DOMResult object @javax.xml.transform.dom.DOMResult
75
*/
76
public XMLDOMWriterImpl(DOMResult result) {
77
78
node = result.getNode();
79
if( node.getNodeType() == Node.DOCUMENT_NODE){
80
ownerDoc = (Document)node;
81
currentNode = ownerDoc;
82
}else{
83
ownerDoc = node.getOwnerDocument();
84
currentNode = node;
85
}
86
getDLThreeMethods();
87
stringBuffer = new StringBuffer();
88
needContextPop = new boolean[resizeValue];
89
namespaceContext = new NamespaceSupport();
90
}
91
92
private void getDLThreeMethods(){
93
try{
94
mXmlVersion = ownerDoc.getClass().getMethod("setXmlVersion",new Class[] {String.class});
95
}catch(NoSuchMethodException mex){
96
//log these errors at fine level.
97
mXmlVersion = null;
98
}catch(SecurityException se){
99
//log these errors at fine level.
100
mXmlVersion = null;
101
}
102
}
103
104
105
/**
106
* This method has no effect when called.
107
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
108
*/
109
public void close() throws XMLStreamException {
110
//no-op
111
}
112
113
/**
114
* This method has no effect when called.
115
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
116
*/
117
public void flush() throws XMLStreamException {
118
//no-op
119
}
120
121
/**
122
* {@inheritDoc}
123
* @return {@inheritDoc}
124
*/
125
public javax.xml.namespace.NamespaceContext getNamespaceContext() {
126
return null;
127
}
128
129
/**
130
* {@inheritDoc}
131
* @param namespaceURI {@inheritDoc}
132
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
133
* @return {@inheritDoc}
134
*/
135
public String getPrefix(String namespaceURI) throws XMLStreamException {
136
String prefix = null;
137
if(this.namespaceContext != null){
138
prefix = namespaceContext.getPrefix(namespaceURI);
139
}
140
return prefix;
141
}
142
143
/**
144
* Is not supported in this implementation.
145
* @param str {@inheritDoc}
146
* @throws java.lang.IllegalArgumentException {@inheritDoc}
147
* @return {@inheritDoc}
148
*/
149
public Object getProperty(String str) throws IllegalArgumentException {
150
throw new UnsupportedOperationException();
151
}
152
153
/**
154
* Is not supported in this version of the implementation.
155
* @param uri {@inheritDoc}
156
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
157
*/
158
public void setDefaultNamespace(String uri) throws XMLStreamException {
159
namespaceContext.declarePrefix(XMLConstants.DEFAULT_NS_PREFIX, uri);
160
if(!needContextPop[depth]){
161
needContextPop[depth] = true;
162
}
163
}
164
165
/**
166
* {@inheritDoc}
167
* @param namespaceContext {@inheritDoc}
168
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
169
*/
170
public void setNamespaceContext(javax.xml.namespace.NamespaceContext namespaceContext) throws XMLStreamException {
171
throw new UnsupportedOperationException();
172
}
173
174
/**
175
* Is not supported in this version of the implementation.
176
* @param prefix {@inheritDoc}
177
* @param uri {@inheritDoc}
178
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
179
*/
180
public void setPrefix(String prefix, String uri) throws XMLStreamException {
181
if(prefix == null){
182
throw new XMLStreamException("Prefix cannot be null");
183
}
184
namespaceContext.declarePrefix(prefix, uri);
185
if(!needContextPop[depth]){
186
needContextPop[depth] = true;
187
}
188
}
189
190
/**
191
* Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
192
* @param localName {@inheritDoc}
193
* @param value {@inheritDoc}
194
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
195
*/
196
public void writeAttribute(String localName, String value) throws XMLStreamException {
197
198
if(currentNode.getNodeType() == Node.ELEMENT_NODE){
199
Attr attr = ownerDoc.createAttribute(localName);
200
attr.setValue(value);
201
((Element)currentNode).setAttributeNode(attr);
202
}else{
203
//Convert node type to String
204
throw new IllegalStateException("Current DOM Node type is "+ currentNode.getNodeType() +
205
"and does not allow attributes to be set ");
206
}
207
}
208
209
/**
210
* Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
211
* @param namespaceURI {@inheritDoc}
212
* @param localName {@inheritDoc}
213
* @param value {@inheritDoc}
214
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
215
*/
216
public void writeAttribute(String namespaceURI,String localName,String value)throws XMLStreamException {
217
if(currentNode.getNodeType() == Node.ELEMENT_NODE){
218
String prefix = null;
219
if(namespaceURI == null ){
220
throw new XMLStreamException("NamespaceURI cannot be null");
221
}
222
if(localName == null){
223
throw new XMLStreamException("Local name cannot be null");
224
}
225
if(namespaceContext != null){
226
prefix = namespaceContext.getPrefix(namespaceURI);
227
}
228
229
if(prefix == null){
230
throw new XMLStreamException("Namespace URI "+namespaceURI +
231
"is not bound to any prefix" );
232
}
233
234
String qualifiedName = null;
235
if(prefix.equals("")){
236
qualifiedName = localName;
237
}else{
238
qualifiedName = getQName(prefix,localName);
239
}
240
Attr attr = ownerDoc.createAttributeNS(namespaceURI, qualifiedName);
241
attr.setValue(value);
242
((Element)currentNode).setAttributeNode(attr);
243
}else{
244
//Convert node type to String
245
throw new IllegalStateException("Current DOM Node type is "+ currentNode.getNodeType() +
246
"and does not allow attributes to be set ");
247
}
248
}
249
250
/**
251
* Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
252
* @param prefix {@inheritDoc}
253
* @param namespaceURI {@inheritDoc}
254
* @param localName {@inheritDoc}
255
* @param value {@inheritDoc}
256
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
257
*/
258
public void writeAttribute(String prefix,String namespaceURI,String localName,String value)throws XMLStreamException {
259
if(currentNode.getNodeType() == Node.ELEMENT_NODE){
260
if(namespaceURI == null ){
261
throw new XMLStreamException("NamespaceURI cannot be null");
262
}
263
if(localName == null){
264
throw new XMLStreamException("Local name cannot be null");
265
}
266
if(prefix == null){
267
throw new XMLStreamException("prefix cannot be null");
268
}
269
String qualifiedName = null;
270
if(prefix.equals("")){
271
qualifiedName = localName;
272
}else{
273
274
qualifiedName = getQName(prefix,localName);
275
}
276
Attr attr = ownerDoc.createAttributeNS(namespaceURI, qualifiedName);
277
attr.setValue(value);
278
((Element)currentNode).setAttributeNodeNS(attr);
279
}else{
280
//Convert node type to String
281
throw new IllegalStateException("Current DOM Node type is "+ currentNode.getNodeType() +
282
"and does not allow attributes to be set ");
283
}
284
285
}
286
287
/**
288
* Creates a CDATA object @see org.w3c.dom.CDATASection.
289
* @param data {@inheritDoc}
290
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
291
*/
292
public void writeCData(String data) throws XMLStreamException {
293
if(data == null){
294
throw new XMLStreamException("CDATA cannot be null");
295
}
296
297
CDATASection cdata = ownerDoc.createCDATASection(data);
298
getNode().appendChild(cdata);
299
}
300
301
/**
302
* Creates a character object @see org.w3c.dom.Text and appends it to the current
303
* element in the DOM tree.
304
* @param charData {@inheritDoc}
305
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
306
*/
307
public void writeCharacters(String charData) throws XMLStreamException {
308
Text text = ownerDoc.createTextNode(charData);
309
currentNode.appendChild(text);
310
}
311
312
/**
313
* Creates a character object @see org.w3c.dom.Text and appends it to the current
314
* element in the DOM tree.
315
* @param values {@inheritDoc}
316
* @param param {@inheritDoc}
317
* @param param2 {@inheritDoc}
318
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
319
*/
320
public void writeCharacters(char[] values, int param, int param2) throws XMLStreamException {
321
322
Text text = ownerDoc.createTextNode(new String(values,param,param2));
323
currentNode.appendChild(text);
324
}
325
326
/**
327
* Creates a Comment object @see org.w3c.dom.Comment and appends it to the current
328
* element in the DOM tree.
329
* @param str {@inheritDoc}
330
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
331
*/
332
public void writeComment(String str) throws XMLStreamException {
333
Comment comment = ownerDoc.createComment(str);
334
getNode().appendChild(comment);
335
}
336
337
/**
338
* This method is not supported in this implementation.
339
* @param str {@inheritDoc}
340
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
341
*/
342
public void writeDTD(String str) throws XMLStreamException {
343
throw new UnsupportedOperationException();
344
}
345
346
/**
347
* Creates a DOM attribute and adds it to the current element in the DOM tree.
348
* @param namespaceURI {@inheritDoc}
349
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
350
*/
351
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
352
if(currentNode.getNodeType() == Node.ELEMENT_NODE){
353
String qname = XMLConstants.XMLNS_ATTRIBUTE;
354
((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI);
355
}else{
356
//Convert node type to String
357
throw new IllegalStateException("Current DOM Node type is "+ currentNode.getNodeType() +
358
"and does not allow attributes to be set ");
359
}
360
}
361
362
/**
363
* creates a DOM Element and appends it to the current element in the tree.
364
* @param localName {@inheritDoc}
365
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
366
*/
367
public void writeEmptyElement(String localName) throws XMLStreamException {
368
if(ownerDoc != null){
369
Element element = ownerDoc.createElement(localName);
370
if(currentNode!=null){
371
currentNode.appendChild(element);
372
}else{
373
ownerDoc.appendChild(element);
374
}
375
}
376
377
}
378
379
/**
380
* creates a DOM Element and appends it to the current element in the tree.
381
* @param namespaceURI {@inheritDoc}
382
* @param localName {@inheritDoc}
383
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
384
*/
385
public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
386
if(ownerDoc != null){
387
String qualifiedName = null;
388
String prefix = null;
389
if(namespaceURI == null ){
390
throw new XMLStreamException("NamespaceURI cannot be null");
391
}
392
if(localName == null){
393
throw new XMLStreamException("Local name cannot be null");
394
}
395
396
if(namespaceContext != null){
397
prefix = namespaceContext.getPrefix(namespaceURI);
398
}
399
if(prefix == null){
400
throw new XMLStreamException("Namespace URI "+namespaceURI +
401
"is not bound to any prefix" );
402
}
403
if("".equals(prefix)){
404
qualifiedName = localName;
405
}else{
406
407
qualifiedName = getQName(prefix,localName);
408
409
}
410
Element element = ownerDoc.createElementNS(namespaceURI, qualifiedName);
411
if(currentNode!=null){
412
currentNode.appendChild(element);
413
}else{
414
ownerDoc.appendChild(element);
415
}
416
//currentNode = element;
417
}
418
}
419
420
/**
421
* creates a DOM Element and appends it to the current element in the tree.
422
* @param prefix {@inheritDoc}
423
* @param localName {@inheritDoc}
424
* @param namespaceURI {@inheritDoc}
425
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
426
*/
427
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
428
if(ownerDoc != null){
429
if(namespaceURI == null ){
430
throw new XMLStreamException("NamespaceURI cannot be null");
431
}
432
if(localName == null){
433
throw new XMLStreamException("Local name cannot be null");
434
}
435
if(prefix == null){
436
throw new XMLStreamException("Prefix cannot be null");
437
}
438
String qualifiedName = null;
439
if("".equals(prefix)){
440
qualifiedName = localName;
441
}else{
442
qualifiedName = getQName(prefix,localName);
443
}
444
Element el = ownerDoc.createElementNS(namespaceURI,qualifiedName);
445
if(currentNode!=null){
446
currentNode.appendChild(el);
447
}else{
448
ownerDoc.appendChild(el);
449
}
450
451
}
452
}
453
454
/**
455
* Will reset current Node pointer maintained by the implementation.
456
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
457
*/
458
public void writeEndDocument() throws XMLStreamException {
459
//What do you want me to do eh! :)
460
currentNode = null;
461
for(int i=0; i< depth;i++){
462
if(needContextPop[depth]){
463
needContextPop[depth] = false;
464
namespaceContext.popContext();
465
}
466
depth--;
467
}
468
depth =0;
469
}
470
471
/**
472
* Internal current Node pointer will point to the parent of the current Node.
473
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
474
*/
475
public void writeEndElement() throws XMLStreamException {
476
Node node= currentNode.getParentNode();
477
if(currentNode.getNodeType() == Node.DOCUMENT_NODE){
478
currentNode = null;
479
}else{
480
currentNode = node;
481
}
482
if(needContextPop[depth]){
483
needContextPop[depth] = false;
484
namespaceContext.popContext();
485
}
486
depth--;
487
}
488
489
/**
490
* Is not supported in this implementation.
491
* @param name {@inheritDoc}
492
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
493
*/
494
public void writeEntityRef(String name) throws XMLStreamException {
495
EntityReference er = ownerDoc.createEntityReference(name);
496
currentNode.appendChild(er);
497
}
498
499
/**
500
* creates a namespace attribute and will associate it with the current element in
501
* the DOM tree.
502
* @param prefix {@inheritDoc}
503
* @param namespaceURI {@inheritDoc}
504
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
505
*/
506
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
507
508
if (prefix == null) {
509
throw new XMLStreamException("prefix cannot be null");
510
}
511
512
if (namespaceURI == null) {
513
throw new XMLStreamException("NamespaceURI cannot be null");
514
}
515
516
String qname = null;
517
518
if (prefix.equals("")) {
519
qname = XMLConstants.XMLNS_ATTRIBUTE;
520
} else {
521
qname = getQName(XMLConstants.XMLNS_ATTRIBUTE,prefix);
522
}
523
524
((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI);
525
}
526
527
/**
528
* is not supported in this release.
529
* @param target {@inheritDoc}
530
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
531
*/
532
public void writeProcessingInstruction(String target) throws XMLStreamException {
533
if(target == null){
534
throw new XMLStreamException("Target cannot be null");
535
}
536
ProcessingInstruction pi = ownerDoc.createProcessingInstruction(target, "");
537
currentNode.appendChild(pi);
538
}
539
540
/**
541
* is not supported in this release.
542
* @param target {@inheritDoc}
543
* @param data {@inheritDoc}
544
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
545
*/
546
public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
547
if(target == null){
548
throw new XMLStreamException("Target cannot be null");
549
}
550
ProcessingInstruction pi = ownerDoc.createProcessingInstruction(target, data);
551
currentNode.appendChild(pi);
552
}
553
554
/**
555
* will set version on the Document object when the DOM Node passed to this implementation
556
* supports DOM Level3 API's.
557
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
558
*/
559
public void writeStartDocument() throws XMLStreamException {
560
try{
561
if(mXmlVersion != null){
562
mXmlVersion.invoke(ownerDoc, new Object[] {"1.0"});
563
}
564
}catch(IllegalAccessException iae){
565
throw new XMLStreamException(iae);
566
}catch(InvocationTargetException ite){
567
throw new XMLStreamException(ite);
568
}
569
}
570
571
/**
572
* will set version on the Document object when the DOM Node passed to this implementation
573
* supports DOM Level3 API's.
574
* @param version {@inheritDoc}
575
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
576
*/
577
public void writeStartDocument(String version) throws XMLStreamException {
578
try{
579
if(mXmlVersion != null){
580
mXmlVersion.invoke(ownerDoc, new Object[] {version});
581
}
582
}catch(IllegalAccessException iae){
583
throw new XMLStreamException(iae);
584
}catch(InvocationTargetException ite){
585
throw new XMLStreamException(ite);
586
}
587
}
588
589
/**
590
* will set version on the Document object when the DOM Node passed to this implementation
591
* supports DOM Level3 API's.
592
* @param encoding {@inheritDoc}
593
* @param version {@inheritDoc}
594
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
595
*/
596
public void writeStartDocument(String encoding, String version) throws XMLStreamException {
597
try{
598
if(mXmlVersion != null){
599
mXmlVersion.invoke(ownerDoc, new Object[] {version});
600
}
601
}catch(IllegalAccessException iae){
602
throw new XMLStreamException(iae);
603
}catch(InvocationTargetException ite){
604
throw new XMLStreamException(ite);
605
}
606
//TODO: What to do with encoding.-Venu
607
}
608
609
/**
610
* creates a DOM Element and appends it to the current element in the tree.
611
* @param localName {@inheritDoc}
612
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
613
*/
614
public void writeStartElement(String localName) throws XMLStreamException {
615
if(ownerDoc != null){
616
Element element = ownerDoc.createElement(localName);
617
if(currentNode!=null){
618
currentNode.appendChild(element);
619
}else{
620
ownerDoc.appendChild(element);
621
}
622
currentNode = element;
623
}
624
if(needContextPop[depth]){
625
namespaceContext.pushContext();
626
}
627
incDepth();
628
}
629
630
/**
631
* creates a DOM Element and appends it to the current element in the tree.
632
* @param namespaceURI {@inheritDoc}
633
* @param localName {@inheritDoc}
634
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
635
*/
636
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
637
if(ownerDoc != null){
638
String qualifiedName = null;
639
String prefix = null;
640
641
if(namespaceURI == null ){
642
throw new XMLStreamException("NamespaceURI cannot be null");
643
}
644
if(localName == null){
645
throw new XMLStreamException("Local name cannot be null");
646
}
647
648
if(namespaceContext != null){
649
prefix = namespaceContext.getPrefix(namespaceURI);
650
}
651
if(prefix == null){
652
throw new XMLStreamException("Namespace URI "+namespaceURI +
653
"is not bound to any prefix" );
654
}
655
if("".equals(prefix)){
656
qualifiedName = localName;
657
}else{
658
qualifiedName = getQName(prefix,localName);
659
}
660
661
Element element = ownerDoc.createElementNS(namespaceURI, qualifiedName);
662
663
if(currentNode!=null){
664
currentNode.appendChild(element);
665
}else{
666
ownerDoc.appendChild(element);
667
}
668
currentNode = element;
669
}
670
if(needContextPop[depth]){
671
namespaceContext.pushContext();
672
}
673
incDepth();
674
}
675
676
/**
677
* creates a DOM Element and appends it to the current element in the tree.
678
* @param prefix {@inheritDoc}
679
* @param localName {@inheritDoc}
680
* @param namespaceURI {@inheritDoc}
681
* @throws javax.xml.stream.XMLStreamException {@inheritDoc}
682
*/
683
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
684
685
if(ownerDoc != null){
686
String qname = null;
687
if(namespaceURI == null ){
688
throw new XMLStreamException("NamespaceURI cannot be null");
689
}
690
if(localName == null){
691
throw new XMLStreamException("Local name cannot be null");
692
}
693
if(prefix == null){
694
throw new XMLStreamException("Prefix cannot be null");
695
}
696
697
if(prefix.equals("")){
698
qname = localName;
699
}else{
700
qname = getQName(prefix,localName);
701
}
702
703
Element el = ownerDoc.createElementNS(namespaceURI,qname);
704
705
if(currentNode!=null){
706
currentNode.appendChild(el);
707
}else{
708
ownerDoc.appendChild(el);
709
}
710
currentNode = el;
711
if(needContextPop[depth]){
712
namespaceContext.pushContext();
713
}
714
incDepth();
715
716
}
717
}
718
719
private String getQName(String prefix , String localName){
720
stringBuffer.setLength(0);
721
stringBuffer.append(prefix);
722
stringBuffer.append(":");
723
stringBuffer.append(localName);
724
return stringBuffer.toString();
725
}
726
727
private Node getNode(){
728
if(currentNode == null){
729
return ownerDoc;
730
} else{
731
return currentNode;
732
}
733
}
734
private void incDepth() {
735
depth++;
736
if (depth == needContextPop.length) {
737
boolean[] array = new boolean[depth + resizeValue];
738
System.arraycopy(needContextPop, 0, array, 0, depth);
739
needContextPop = array;
740
}
741
}
742
}
743
744