001: package net.sf.saxon.style;
002:
003: import net.sf.saxon.expr.Expression;
004: import net.sf.saxon.instruct.Executable;
005: import net.sf.saxon.om.AttributeCollection;
006: import net.sf.saxon.om.NamePool;
007: import net.sf.saxon.om.NamespaceException;
008: import net.sf.saxon.trans.XPathException;
009:
010: /**
011: * An xsl:namespace-alias element in the stylesheet. <br>
012: */
013:
014: public class XSLNamespaceAlias extends StyleElement {
015:
016: private short stylesheetURICode;
017: private int resultNamespaceCode;
018:
019: public void prepareAttributes() throws XPathException {
020:
021: String stylesheetPrefix = null;
022: String resultPrefix = null;
023:
024: AttributeCollection atts = getAttributeList();
025:
026: for (int a = 0; a < atts.getLength(); a++) {
027: int nc = atts.getNameCode(a);
028: String f = getNamePool().getClarkName(nc);
029: if (f == StandardNames.STYLESHEET_PREFIX) {
030: stylesheetPrefix = atts.getValue(a).trim();
031: } else if (f == StandardNames.RESULT_PREFIX) {
032: resultPrefix = atts.getValue(a).trim();
033: } else {
034: checkUnknownAttribute(nc);
035: }
036: }
037: if (stylesheetPrefix == null) {
038: reportAbsence("stylesheet-prefix");
039: return;
040: }
041: if (stylesheetPrefix.equals("#default")) {
042: stylesheetPrefix = "";
043: }
044: if (resultPrefix == null) {
045: reportAbsence("result-prefix");
046: return;
047: }
048: if (resultPrefix.equals("#default")) {
049: resultPrefix = "";
050: }
051: try {
052: String ssURI = getURIForPrefix(stylesheetPrefix, true);
053: if (ssURI == null) {
054: compileError("stylesheet-prefix " + stylesheetPrefix
055: + " has not been declared", "XTSE0812");
056: // TODO: error code provisional. See W3C Bugzilla 1879
057: // recovery action
058: stylesheetURICode = 0;
059: resultNamespaceCode = 0;
060: return;
061: }
062: stylesheetURICode = getURICodeForPrefix(stylesheetPrefix);
063: NamePool pool = getNamePool();
064: String resultURI = getURIForPrefix(resultPrefix, true);
065: if (resultURI == null) {
066: compileError("result-prefix " + resultPrefix
067: + " has not been declared", "XTSE0812");
068: // TODO: error code provisional. See W3C Bugzilla 1879
069: // recovery action
070: stylesheetURICode = 0;
071: resultNamespaceCode = 0;
072: return;
073: }
074: resultNamespaceCode = pool.getNamespaceCode(resultPrefix,
075: resultURI);
076: } catch (NamespaceException err) {
077: compileError(err.getMessage());
078: }
079: }
080:
081: public void validate() throws XPathException {
082: checkTopLevel(null);
083: }
084:
085: public Expression compile(Executable exec) throws XPathException {
086: return null;
087: }
088:
089: public short getStylesheetURICode() {
090: return stylesheetURICode;
091: }
092:
093: public int getResultNamespaceCode() {
094: return resultNamespaceCode;
095: }
096:
097: }
098:
099: //
100: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
101: // you may not use this file except in compliance with the License. You may obtain a copy of the
102: // License at http://www.mozilla.org/MPL/
103: //
104: // Software distributed under the License is distributed on an "AS IS" basis,
105: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
106: // See the License for the specific language governing rights and limitations under the License.
107: //
108: // The Original Code is: all this file.
109: //
110: // The Initial Developer of the Original Code is Michael H. Kay.
111: //
112: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
113: //
114: // Contributor(s): none.
115: //
|