286N/A/*
286N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
286N/A *
286N/A * This code is free software; you can redistribute it and/or modify it
286N/A * under the terms of the GNU General Public License version 2 only, as
286N/A * published by the Free Software Foundation. Oracle designates this
286N/A * particular file as subject to the "Classpath" exception as provided
286N/A * by Oracle in the LICENSE file that accompanied this code.
286N/A *
286N/A * This code is distributed in the hope that it will be useful, but WITHOUT
286N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
286N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
286N/A * version 2 for more details (a copy is included in the LICENSE file that
286N/A * accompanied this code).
286N/A *
286N/A * You should have received a copy of the GNU General Public License version
286N/A * 2 along with this work; if not, write to the Free Software Foundation,
286N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
286N/A *
286N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
286N/A * or visit www.oracle.com if you need additional information or have any
286N/A * questions.
286N/A */
286N/A
286N/Apackage com.sun.xml.internal.stream.writers;
286N/A
286N/Aimport java.lang.reflect.InvocationTargetException;
286N/Aimport java.lang.reflect.Method;
286N/Aimport javax.xml.XMLConstants;
286N/Aimport javax.xml.namespace.NamespaceContext;
286N/Aimport javax.xml.stream.XMLStreamException;
286N/Aimport javax.xml.stream.XMLStreamWriter;
286N/Aimport javax.xml.transform.dom.DOMResult;
286N/Aimport org.w3c.dom.Attr;
286N/Aimport org.w3c.dom.CDATASection;
286N/Aimport org.w3c.dom.Comment;
286N/Aimport org.w3c.dom.Document;
286N/Aimport org.w3c.dom.Element;
286N/Aimport org.w3c.dom.EntityReference;
286N/Aimport org.w3c.dom.Node;
286N/Aimport org.w3c.dom.ProcessingInstruction;
286N/Aimport org.w3c.dom.Text;
286N/Aimport org.xml.sax.helpers.NamespaceSupport;
286N/A
286N/A/**
286N/A * This class provides support to build a DOM tree using XMLStreamWriter API's.
286N/A * @author K.Venugopal@sun.com
286N/A */
286N/A
286N/A/*
286N/A * TODO : -Venu
286N/A * Internal NamespaceManagement
286N/A * setPrefix
286N/A * support for isRepairNamespace property.
286N/A * Some Unsupported Methods.
286N/A * Change StringBuffer to StringBuilder, when JDK 1.5 will be minimum requirement for SJSXP.
286N/A */
286N/A
286N/Apublic class XMLDOMWriterImpl implements XMLStreamWriter {
286N/A
286N/A
286N/A private Document ownerDoc = null;
286N/A private Node currentNode = null;
286N/A private Node node = null;
286N/A private NamespaceSupport namespaceContext = null;
286N/A private Method mXmlVersion = null;
286N/A private boolean [] needContextPop = null;
286N/A private StringBuffer stringBuffer = null;
286N/A private int resizeValue = 20;
286N/A private int depth = 0;
286N/A /**
286N/A * Creates a new instance of XMLDOMwriterImpl
286N/A * @param result DOMResult object @javax.xml.transform.dom.DOMResult
286N/A */
286N/A public XMLDOMWriterImpl(DOMResult result) {
286N/A
286N/A node = result.getNode();
286N/A if( node.getNodeType() == Node.DOCUMENT_NODE){
286N/A ownerDoc = (Document)node;
286N/A currentNode = ownerDoc;
286N/A }else{
286N/A ownerDoc = node.getOwnerDocument();
286N/A currentNode = node;
286N/A }
286N/A getDLThreeMethods();
286N/A stringBuffer = new StringBuffer();
286N/A needContextPop = new boolean[resizeValue];
286N/A namespaceContext = new NamespaceSupport();
286N/A }
286N/A
286N/A private void getDLThreeMethods(){
286N/A try{
286N/A mXmlVersion = ownerDoc.getClass().getMethod("setXmlVersion",new Class[] {String.class});
286N/A }catch(NoSuchMethodException mex){
286N/A //log these errors at fine level.
286N/A mXmlVersion = null;
286N/A }catch(SecurityException se){
286N/A //log these errors at fine level.
286N/A mXmlVersion = null;
286N/A }
286N/A }
286N/A
286N/A
286N/A /**
286N/A * This method has no effect when called.
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void close() throws XMLStreamException {
286N/A //no-op
286N/A }
286N/A
286N/A /**
286N/A * This method has no effect when called.
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void flush() throws XMLStreamException {
286N/A //no-op
286N/A }
286N/A
286N/A /**
286N/A * {@inheritDoc}
286N/A * @return {@inheritDoc}
286N/A */
286N/A public javax.xml.namespace.NamespaceContext getNamespaceContext() {
286N/A return null;
286N/A }
286N/A
286N/A /**
286N/A * {@inheritDoc}
286N/A * @param namespaceURI {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A * @return {@inheritDoc}
286N/A */
286N/A public String getPrefix(String namespaceURI) throws XMLStreamException {
286N/A String prefix = null;
286N/A if(this.namespaceContext != null){
286N/A prefix = namespaceContext.getPrefix(namespaceURI);
286N/A }
286N/A return prefix;
286N/A }
286N/A
286N/A /**
286N/A * Is not supported in this implementation.
286N/A * @param str {@inheritDoc}
286N/A * @throws java.lang.IllegalArgumentException {@inheritDoc}
286N/A * @return {@inheritDoc}
286N/A */
286N/A public Object getProperty(String str) throws IllegalArgumentException {
286N/A throw new UnsupportedOperationException();
286N/A }
286N/A
286N/A /**
286N/A * Is not supported in this version of the implementation.
286N/A * @param uri {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void setDefaultNamespace(String uri) throws XMLStreamException {
286N/A namespaceContext.declarePrefix(XMLConstants.DEFAULT_NS_PREFIX, uri);
286N/A if(!needContextPop[depth]){
286N/A needContextPop[depth] = true;
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * {@inheritDoc}
286N/A * @param namespaceContext {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void setNamespaceContext(javax.xml.namespace.NamespaceContext namespaceContext) throws XMLStreamException {
286N/A throw new UnsupportedOperationException();
286N/A }
286N/A
286N/A /**
286N/A * Is not supported in this version of the implementation.
286N/A * @param prefix {@inheritDoc}
286N/A * @param uri {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void setPrefix(String prefix, String uri) throws XMLStreamException {
286N/A if(prefix == null){
286N/A throw new XMLStreamException("Prefix cannot be null");
286N/A }
286N/A namespaceContext.declarePrefix(prefix, uri);
286N/A if(!needContextPop[depth]){
286N/A needContextPop[depth] = true;
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
286N/A * @param localName {@inheritDoc}
286N/A * @param value {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeAttribute(String localName, String value) throws XMLStreamException {
286N/A
286N/A if(currentNode.getNodeType() == Node.ELEMENT_NODE){
286N/A Attr attr = ownerDoc.createAttribute(localName);
286N/A attr.setValue(value);
286N/A ((Element)currentNode).setAttributeNode(attr);
286N/A }else{
286N/A //Convert node type to String
286N/A throw new IllegalStateException("Current DOM Node type is "+ currentNode.getNodeType() +
286N/A "and does not allow attributes to be set ");
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
286N/A * @param namespaceURI {@inheritDoc}
286N/A * @param localName {@inheritDoc}
286N/A * @param value {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeAttribute(String namespaceURI,String localName,String value)throws XMLStreamException {
286N/A if(currentNode.getNodeType() == Node.ELEMENT_NODE){
286N/A String prefix = null;
286N/A if(namespaceURI == null ){
286N/A throw new XMLStreamException("NamespaceURI cannot be null");
286N/A }
286N/A if(localName == null){
286N/A throw new XMLStreamException("Local name cannot be null");
286N/A }
286N/A if(namespaceContext != null){
286N/A prefix = namespaceContext.getPrefix(namespaceURI);
286N/A }
286N/A
286N/A if(prefix == null){
286N/A throw new XMLStreamException("Namespace URI "+namespaceURI +
286N/A "is not bound to any prefix" );
286N/A }
286N/A
286N/A String qualifiedName = null;
286N/A if(prefix.equals("")){
286N/A qualifiedName = localName;
286N/A }else{
286N/A qualifiedName = getQName(prefix,localName);
286N/A }
286N/A Attr attr = ownerDoc.createAttributeNS(namespaceURI, qualifiedName);
286N/A attr.setValue(value);
286N/A ((Element)currentNode).setAttributeNode(attr);
286N/A }else{
286N/A //Convert node type to String
286N/A throw new IllegalStateException("Current DOM Node type is "+ currentNode.getNodeType() +
286N/A "and does not allow attributes to be set ");
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Creates a DOM Atrribute @see org.w3c.dom.Node and associates it with the current DOM element @see org.w3c.dom.Node.
286N/A * @param prefix {@inheritDoc}
286N/A * @param namespaceURI {@inheritDoc}
286N/A * @param localName {@inheritDoc}
286N/A * @param value {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeAttribute(String prefix,String namespaceURI,String localName,String value)throws XMLStreamException {
286N/A if(currentNode.getNodeType() == Node.ELEMENT_NODE){
286N/A if(namespaceURI == null ){
286N/A throw new XMLStreamException("NamespaceURI cannot be null");
286N/A }
286N/A if(localName == null){
286N/A throw new XMLStreamException("Local name cannot be null");
286N/A }
286N/A if(prefix == null){
286N/A throw new XMLStreamException("prefix cannot be null");
286N/A }
286N/A String qualifiedName = null;
286N/A if(prefix.equals("")){
286N/A qualifiedName = localName;
286N/A }else{
286N/A
286N/A qualifiedName = getQName(prefix,localName);
286N/A }
286N/A Attr attr = ownerDoc.createAttributeNS(namespaceURI, qualifiedName);
286N/A attr.setValue(value);
286N/A ((Element)currentNode).setAttributeNodeNS(attr);
286N/A }else{
286N/A //Convert node type to String
286N/A throw new IllegalStateException("Current DOM Node type is "+ currentNode.getNodeType() +
286N/A "and does not allow attributes to be set ");
286N/A }
286N/A
286N/A }
286N/A
286N/A /**
286N/A * Creates a CDATA object @see org.w3c.dom.CDATASection.
286N/A * @param data {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeCData(String data) throws XMLStreamException {
286N/A if(data == null){
286N/A throw new XMLStreamException("CDATA cannot be null");
286N/A }
286N/A
286N/A CDATASection cdata = ownerDoc.createCDATASection(data);
286N/A getNode().appendChild(cdata);
286N/A }
286N/A
286N/A /**
286N/A * Creates a character object @see org.w3c.dom.Text and appends it to the current
286N/A * element in the DOM tree.
286N/A * @param charData {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeCharacters(String charData) throws XMLStreamException {
286N/A Text text = ownerDoc.createTextNode(charData);
286N/A currentNode.appendChild(text);
286N/A }
286N/A
286N/A /**
286N/A * Creates a character object @see org.w3c.dom.Text and appends it to the current
286N/A * element in the DOM tree.
286N/A * @param values {@inheritDoc}
286N/A * @param param {@inheritDoc}
286N/A * @param param2 {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeCharacters(char[] values, int param, int param2) throws XMLStreamException {
286N/A
286N/A Text text = ownerDoc.createTextNode(new String(values,param,param2));
286N/A currentNode.appendChild(text);
286N/A }
286N/A
286N/A /**
286N/A * Creates a Comment object @see org.w3c.dom.Comment and appends it to the current
286N/A * element in the DOM tree.
286N/A * @param str {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeComment(String str) throws XMLStreamException {
286N/A Comment comment = ownerDoc.createComment(str);
286N/A getNode().appendChild(comment);
286N/A }
286N/A
286N/A /**
286N/A * This method is not supported in this implementation.
286N/A * @param str {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeDTD(String str) throws XMLStreamException {
286N/A throw new UnsupportedOperationException();
286N/A }
286N/A
286N/A /**
286N/A * Creates a DOM attribute and adds it to the current element in the DOM tree.
286N/A * @param namespaceURI {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
286N/A if(currentNode.getNodeType() == Node.ELEMENT_NODE){
286N/A String qname = XMLConstants.XMLNS_ATTRIBUTE;
286N/A ((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI);
286N/A }else{
286N/A //Convert node type to String
286N/A throw new IllegalStateException("Current DOM Node type is "+ currentNode.getNodeType() +
286N/A "and does not allow attributes to be set ");
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * creates a DOM Element and appends it to the current element in the tree.
286N/A * @param localName {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeEmptyElement(String localName) throws XMLStreamException {
286N/A if(ownerDoc != null){
286N/A Element element = ownerDoc.createElement(localName);
286N/A if(currentNode!=null){
286N/A currentNode.appendChild(element);
286N/A }else{
286N/A ownerDoc.appendChild(element);
286N/A }
286N/A }
286N/A
286N/A }
286N/A
286N/A /**
286N/A * creates a DOM Element and appends it to the current element in the tree.
286N/A * @param namespaceURI {@inheritDoc}
286N/A * @param localName {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
286N/A if(ownerDoc != null){
286N/A String qualifiedName = null;
286N/A String prefix = null;
286N/A if(namespaceURI == null ){
286N/A throw new XMLStreamException("NamespaceURI cannot be null");
286N/A }
286N/A if(localName == null){
286N/A throw new XMLStreamException("Local name cannot be null");
286N/A }
286N/A
286N/A if(namespaceContext != null){
286N/A prefix = namespaceContext.getPrefix(namespaceURI);
286N/A }
286N/A if(prefix == null){
286N/A throw new XMLStreamException("Namespace URI "+namespaceURI +
286N/A "is not bound to any prefix" );
286N/A }
286N/A if("".equals(prefix)){
286N/A qualifiedName = localName;
286N/A }else{
286N/A
286N/A qualifiedName = getQName(prefix,localName);
286N/A
286N/A }
286N/A Element element = ownerDoc.createElementNS(namespaceURI, qualifiedName);
286N/A if(currentNode!=null){
286N/A currentNode.appendChild(element);
286N/A }else{
286N/A ownerDoc.appendChild(element);
286N/A }
286N/A //currentNode = element;
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * creates a DOM Element and appends it to the current element in the tree.
286N/A * @param prefix {@inheritDoc}
286N/A * @param localName {@inheritDoc}
286N/A * @param namespaceURI {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
286N/A if(ownerDoc != null){
286N/A if(namespaceURI == null ){
286N/A throw new XMLStreamException("NamespaceURI cannot be null");
286N/A }
286N/A if(localName == null){
286N/A throw new XMLStreamException("Local name cannot be null");
286N/A }
286N/A if(prefix == null){
286N/A throw new XMLStreamException("Prefix cannot be null");
286N/A }
286N/A String qualifiedName = null;
286N/A if("".equals(prefix)){
286N/A qualifiedName = localName;
286N/A }else{
286N/A qualifiedName = getQName(prefix,localName);
286N/A }
286N/A Element el = ownerDoc.createElementNS(namespaceURI,qualifiedName);
286N/A if(currentNode!=null){
286N/A currentNode.appendChild(el);
286N/A }else{
286N/A ownerDoc.appendChild(el);
286N/A }
286N/A
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Will reset current Node pointer maintained by the implementation.
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeEndDocument() throws XMLStreamException {
286N/A //What do you want me to do eh! :)
286N/A currentNode = null;
286N/A for(int i=0; i< depth;i++){
286N/A if(needContextPop[depth]){
286N/A needContextPop[depth] = false;
286N/A namespaceContext.popContext();
286N/A }
286N/A depth--;
286N/A }
286N/A depth =0;
286N/A }
286N/A
286N/A /**
286N/A * Internal current Node pointer will point to the parent of the current Node.
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeEndElement() throws XMLStreamException {
286N/A Node node= currentNode.getParentNode();
286N/A if(currentNode.getNodeType() == Node.DOCUMENT_NODE){
286N/A currentNode = null;
286N/A }else{
286N/A currentNode = node;
286N/A }
286N/A if(needContextPop[depth]){
286N/A needContextPop[depth] = false;
286N/A namespaceContext.popContext();
286N/A }
286N/A depth--;
286N/A }
286N/A
286N/A /**
286N/A * Is not supported in this implementation.
286N/A * @param name {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeEntityRef(String name) throws XMLStreamException {
286N/A EntityReference er = ownerDoc.createEntityReference(name);
286N/A currentNode.appendChild(er);
286N/A }
286N/A
286N/A /**
286N/A * creates a namespace attribute and will associate it with the current element in
286N/A * the DOM tree.
286N/A * @param prefix {@inheritDoc}
286N/A * @param namespaceURI {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
286N/A
286N/A if (prefix == null) {
286N/A throw new XMLStreamException("prefix cannot be null");
286N/A }
286N/A
286N/A if (namespaceURI == null) {
286N/A throw new XMLStreamException("NamespaceURI cannot be null");
286N/A }
286N/A
286N/A String qname = null;
286N/A
286N/A if (prefix.equals("")) {
286N/A qname = XMLConstants.XMLNS_ATTRIBUTE;
286N/A } else {
286N/A qname = getQName(XMLConstants.XMLNS_ATTRIBUTE,prefix);
286N/A }
286N/A
286N/A ((Element)currentNode).setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,qname, namespaceURI);
286N/A }
286N/A
286N/A /**
286N/A * is not supported in this release.
286N/A * @param target {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeProcessingInstruction(String target) throws XMLStreamException {
286N/A if(target == null){
286N/A throw new XMLStreamException("Target cannot be null");
286N/A }
286N/A ProcessingInstruction pi = ownerDoc.createProcessingInstruction(target, "");
286N/A currentNode.appendChild(pi);
286N/A }
286N/A
286N/A /**
286N/A * is not supported in this release.
286N/A * @param target {@inheritDoc}
286N/A * @param data {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
286N/A if(target == null){
286N/A throw new XMLStreamException("Target cannot be null");
286N/A }
286N/A ProcessingInstruction pi = ownerDoc.createProcessingInstruction(target, data);
286N/A currentNode.appendChild(pi);
286N/A }
286N/A
286N/A /**
286N/A * will set version on the Document object when the DOM Node passed to this implementation
286N/A * supports DOM Level3 API's.
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeStartDocument() throws XMLStreamException {
286N/A try{
286N/A if(mXmlVersion != null){
286N/A mXmlVersion.invoke(ownerDoc, new Object[] {"1.0"});
286N/A }
286N/A }catch(IllegalAccessException iae){
286N/A throw new XMLStreamException(iae);
286N/A }catch(InvocationTargetException ite){
286N/A throw new XMLStreamException(ite);
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * will set version on the Document object when the DOM Node passed to this implementation
286N/A * supports DOM Level3 API's.
286N/A * @param version {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeStartDocument(String version) throws XMLStreamException {
286N/A try{
286N/A if(mXmlVersion != null){
286N/A mXmlVersion.invoke(ownerDoc, new Object[] {version});
286N/A }
286N/A }catch(IllegalAccessException iae){
286N/A throw new XMLStreamException(iae);
286N/A }catch(InvocationTargetException ite){
286N/A throw new XMLStreamException(ite);
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * will set version on the Document object when the DOM Node passed to this implementation
286N/A * supports DOM Level3 API's.
286N/A * @param encoding {@inheritDoc}
286N/A * @param version {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeStartDocument(String encoding, String version) throws XMLStreamException {
286N/A try{
286N/A if(mXmlVersion != null){
286N/A mXmlVersion.invoke(ownerDoc, new Object[] {version});
286N/A }
286N/A }catch(IllegalAccessException iae){
286N/A throw new XMLStreamException(iae);
286N/A }catch(InvocationTargetException ite){
286N/A throw new XMLStreamException(ite);
286N/A }
286N/A //TODO: What to do with encoding.-Venu
286N/A }
286N/A
286N/A /**
286N/A * creates a DOM Element and appends it to the current element in the tree.
286N/A * @param localName {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeStartElement(String localName) throws XMLStreamException {
286N/A if(ownerDoc != null){
286N/A Element element = ownerDoc.createElement(localName);
286N/A if(currentNode!=null){
286N/A currentNode.appendChild(element);
286N/A }else{
286N/A ownerDoc.appendChild(element);
286N/A }
286N/A currentNode = element;
286N/A }
286N/A if(needContextPop[depth]){
286N/A namespaceContext.pushContext();
286N/A }
286N/A incDepth();
286N/A }
286N/A
286N/A /**
286N/A * creates a DOM Element and appends it to the current element in the tree.
286N/A * @param namespaceURI {@inheritDoc}
286N/A * @param localName {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
286N/A if(ownerDoc != null){
286N/A String qualifiedName = null;
286N/A String prefix = null;
286N/A
286N/A if(namespaceURI == null ){
286N/A throw new XMLStreamException("NamespaceURI cannot be null");
286N/A }
286N/A if(localName == null){
286N/A throw new XMLStreamException("Local name cannot be null");
286N/A }
286N/A
286N/A if(namespaceContext != null){
286N/A prefix = namespaceContext.getPrefix(namespaceURI);
286N/A }
286N/A if(prefix == null){
286N/A throw new XMLStreamException("Namespace URI "+namespaceURI +
286N/A "is not bound to any prefix" );
286N/A }
286N/A if("".equals(prefix)){
286N/A qualifiedName = localName;
286N/A }else{
286N/A qualifiedName = getQName(prefix,localName);
286N/A }
286N/A
286N/A Element element = ownerDoc.createElementNS(namespaceURI, qualifiedName);
286N/A
286N/A if(currentNode!=null){
286N/A currentNode.appendChild(element);
286N/A }else{
286N/A ownerDoc.appendChild(element);
286N/A }
286N/A currentNode = element;
286N/A }
286N/A if(needContextPop[depth]){
286N/A namespaceContext.pushContext();
286N/A }
286N/A incDepth();
286N/A }
286N/A
286N/A /**
286N/A * creates a DOM Element and appends it to the current element in the tree.
286N/A * @param prefix {@inheritDoc}
286N/A * @param localName {@inheritDoc}
286N/A * @param namespaceURI {@inheritDoc}
286N/A * @throws javax.xml.stream.XMLStreamException {@inheritDoc}
286N/A */
286N/A public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
286N/A
286N/A if(ownerDoc != null){
286N/A String qname = null;
286N/A if(namespaceURI == null ){
286N/A throw new XMLStreamException("NamespaceURI cannot be null");
286N/A }
286N/A if(localName == null){
286N/A throw new XMLStreamException("Local name cannot be null");
286N/A }
286N/A if(prefix == null){
286N/A throw new XMLStreamException("Prefix cannot be null");
286N/A }
286N/A
286N/A if(prefix.equals("")){
286N/A qname = localName;
286N/A }else{
286N/A qname = getQName(prefix,localName);
286N/A }
286N/A
286N/A Element el = ownerDoc.createElementNS(namespaceURI,qname);
286N/A
286N/A if(currentNode!=null){
286N/A currentNode.appendChild(el);
286N/A }else{
286N/A ownerDoc.appendChild(el);
286N/A }
286N/A currentNode = el;
286N/A if(needContextPop[depth]){
286N/A namespaceContext.pushContext();
286N/A }
286N/A incDepth();
286N/A
286N/A }
286N/A }
286N/A
286N/A private String getQName(String prefix , String localName){
286N/A stringBuffer.setLength(0);
286N/A stringBuffer.append(prefix);
286N/A stringBuffer.append(":");
286N/A stringBuffer.append(localName);
286N/A return stringBuffer.toString();
286N/A }
286N/A
286N/A private Node getNode(){
286N/A if(currentNode == null){
286N/A return ownerDoc;
286N/A } else{
286N/A return currentNode;
286N/A }
286N/A }
286N/A private void incDepth() {
286N/A depth++;
286N/A if (depth == needContextPop.length) {
286N/A boolean[] array = new boolean[depth + resizeValue];
286N/A System.arraycopy(needContextPop, 0, array, 0, depth);
286N/A needContextPop = array;
286N/A }
286N/A }
286N/A}