001: package net.sf.saxon.style;
002:
003: import net.sf.saxon.expr.Expression;
004: import net.sf.saxon.expr.ExpressionTool;
005: import net.sf.saxon.expr.ComputedExpression;
006: import net.sf.saxon.instruct.Block;
007: import net.sf.saxon.instruct.Executable;
008: import net.sf.saxon.instruct.Message;
009: import net.sf.saxon.om.AttributeCollection;
010: import net.sf.saxon.om.Axis;
011: import net.sf.saxon.trans.XPathException;
012: import net.sf.saxon.value.StringValue;
013:
014: /**
015: * An xsl:message element in the stylesheet. <br>
016: */
017:
018: public final class XSLMessage extends StyleElement {
019:
020: private Expression terminate = null;
021: private Expression select = null;
022:
023: /**
024: * Determine whether this node is an instruction.
025: * @return true - it is an instruction
026: */
027:
028: public boolean isInstruction() {
029: return true;
030: }
031:
032: /**
033: * Determine whether this type of element is allowed to contain a template-body
034: * @return true: yes, it may contain a template-body
035: */
036:
037: public boolean mayContainSequenceConstructor() {
038: return true;
039: }
040:
041: public void prepareAttributes() throws XPathException {
042:
043: String terminateAtt = null;
044: String selectAtt = null;
045: AttributeCollection atts = getAttributeList();
046:
047: for (int a = 0; a < atts.getLength(); a++) {
048: int nc = atts.getNameCode(a);
049: String f = getNamePool().getClarkName(nc);
050: if (f == StandardNames.TERMINATE) {
051: terminateAtt = atts.getValue(a).trim();
052: } else if (f == StandardNames.SELECT) {
053: selectAtt = atts.getValue(a);
054:
055: } else {
056: checkUnknownAttribute(nc);
057: }
058: }
059: if (selectAtt != null) {
060: select = makeExpression(selectAtt);
061: }
062:
063: if (terminateAtt == null) {
064: terminateAtt = "no";
065: }
066:
067: terminate = makeAttributeValueTemplate(terminateAtt);
068: if (terminate instanceof StringValue) {
069: String t = ((StringValue) terminate).getStringValue();
070: if (!(t.equals("yes") || t.equals("no"))) {
071: compileError("terminate must be 'yes' or 'no'",
072: "XTSE0020");
073: }
074: }
075: }
076:
077: public void validate() throws XPathException {
078: if (!(getParent() instanceof XSLFunction)) {
079: checkWithinTemplate();
080: }
081: select = typeCheck("select", select);
082: terminate = typeCheck("terminate", terminate);
083: }
084:
085: public Expression compile(Executable exec) throws XPathException {
086: Expression b = compileSequenceConstructor(exec,
087: iterateAxis(Axis.CHILD), true);
088: if (b != null) {
089: if (select == null) {
090: select = b;
091: } else {
092: select = Block.makeBlock(select, b);
093: if (select instanceof ComputedExpression) {
094: ((ComputedExpression) select)
095: .setLocationId(allocateLocationId(
096: getSystemId(), getLineNumber()));
097: }
098: }
099: }
100: if (select == null) {
101: select = new StringValue("xsl:message (no content)");
102: }
103: Message inst = new Message(select, terminate);
104: ExpressionTool.makeParentReferences(inst);
105: return inst;
106: }
107:
108: }
109: //
110: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
111: // you may not use this file except in compliance with the License. You may obtain a copy of the
112: // License at http://www.mozilla.org/MPL/
113: //
114: // Software distributed under the License is distributed on an "AS IS" basis,
115: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
116: // See the License for the specific language governing rights and limitations under the License.
117: //
118: // The Original Code is: all this file.
119: //
120: // The Initial Developer of the Original Code is Michael H. Kay.
121: //
122: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
123: //
124: // Contributor(s): none.
125: //
|