jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerHandlerImpl.java
author joehw
Tue, 17 Apr 2012 11:17:59 -0700
changeset 12458 d601e4bba306
parent 12457 c348e06f0e82
child 18352 a1e183c996d6
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
 * Copyright 2001-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: TransformerHandlerImpl.java,v 1.2.4.1 2005/09/15 06:25:12 pvedula Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
package com.sun.org.apache.xalan.internal.xsltc.trax;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import javax.xml.transform.Result;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import javax.xml.transform.Transformer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import javax.xml.transform.TransformerException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import javax.xml.transform.sax.TransformerHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import javax.xml.transform.dom.DOMResult;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xalan.internal.xsltc.StripFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xalan.internal.xsltc.dom.DOMWSFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xalan.internal.xsltc.dom.XSLTCDTMManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import org.xml.sax.Attributes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import org.xml.sax.ContentHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import org.xml.sax.DTDHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import org.xml.sax.Locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import org.xml.sax.ext.DeclHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import org.xml.sax.ext.LexicalHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
import org.xml.sax.helpers.DefaultHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * Implementation of a JAXP1.1 TransformerHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * @author Morten Jorgensen
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
public class TransformerHandlerImpl implements TransformerHandler, DeclHandler {
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    private TransformerImpl  _transformer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
    private AbstractTranslet _translet = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
    private String           _systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
    private SAXImpl          _dom = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
    private ContentHandler   _handler = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    private LexicalHandler   _lexHandler = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    private DTDHandler       _dtdHandler = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    private DeclHandler      _declHandler = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    private Result           _result = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    private Locator          _locator = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    private boolean          _done = false; // Set in endDocument()
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
     * A flag indicating whether this transformer handler implements the
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
     * identity transform.
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    private boolean _isIdentity = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
     * Cosntructor - pass in reference to a TransformerImpl object
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    public TransformerHandlerImpl(TransformerImpl transformer) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
        // Save the reference to the transformer
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
        _transformer = transformer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
        if (transformer.isIdentity()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
            // Set initial handler to the empty handler
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
            _handler = new DefaultHandler();
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
            _isIdentity = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
        else {
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
            // Get a reference to the translet wrapped inside the transformer
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
            _translet = _transformer.getTranslet();
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
     * Implements javax.xml.transform.sax.TransformerHandler.getSystemId()
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
     * Get the base ID (URI or system ID) from where relative URLs will be
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
     * resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
     * @return The systemID that was set with setSystemId(String id)
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    public String getSystemId() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
        return _systemId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
     * Implements javax.xml.transform.sax.TransformerHandler.setSystemId()
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
     * Get the base ID (URI or system ID) from where relative URLs will be
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
     * resolved.
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
     * @param id Base URI for this stylesheet
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    public void setSystemId(String id) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
        _systemId = id;
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
     * Implements javax.xml.transform.sax.TransformerHandler.getTransformer()
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
     * Get the Transformer associated with this handler, which is needed in
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
     * order to set parameters and output properties.
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
     * @return The Transformer object
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    public Transformer getTransformer() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        return _transformer;
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
     * Implements javax.xml.transform.sax.TransformerHandler.setResult()
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
     * Enables the user of the TransformerHandler to set the to set the Result
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
     * for the transformation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
     * @param result A Result instance, should not be null
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
     * @throws IllegalArgumentException if result is invalid for some reason
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    public void setResult(Result result) throws IllegalArgumentException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
        _result = result;
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    if (null == result) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
       ErrorMsg err = new ErrorMsg(ErrorMsg.ER_RESULT_NULL);
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
       throw new IllegalArgumentException(err.toString()); //"result should not be null");
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
        if (_isIdentity) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
                // Connect this object with output system directly
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
                SerializationHandler outputHandler =
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
                    _transformer.getOutputHandler(result);
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
                _transformer.transferOutputProperties(outputHandler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
                _handler = outputHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
                _lexHandler = outputHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
            catch (TransformerException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
                _result = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
        else if (_done) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
            // Run the transformation now, if not already done
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
                _transformer.setDOM(_dom);
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
                _transformer.transform(null, _result);
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
            catch (TransformerException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
                // What the hell are we supposed to do with this???
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
                throw new IllegalArgumentException(e.getMessage());
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     * Implements org.xml.sax.ContentHandler.characters()
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     * Receive notification of character data.
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
    public void characters(char[] ch, int start, int length)
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
        _handler.characters(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
     * Implements org.xml.sax.ContentHandler.startDocument()
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
     * Receive notification of the beginning of a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
    public void startDocument() throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
        // Make sure setResult() was called before the first SAX event
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
        if (_result == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
            ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_SET_RESULT_ERR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
            throw new SAXException(err.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
        if (!_isIdentity) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
            boolean hasIdCall = (_translet != null) ? _translet.hasIdCall() : false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
            XSLTCDTMManager dtmManager = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
            // Create an internal DOM (not W3C) and get SAX2 input handler
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
                dtmManager =
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
                    (XSLTCDTMManager)_transformer.getTransformerFactory()
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
                                                 .getDTMManagerClass()
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
                                                 .newInstance();
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
            } catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
                throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
            DTMWSFilter wsFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
            if (_translet != null && _translet instanceof StripFilter) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
                wsFilter = new DOMWSFilter(_translet);
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
            } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
                wsFilter = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
            // Construct the DTM using the SAX events that come through
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
            _dom = (SAXImpl)dtmManager.getDTM(null, false, wsFilter, true,
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
                                              false, hasIdCall);
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
            _handler = _dom.getBuilder();
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
            _lexHandler = (LexicalHandler) _handler;
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
            _dtdHandler = (DTDHandler) _handler;
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
            _declHandler = (DeclHandler) _handler;
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
            // Set document URI
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
            _dom.setDocumentURI(_systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
            if (_locator != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
                _handler.setDocumentLocator(_locator);
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
        // Proxy call
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        _handler.startDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
     * Implements org.xml.sax.ContentHandler.endDocument()
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
     * Receive notification of the end of a document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
    public void endDocument() throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        // Signal to the DOMBuilder that the document is complete
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
        _handler.endDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
        if (!_isIdentity) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
            // Run the transformation now if we have a reference to a Result object
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
            if (_result != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
                try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
                    _transformer.setDOM(_dom);
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
                    _transformer.transform(null, _result);
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
                catch (TransformerException e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
                    throw new SAXException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
            // Signal that the internal DOM is built (see 'setResult()').
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
            _done = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
            // Set this DOM as the transformer's DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
            _transformer.setDOM(_dom);
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
        if (_isIdentity && _result instanceof DOMResult) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
            ((DOMResult)_result).setNode(_transformer.getTransletOutputHandlerFactory().getNode());
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
     * Implements org.xml.sax.ContentHandler.startElement()
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
     * Receive notification of the beginning of an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
    public void startElement(String uri, String localName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
                             String qname, Attributes attributes)
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
        _handler.startElement(uri, localName, qname, attributes);
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
     * Implements org.xml.sax.ContentHandler.endElement()
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
     * Receive notification of the end of an element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    public void endElement(String namespaceURI, String localName, String qname)
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        _handler.endElement(namespaceURI, localName, qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
     * Implements org.xml.sax.ContentHandler.processingInstruction()
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
     * Receive notification of a processing instruction.
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
    public void processingInstruction(String target, String data)
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
        _handler.processingInstruction(target, data);
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
     * Implements org.xml.sax.ext.LexicalHandler.startCDATA()
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
    public void startCDATA() throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
        if (_lexHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
            _lexHandler.startCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
     * Implements org.xml.sax.ext.LexicalHandler.endCDATA()
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
    public void endCDATA() throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        if (_lexHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
            _lexHandler.endCDATA();
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
     * Implements org.xml.sax.ext.LexicalHandler.comment()
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
     * Receieve notification of a comment
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
    public void comment(char[] ch, int start, int length)
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
        if (_lexHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
            _lexHandler.comment(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
     * Implements org.xml.sax.ContentHandler.ignorableWhitespace()
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
     * Receive notification of ignorable whitespace in element
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
     * content. Similar to characters(char[], int, int).
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
    public void ignorableWhitespace(char[] ch, int start, int length)
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
        _handler.ignorableWhitespace(ch, start, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
     * Implements org.xml.sax.ContentHandler.setDocumentLocator()
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
     * Receive an object for locating the origin of SAX document events.
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
    public void setDocumentLocator(Locator locator) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
        _locator = locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
        if (_handler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
            _handler.setDocumentLocator(locator);
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
     * Implements org.xml.sax.ContentHandler.skippedEntity()
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
     * Receive notification of a skipped entity.
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
    public void skippedEntity(String name) throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
        _handler.skippedEntity(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
     * Implements org.xml.sax.ContentHandler.startPrefixMapping()
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
     * Begin the scope of a prefix-URI Namespace mapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
    public void startPrefixMapping(String prefix, String uri)
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
        throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
        _handler.startPrefixMapping(prefix, uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
     * Implements org.xml.sax.ContentHandler.endPrefixMapping()
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
     * End the scope of a prefix-URI Namespace mapping.
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
    public void endPrefixMapping(String prefix) throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
        _handler.endPrefixMapping(prefix);
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
     * Implements org.xml.sax.ext.LexicalHandler.startDTD()
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
    public void startDTD(String name, String publicId, String systemId)
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
        if (_lexHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
            _lexHandler.startDTD(name, publicId, systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
     * Implements org.xml.sax.ext.LexicalHandler.endDTD()
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
    public void endDTD() throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
        if (_lexHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
            _lexHandler.endDTD();
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
     * Implements org.xml.sax.ext.LexicalHandler.startEntity()
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
    public void startEntity(String name) throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
        if (_lexHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
            _lexHandler.startEntity(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
     * Implements org.xml.sax.ext.LexicalHandler.endEntity()
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
    public void endEntity(String name) throws SAXException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
        if (_lexHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
            _lexHandler.endEntity(name);
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
     * Implements org.xml.sax.DTDHandler.unparsedEntityDecl()
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
    public void unparsedEntityDecl(String name, String publicId,
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
        String systemId, String notationName) throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
        if (_dtdHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
            _dtdHandler.unparsedEntityDecl(name, publicId, systemId,
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
                                           notationName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
     * Implements org.xml.sax.DTDHandler.notationDecl()
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
    public void notationDecl(String name, String publicId, String systemId)
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
        if (_dtdHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
            _dtdHandler.notationDecl(name, publicId, systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
     * Implements org.xml.sax.ext.DeclHandler.attributeDecl()
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
    public void attributeDecl(String eName, String aName, String type,
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
        String valueDefault, String value) throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
        if (_declHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
            _declHandler.attributeDecl(eName, aName, type, valueDefault, value);
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
     * Implements org.xml.sax.ext.DeclHandler.elementDecl()
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
    public void elementDecl(String name, String model)
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
        if (_declHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
            _declHandler.elementDecl(name, model);
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
     * Implements org.xml.sax.ext.DeclHandler.externalEntityDecl()
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
    public void externalEntityDecl(String name, String publicId, String systemId)
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
        if (_declHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
            _declHandler.externalEntityDecl(name, publicId, systemId);
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
     * Implements org.xml.sax.ext.DeclHandler.externalEntityDecl()
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
    public void internalEntityDecl(String name, String value)
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
        throws SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
        if (_declHandler != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
            _declHandler.internalEntityDecl(name, value);
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
   /** Implementation of the reset() method
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
    *
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
    */
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
   public void reset() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
       _systemId = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
       _dom = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
       _handler = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
       _lexHandler = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
       _dtdHandler = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
       _declHandler = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
       _result = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
       _locator = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
   }
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
}