jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/XSLTCSource.java
author joehw
Tue, 17 Apr 2012 11:17:59 -0700
changeset 12458 d601e4bba306
parent 12457 c348e06f0e82
permissions -rw-r--r--
7160380: Sync JDK8 with JAXP 1.4.5 Summary: bring JDK8 up to date to what we have in 7u4 Reviewed-by: lancea, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 * Copyright 2001-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * You may obtain a copy of the License at
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: XSLTCSource.java,v 1.2.4.1 2005/09/06 12:43:28 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.trax;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import javax.xml.transform.Source;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import javax.xml.transform.stream.StreamSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xalan.internal.xsltc.DOM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xalan.internal.xsltc.StripFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xalan.internal.xsltc.dom.DOMWSFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
public final class XSLTCSource implements Source {
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
    private String     _systemId = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
    private Source     _source   = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
    private ThreadLocal _dom     = new ThreadLocal();
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
     * Create a new XSLTC-specific source from a system ID
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
    public XSLTCSource(String systemId)
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
        _systemId = systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
     * Create a new XSLTC-specific source from a JAXP Source
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
    public XSLTCSource(Source source)
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
        _source = source;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
     * Implements javax.xml.transform.Source.setSystemId()
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
     * Set the system identifier for this Source.
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
     * This Source can get its input either directly from a file (in this case
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
     * it will instanciate and use a JAXP parser) or it can receive it through
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
     * ContentHandler/LexicalHandler interfaces.
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
     * @param systemId The system Id for this Source
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    public void setSystemId(String systemId) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
        _systemId = systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
        if (_source != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
            _source.setSystemId(systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
     * Implements javax.xml.transform.Source.getSystemId()
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
     * Get the system identifier that was set with setSystemId.
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
     * @return The system identifier that was set with setSystemId,
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
     *         or null if setSystemId was not called.
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    public String getSystemId() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
        if (_source != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
            return _source.getSystemId();
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
            return(_systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
     * Internal interface which returns a DOM for a given DTMManager and translet.
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
    protected DOM getDOM(XSLTCDTMManager dtmManager, AbstractTranslet translet)
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
        SAXImpl idom = (SAXImpl)_dom.get();
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
        if (idom != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
            if (dtmManager != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
                idom.migrateTo(dtmManager);
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
            Source source = _source;
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
            if (source == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
                if (_systemId != null && _systemId.length() > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
                    source = new StreamSource(_systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
                    ErrorMsg err = new ErrorMsg(ErrorMsg.XSLTC_SOURCE_ERR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
                    throw new SAXException(err.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
            DOMWSFilter wsfilter = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
            if (translet != null && translet instanceof StripFilter) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
                wsfilter = new DOMWSFilter(translet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
            boolean hasIdCall = (translet != null) ? translet.hasIdCall() : false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
            if (dtmManager == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
                dtmManager = XSLTCDTMManager.newInstance();
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
            idom = (SAXImpl)dtmManager.getDTM(source, true, wsfilter, false, false, hasIdCall);
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
            String systemId = getSystemId();
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
            if (systemId != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
                idom.setDocumentURI(systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
            _dom.set(idom);
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
        return idom;
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
}