src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/SymbolTable.java
author joehw
Wed, 18 Oct 2017 13:25:49 -0700
changeset 47359 e1a6c0168741
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked Reviewed-by: lancea, rriggs, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Oct 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 * $Id: SymbolTable.java,v 1.5 2005/09/28 13:48:16 pvedula Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
package com.sun.org.apache.xalan.internal.xsltc.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    27
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    28
import java.util.ArrayList;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    29
import java.util.HashMap;
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    30
import java.util.List;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    31
import java.util.Map;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    32
import java.util.Stack;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import java.util.StringTokenizer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * @author Jacek Ambroziak
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * @author Santiago Pericas-Geertsen
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
final class SymbolTable {
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    42
    // These maps are used for all stylesheets
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    43
    private final Map<String, Stylesheet> _stylesheets = new HashMap<>();
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    44
    private final Map<String, List<MethodType>> _primops = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    46
    // These maps are used for some stylesheets
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    47
    private Map<String, VariableBase> _variables = null;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    48
    private Map<String, Template> _templates = null;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    49
    private Map<String, AttributeSet> _attributeSets = null;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    50
    private Map<String, String> _aliases = null;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    51
    private Map<String, Integer> _excludedURI = null;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    52
    private Stack<Map<String, Integer>>     _excludedURIStack = null;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    53
    private Map<String, DecimalFormatting> _decimalFormats = null;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    54
    private Map<String, Key> _keys = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    public DecimalFormatting getDecimalFormatting(QName name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
        if (_decimalFormats == null) return null;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    58
        return(_decimalFormats.get(name.getStringRep()));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    public void addDecimalFormatting(QName name, DecimalFormatting symbols) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    62
        if (_decimalFormats == null) _decimalFormats = new HashMap<>();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    63
        _decimalFormats.put(name.getStringRep(), symbols);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    public Key getKey(QName name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
        if (_keys == null) return null;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    68
        return _keys.get(name.getStringRep());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    public void addKey(QName name, Key key) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    72
        if (_keys == null) _keys = new HashMap<>();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    73
        _keys.put(name.getStringRep(), key);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    public Stylesheet addStylesheet(QName name, Stylesheet node) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    77
        return _stylesheets.put(name.getStringRep(), node);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    public Stylesheet lookupStylesheet(QName name) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    81
        return _stylesheets.get(name.getStringRep());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    public Template addTemplate(Template template) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
        final QName name = template.getName();
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    86
        if (_templates == null) _templates = new HashMap<>();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    87
        return _templates.put(name.getStringRep(), template);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    public Template lookupTemplate(QName name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
        if (_templates == null) return null;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    92
        return _templates.get(name.getStringRep());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
    public Variable addVariable(Variable variable) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    96
        if (_variables == null) _variables = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
        final String name = variable.getName().getStringRep();
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
        return (Variable)_variables.put(name, variable);
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    public Param addParam(Param parameter) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   102
        if (_variables == null) _variables = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
        final String name = parameter.getName().getStringRep();
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
        return (Param)_variables.put(name, parameter);
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
    public Variable lookupVariable(QName qname) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
        if (_variables == null) return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
        final String name = qname.getStringRep();
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   110
        final VariableBase obj = _variables.get(name);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        return obj instanceof Variable ? (Variable)obj : null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    public Param lookupParam(QName qname) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
        if (_variables == null) return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
        final String name = qname.getStringRep();
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   117
        final VariableBase obj = _variables.get(name);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        return obj instanceof Param ? (Param)obj : null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    public SyntaxTreeNode lookupName(QName qname) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
        if (_variables == null) return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
        final String name = qname.getStringRep();
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        return (SyntaxTreeNode)_variables.get(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    public AttributeSet addAttributeSet(AttributeSet atts) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   128
        if (_attributeSets == null) _attributeSets = new HashMap<>();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   129
        return _attributeSets.put(atts.getName().getStringRep(), atts);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    public AttributeSet lookupAttributeSet(QName name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
        if (_attributeSets == null) return null;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   134
        return _attributeSets.get(name.getStringRep());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     * Add a primitive operator or function to the symbol table. To avoid
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
     * name clashes with user-defined names, the prefix <tt>PrimopPrefix</tt>
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
     * is prepended.
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    public void addPrimop(String name, MethodType mtype) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   143
        List<MethodType> methods = _primops.get(name);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
        if (methods == null) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   145
            _primops.put(name, methods = new ArrayList<>());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
        }
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   147
        methods.add(mtype);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     * Lookup a primitive operator or function in the symbol table by
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
     * prepending the prefix <tt>PrimopPrefix</tt>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
     */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   154
    public List<MethodType> lookupPrimop(String name) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   155
        return _primops.get(name);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
     * This is used for xsl:attribute elements that have a "namespace"
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
     * attribute that is currently not defined using xmlns:
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
    private int _nsCounter = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
    public String generateNamespacePrefix() {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   165
        return("ns"+(_nsCounter++));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
     * Use a namespace prefix to lookup a namespace URI
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    private SyntaxTreeNode _current = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
    public void setCurrentNode(SyntaxTreeNode node) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
        _current = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
    public String lookupNamespace(String prefix) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
        if (_current == null) return(Constants.EMPTYSTRING);
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
        return(_current.lookupNamespace(prefix));
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
     * Adds an alias for a namespace prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
    public void addPrefixAlias(String prefix, String alias) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   186
        if (_aliases == null) _aliases = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
        _aliases.put(prefix,alias);
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
     * Retrieves any alias for a given namespace prefix
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    public String lookupPrefixAlias(String prefix) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
        if (_aliases == null) return null;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   195
        return _aliases.get(prefix);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
     * Register a namespace URI so that it will not be declared in the output
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
     * unless it is actually referenced in the output.
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
    public void excludeURI(String uri) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
        // The null-namespace cannot be excluded
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
        if (uri == null) return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   206
        // Create a new map of exlcuded URIs if none exists
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   207
        if (_excludedURI == null) _excludedURI = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
        // Register the namespace URI
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   210
        Integer refcnt = _excludedURI.get(uri);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
        if (refcnt == null)
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   212
            refcnt = 1;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
        else
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   214
            refcnt = refcnt + 1;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
        _excludedURI.put(uri,refcnt);
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
     * Exclude a series of namespaces given by a list of whitespace
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
     * separated namespace prefixes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    public void excludeNamespaces(String prefixes) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
        if (prefixes != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
            StringTokenizer tokens = new StringTokenizer(prefixes);
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
            while (tokens.hasMoreTokens()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
                final String prefix = tokens.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
                final String uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
                if (prefix.equals("#default"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
                    uri = lookupNamespace(Constants.EMPTYSTRING);
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
                    uri = lookupNamespace(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
                if (uri != null) excludeURI(uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
     * Check if a namespace should not be declared in the output (unless used)
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
    public boolean isExcludedNamespace(String uri) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
        if (uri != null && _excludedURI != null) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   242
            final Integer refcnt = _excludedURI.get(uri);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   243
            return (refcnt != null && refcnt > 0);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
     * Turn of namespace declaration exclusion
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
    public void unExcludeNamespaces(String prefixes) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        if (_excludedURI == null) return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        if (prefixes != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
            StringTokenizer tokens = new StringTokenizer(prefixes);
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
            while (tokens.hasMoreTokens()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                final String prefix = tokens.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
                final String uri;
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
                if (prefix.equals("#default"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
                    uri = lookupNamespace(Constants.EMPTYSTRING);
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
                    uri = lookupNamespace(prefix);
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   262
                Integer refcnt = _excludedURI.get(uri);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
                if (refcnt != null)
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   264
                    _excludedURI.put(uri, refcnt - 1);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
    }
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   268
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   269
     * Exclusion of namespaces by a stylesheet does not extend to any stylesheet
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   270
     * imported or included by the stylesheet.  Upon entering the context of a
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   271
     * new stylesheet, a call to this method is needed to clear the current set
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   272
     * of excluded namespaces temporarily.  Every call to this method requires
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   273
     * a corresponding call to {@link #popExcludedNamespacesContext()}.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   274
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   275
    public void pushExcludedNamespacesContext() {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   276
        if (_excludedURIStack == null) {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   277
            _excludedURIStack = new Stack<>();
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   278
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   279
        _excludedURIStack.push(_excludedURI);
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   280
        _excludedURI = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   281
    }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   282
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   283
    /**
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   284
     * Exclusion of namespaces by a stylesheet does not extend to any stylesheet
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   285
     * imported or included by the stylesheet.  Upon exiting the context of a
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   286
     * stylesheet, a call to this method is needed to restore the set of
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   287
     * excluded namespaces that was in effect prior to entering the context of
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   288
     * the current stylesheet.
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   289
     */
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   290
    public void popExcludedNamespacesContext() {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   291
        _excludedURI = _excludedURIStack.pop();
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   292
        if (_excludedURIStack.isEmpty()) {
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   293
            _excludedURIStack = null;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   294
        }
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   295
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
}