< prev index next >

src/java.xml/share/classes/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2017, 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


  27 
  28 import com.sun.org.apache.xerces.internal.impl.Constants;
  29 import com.sun.org.apache.xerces.internal.impl.PropertyManager;
  30 import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
  31 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  32 import com.sun.org.apache.xerces.internal.xni.QName;
  33 import com.sun.xml.internal.stream.util.ReadOnlyIterator;
  34 import java.io.FileOutputStream;
  35 import java.io.IOException;
  36 import java.io.OutputStream;
  37 import java.io.OutputStreamWriter;
  38 import java.io.Writer;
  39 import java.nio.charset.Charset;
  40 import java.nio.charset.CharsetEncoder;
  41 import java.util.AbstractMap;
  42 import java.util.ArrayList;
  43 import java.util.HashMap;
  44 import java.util.Iterator;
  45 import java.util.List;
  46 import java.util.Map;

  47 import java.util.Random;
  48 import java.util.Set;
  49 import javax.xml.XMLConstants;
  50 import javax.xml.namespace.NamespaceContext;
  51 import javax.xml.stream.XMLOutputFactory;
  52 import javax.xml.stream.XMLStreamConstants;
  53 import javax.xml.stream.XMLStreamException;
  54 import javax.xml.transform.stream.StreamResult;
  55 import jdk.xml.internal.SecuritySupport;
  56 
  57 /**
  58  * This class implements a StAX XMLStreamWriter. It extends
  59  * <code>AbstractMap</code> in order to support a getter for
  60  * implementation-specific properties. For example, you can get
  61  * the underlying <code>OutputStream</code> by casting an instance
  62  * of this class to <code>Map</code> and calling
  63  * <code>getProperty(OUTPUTSTREAM_PROPERTY)</code>.
  64  *
  65  * @author Neeraj Bajaj
  66  * @author K.Venugopal


1712      * return the prefix if the attribute has an uri the same as that of the default namespace
1713      */
1714     private String getAttrPrefix(String uri) {
1715         if (fAttrNamespace != null) {
1716             return fAttrNamespace.get(uri);
1717         }
1718         return null;
1719     }
1720     private void addAttrNamespace(String prefix, String uri) {
1721         if (fAttrNamespace == null) {
1722             fAttrNamespace = new HashMap<>();
1723         }
1724         fAttrNamespace.put(prefix, uri);
1725     }
1726     /**
1727      * @param uri
1728      * @return
1729      */
1730     private boolean isDefaultNamespace(String uri) {
1731         String defaultNamespace = fInternalNamespaceContext.getURI(DEFAULT_PREFIX);
1732 
1733         if (uri.equals(defaultNamespace)) {
1734             return true;
1735         }
1736 
1737         return false;
1738     }
1739 
1740     /**
1741      * @param prefix
1742      * @param uri
1743      * @return
1744      */
1745     private boolean checkUserNamespaceContext(String prefix, String uri) {
1746         if (fNamespaceContext.userContext != null) {
1747             String tmpURI = fNamespaceContext.userContext.getNamespaceURI(prefix);
1748 
1749             if ((tmpURI != null) && tmpURI.equals(uri)) {
1750                 return true;
1751             }
1752         }
1753 
1754         return false;
1755     }
1756 
1757     /**


   1 /*
   2  * Copyright (c) 2005, 2019, 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


  27 
  28 import com.sun.org.apache.xerces.internal.impl.Constants;
  29 import com.sun.org.apache.xerces.internal.impl.PropertyManager;
  30 import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
  31 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  32 import com.sun.org.apache.xerces.internal.xni.QName;
  33 import com.sun.xml.internal.stream.util.ReadOnlyIterator;
  34 import java.io.FileOutputStream;
  35 import java.io.IOException;
  36 import java.io.OutputStream;
  37 import java.io.OutputStreamWriter;
  38 import java.io.Writer;
  39 import java.nio.charset.Charset;
  40 import java.nio.charset.CharsetEncoder;
  41 import java.util.AbstractMap;
  42 import java.util.ArrayList;
  43 import java.util.HashMap;
  44 import java.util.Iterator;
  45 import java.util.List;
  46 import java.util.Map;
  47 import java.util.Objects;
  48 import java.util.Random;
  49 import java.util.Set;
  50 import javax.xml.XMLConstants;
  51 import javax.xml.namespace.NamespaceContext;
  52 import javax.xml.stream.XMLOutputFactory;
  53 import javax.xml.stream.XMLStreamConstants;
  54 import javax.xml.stream.XMLStreamException;
  55 import javax.xml.transform.stream.StreamResult;
  56 import jdk.xml.internal.SecuritySupport;
  57 
  58 /**
  59  * This class implements a StAX XMLStreamWriter. It extends
  60  * <code>AbstractMap</code> in order to support a getter for
  61  * implementation-specific properties. For example, you can get
  62  * the underlying <code>OutputStream</code> by casting an instance
  63  * of this class to <code>Map</code> and calling
  64  * <code>getProperty(OUTPUTSTREAM_PROPERTY)</code>.
  65  *
  66  * @author Neeraj Bajaj
  67  * @author K.Venugopal


1713      * return the prefix if the attribute has an uri the same as that of the default namespace
1714      */
1715     private String getAttrPrefix(String uri) {
1716         if (fAttrNamespace != null) {
1717             return fAttrNamespace.get(uri);
1718         }
1719         return null;
1720     }
1721     private void addAttrNamespace(String prefix, String uri) {
1722         if (fAttrNamespace == null) {
1723             fAttrNamespace = new HashMap<>();
1724         }
1725         fAttrNamespace.put(prefix, uri);
1726     }
1727     /**
1728      * @param uri
1729      * @return
1730      */
1731     private boolean isDefaultNamespace(String uri) {
1732         String defaultNamespace = fInternalNamespaceContext.getURI(DEFAULT_PREFIX);
1733         return Objects.equals(uri, defaultNamespace);





1734     }
1735 
1736     /**
1737      * @param prefix
1738      * @param uri
1739      * @return
1740      */
1741     private boolean checkUserNamespaceContext(String prefix, String uri) {
1742         if (fNamespaceContext.userContext != null) {
1743             String tmpURI = fNamespaceContext.userContext.getNamespaceURI(prefix);
1744 
1745             if ((tmpURI != null) && tmpURI.equals(uri)) {
1746                 return true;
1747             }
1748         }
1749 
1750         return false;
1751     }
1752 
1753     /**


< prev index next >