src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/StylesheetPIHandler.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) 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
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
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
 *
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
6
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
 */
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    21
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xml.internal.utils;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    24
import java.util.ArrayList;
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    25
import java.util.List;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import java.util.StringTokenizer;
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.TransformerException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import javax.xml.transform.URIResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import javax.xml.transform.sax.SAXSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import org.xml.sax.Attributes;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import org.xml.sax.InputSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import org.xml.sax.helpers.DefaultHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * Search for the xml-stylesheet processing instructions in an XML document.
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    37
 * @see <a href="http://www.w3.org/TR/xml-stylesheet/">
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    38
 * Associating Style Sheets with XML documents, Version 1.0</a>
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
public class StylesheetPIHandler extends DefaultHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
  /** The baseID of the document being processed.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
  String m_baseID;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
  /** The desired media criteria. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
  String m_media;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
  /** The desired title criteria.  */
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
  String m_title;
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
  /** The desired character set criteria.   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
  String m_charset;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
  /** A list of SAXSource objects that match the criteria.  */
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
    55
  List<Source> m_stylesheets = new ArrayList<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
  // Add code to use a URIResolver. Patch from Dmitri Ilyin.
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
   * The object that implements the URIResolver interface,
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
  URIResolver m_uriResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   * Get the object that will be used to resolve URIs in href
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
   * in xml-stylesheet processing instruction.
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
   * @param resolver An object that implements the URIResolver interface,
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
   * or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
  public void setURIResolver(URIResolver resolver)
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    m_uriResolver = resolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
   * Get the object that will be used to resolve URIs in href
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   * in xml-stylesheet processing instruction.
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
   * @return The URIResolver that was set with setURIResolver.
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
  public URIResolver getURIResolver()
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
    return m_uriResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
   * Construct a StylesheetPIHandler instance that will search
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
   * for xml-stylesheet PIs based on the given criteria.
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   * @param baseID The base ID of the XML document, needed to resolve
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   *               relative IDs.
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * @param media The desired media criteria.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   * @param title The desired title criteria.
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
   * @param charset The desired character set criteria.
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
  public StylesheetPIHandler(String baseID, String media, String title,
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
                             String charset)
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    m_baseID = baseID;
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
    m_media = media;
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    m_title = title;
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    m_charset = charset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * Return the last stylesheet found that match the constraints.
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   * @return Source object that references the last stylesheet reference
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
   *         that matches the constraints.
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
  public Source getAssociatedStylesheet()
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    int sz = m_stylesheets.size();
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    if (sz > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
    {
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   121
      Source source = m_stylesheets.get(sz-1);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
      return source;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
      return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
   * Handle the xml-stylesheet processing instruction.
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
   * @param target The processing instruction target.
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
   * @param data The processing instruction data, or null if
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
   *             none is supplied.
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
   * @throws org.xml.sax.SAXException Any SAX exception, possibly
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
   *            wrapping another exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
   * @see org.xml.sax.ContentHandler#processingInstruction
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   137
   * @see <a href="http://www.w3.org/TR/xml-stylesheet/">
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   138
   * Associating Style Sheets with XML documents, Version 1.0</a>
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
  public void processingInstruction(String target, String data)
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
          throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
    if (target.equals("xml-stylesheet"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
      String href = null;  // CDATA #REQUIRED
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
      String type = null;  // CDATA #REQUIRED
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
      String title = null;  // CDATA #IMPLIED
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
      String media = null;  // CDATA #IMPLIED
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
      String charset = null;  // CDATA #IMPLIED
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
      boolean alternate = false;  // (yes|no) "no"
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
      StringTokenizer tokenizer = new StringTokenizer(data, " \t=\n", true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
      boolean lookedAhead = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
      Source source = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
      String token = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
      while (tokenizer.hasMoreTokens())
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
        if (!lookedAhead)
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
          token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
          lookedAhead = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
        if (tokenizer.hasMoreTokens() &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
               (token.equals(" ") || token.equals("\t") || token.equals("=")))
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
          continue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
        String name = token;
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
        if (name.equals("type"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
          token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
          while (tokenizer.hasMoreTokens() &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
               (token.equals(" " ) || token.equals("\t") || token.equals("=")))
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
            token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
          type = token.substring(1, token.length() - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        else if (name.equals("href"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
          token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
          while (tokenizer.hasMoreTokens() &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
               (token.equals(" " ) || token.equals("\t") || token.equals("=")))
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
            token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
          href = token;
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
          if (tokenizer.hasMoreTokens())
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
            token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
            // If the href value has parameters to be passed to a
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
            // servlet(something like "foobar?id=12..."),
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
            // we want to make sure we get them added to
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
            // the href value. Without this check, we would move on
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
            // to try to process another attribute and that would be
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
            // wrong.
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
            // We need to set lookedAhead here to flag that we
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
            // already have the next token.
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
            while ( token.equals("=") && tokenizer.hasMoreTokens())
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
              href = href + token + tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
              if (tokenizer.hasMoreTokens())
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
                token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
                lookedAhead = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
              else
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
              {
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
          href = href.substring(1, href.length() - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
          try
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
            // Add code to use a URIResolver. Patch from Dmitri Ilyin.
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
            if (m_uriResolver != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
              source = m_uriResolver.resolve(href, m_baseID);
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
           else
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
            {
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
              href = SystemIDResolver.getAbsoluteURI(href, m_baseID);
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
              source = new SAXSource(new InputSource(href));
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
          catch(TransformerException te)
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
            throw new org.xml.sax.SAXException(te);
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
        else if (name.equals("title"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
          token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
          while (tokenizer.hasMoreTokens() &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
               (token.equals(" " ) || token.equals("\t") || token.equals("=")))
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
            token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
          title = token.substring(1, token.length() - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
        else if (name.equals("media"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
          token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
          while (tokenizer.hasMoreTokens() &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
               (token.equals(" " ) || token.equals("\t") || token.equals("=")))
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
            token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
          media = token.substring(1, token.length() - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
        else if (name.equals("charset"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
          token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
          while (tokenizer.hasMoreTokens() &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
              (token.equals(" " ) || token.equals("\t") || token.equals("=")))
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
            token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
          charset = token.substring(1, token.length() - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
        else if (name.equals("alternate"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
          token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
          while (tokenizer.hasMoreTokens() &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
               (token.equals(" " ) || token.equals("\t") || token.equals("=")))
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
            token = tokenizer.nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
          alternate = token.substring(1, token.length()
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
                                             - 1).equals("yes");
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
      if ((null != type)
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
          && (type.equals("text/xsl") || type.equals("text/xml") || type.equals("application/xml+xslt"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
          && (null != href))
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
        if (null != m_media)
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
          if (null != media)
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
            if (!media.equals(m_media))
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
              return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        if (null != m_charset)
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
          if (null != charset)
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
            if (!charset.equals(m_charset))
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
              return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
        if (null != m_title)
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
          if (null != title)
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
            if (!title.equals(m_title))
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
              return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
            return;
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
47359
e1a6c0168741 8181150: Fix lint warnings in JAXP repo: rawtypes and unchecked
joehw
parents: 47216
diff changeset
   301
        m_stylesheets.add(source);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
  }
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
   * The spec notes that "The xml-stylesheet processing instruction is allowed only in the prolog of an XML document.",
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
   * so, at least for right now, I'm going to go ahead an throw a TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
   * in order to stop the parse.
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
   * @param namespaceURI The Namespace URI, or an empty string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
   * @param localName The local name (without prefix), or empty string if not namespace processing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
   * @param qName The qualified name (with prefix).
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
   * @param atts  The specified or defaulted attributes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
   * @throws StopParseException since there can be no valid xml-stylesheet processing
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
   *                            instructions past the first element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
  public void startElement(
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
          String namespaceURI, String localName, String qName, Attributes atts)
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
            throws org.xml.sax.SAXException
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
    throw new StopParseException();
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
    * Added additional getter and setter methods for the Base Id
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
    * to fix bugzilla bug 24187
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
    *
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
    */
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
   public void setBaseId(String baseId) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
       m_baseID = baseId;
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
   }
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
   public String  getBaseId() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
       return m_baseID ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
   }
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
}