2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 * $Id: ProcessorNamespaceAlias.java 468640 2006-10-28 06:53:53Z minchau $
21 package org.apache.xalan.processor;
23 import org.apache.xalan.res.XSLTErrorResources;
24 import org.apache.xalan.templates.NamespaceAlias;
25 import org.xml.sax.Attributes;
28 * TransformerFactory for xsl:namespace-alias markup.
29 * A stylesheet can use the xsl:namespace-alias element to
30 * declare that one namespace URI is an alias for another namespace URI.
32 * <!ELEMENT xsl:namespace-alias EMPTY>
33 * <!ATTLIST xsl:namespace-alias
34 * stylesheet-prefix CDATA #REQUIRED
35 * result-prefix CDATA #REQUIRED
38 * @see <a href="http://www.w3.org/TR/xslt#dtd">XSLT DTD</a>
39 * @see <a href="http://www.w3.org/TR/xslt#literal-result-element">literal-result-element in XSLT Specification</a>
41 class ProcessorNamespaceAlias extends XSLTElementProcessor
43 static final long serialVersionUID = -6309867839007018964L;
46 * Receive notification of the start of an xsl:namespace-alias element.
48 * @param handler The calling StylesheetHandler/TemplatesBuilder.
49 * @param uri The Namespace URI, or the empty string if the
50 * element has no Namespace URI or if Namespace
51 * processing is not being performed.
52 * @param localName The local name (without prefix), or the
53 * empty string if Namespace processing is not being
55 * @param rawName The raw XML 1.0 name (with prefix), or the
56 * empty string if raw names are not available.
57 * @param attributes The attributes attached to the element. If
58 * there are no attributes, it shall be an empty
61 public void startElement(
62 StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes)
63 throws org.xml.sax.SAXException
65 final String resultNS;
66 NamespaceAlias na = new NamespaceAlias(handler.nextUid());
68 setPropertiesFromAttributes(handler, rawName, attributes, na);
69 String prefix = na.getStylesheetPrefix();
70 if(prefix.equals("#default"))
73 na.setStylesheetPrefix(prefix);
75 String stylesheetNS = handler.getNamespaceForPrefix(prefix);
76 na.setStylesheetNamespace(stylesheetNS);
77 prefix = na.getResultPrefix();
78 if(prefix.equals("#default"))
81 na.setResultPrefix(prefix);
82 resultNS = handler.getNamespaceForPrefix(prefix);
84 handler.error(XSLTErrorResources.ER_INVALID_NAMESPACE_URI_VALUE_FOR_RESULT_PREFIX_FOR_DEFAULT, null, null);
88 resultNS = handler.getNamespaceForPrefix(prefix);
90 handler.error(XSLTErrorResources.ER_INVALID_NAMESPACE_URI_VALUE_FOR_RESULT_PREFIX, new Object[] {prefix}, null);
93 na.setResultNamespace(resultNS);
94 handler.getStylesheet().setNamespaceAlias(na);
95 handler.getStylesheet().appendChild(na);