01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.template.script.event;
18:
19: import java.util.Iterator;
20:
21: import org.apache.cocoon.components.expression.ExpressionContext;
22: import org.apache.cocoon.template.environment.ErrorHolder;
23: import org.apache.cocoon.template.environment.ExecutionContext;
24: import org.apache.cocoon.template.environment.ParsingContext;
25: import org.apache.cocoon.template.expression.JXTExpression;
26: import org.apache.cocoon.template.expression.Literal;
27: import org.apache.cocoon.template.expression.Subst;
28: import org.apache.cocoon.template.instruction.MacroContext;
29: import org.apache.cocoon.template.script.Invoker;
30: import org.apache.cocoon.xml.XMLConsumer;
31: import org.xml.sax.Locator;
32: import org.xml.sax.SAXException;
33: import org.xml.sax.SAXParseException;
34:
35: /**
36: * @version SVN $Id: Characters.java 449189 2006-09-23 06:52:29Z crossley $
37: */
38: public class Characters extends TextEvent {
39: public Characters(ParsingContext parsingContext, Locator location,
40: char[] chars, int start, int length) throws SAXException {
41: super (parsingContext, location, chars, start, length);
42: }
43:
44: public Event execute(XMLConsumer consumer,
45: ExpressionContext expressionContext,
46: ExecutionContext executionContext,
47: MacroContext macroContext, Event startEvent, Event endEvent)
48: throws SAXException {
49: Iterator iter = getSubstitutions().iterator();
50: while (iter.hasNext()) {
51: Subst subst = (Subst) iter.next();
52: char[] chars;
53: if (subst instanceof Literal) {
54: chars = ((Literal) subst).getCharArray();
55: consumer.characters(chars, 0, chars.length);
56: } else {
57: JXTExpression expr = (JXTExpression) subst;
58: try {
59: Object val = expr.getNode(expressionContext);
60: Invoker.executeNode(consumer, val);
61: } catch (Exception e) {
62: throw new SAXParseException(e.getMessage(),
63: getLocation(), e);
64: } catch (Error err) {
65: throw new SAXParseException(err.getMessage(),
66: getLocation(), new ErrorHolder(err));
67: }
68: }
69: }
70: return getNext();
71: }
72: }
|