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.components.language.markup.xsp;
18:
19: import org.apache.cocoon.components.language.markup.CocoonMarkupLanguage;
20: import org.apache.cocoon.components.language.markup.LogicsheetFilter;
21: import org.apache.cocoon.components.language.programming.ProgrammingLanguage;
22: import org.apache.cocoon.xml.AbstractXMLPipe;
23:
24: /**
25: * This class implements <code>MarkupLanguage</code> for Cocoon's
26: * <a href="http://cocoon.apache.org/userdocs/xsp/">XSP</a>.
27: *
28: * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
29: * @author <a href="mailto:ssahuc@apache.org">Sebastien Sahuc</a>
30: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
31: * @version $Id: XSPMarkupLanguage.java 433543 2006-08-22 06:22:54Z crossley $
32: */
33: public class XSPMarkupLanguage extends CocoonMarkupLanguage {
34:
35: /**
36: * Returns the root element for a valid XSP page: page element!
37: */
38: public String getRootElement() {
39: return "page";
40: }
41:
42: /**
43: * Return the filter to preprocess logicsheets expanding {#expr} to
44: * xsp:attribute and xsp:expr elements.
45: */
46: protected LogicsheetFilter getLogicsheetFilter() {
47: return new XSPExpressionFilter(this );
48: }
49:
50: /**
51: * Prepare the input source for logicsheet processing and code generation
52: * with a preprocess filter.
53: * The return <code>XMLFilter</code> object is the first filter on the
54: * transformer chain.
55: *
56: * @param filename The source filename
57: * @param language The target programming language
58: * @return The preprocess filter
59: *
60: * @see XSPMarkupLanguage.PreProcessFilter
61: */
62: protected AbstractXMLPipe getPreprocessFilter(String filename,
63: AbstractXMLPipe filter, ProgrammingLanguage language) {
64: PreProcessFilter prefilter = new PreProcessFilter(filter,
65: filename, language, this );
66: prefilter.enableLogging(getLogger());
67: return prefilter;
68: }
69:
70: //
71: // Inner classes
72: //
73:
74: /**
75: * <code>{@link CocoonMarkupLanguage.PreProcessFilter PreProcessFilter}</code> that replaces
76: * XSP expressions.
77: *
78: * @see org.xml.sax.ContentHandler
79: */
80: protected class PreProcessFilter extends
81: CocoonMarkupLanguage.PreProcessFilter {
82: public PreProcessFilter(AbstractXMLPipe filter,
83: String filename, ProgrammingLanguage language,
84: XSPMarkupLanguage markup) {
85: super (new XSPExpressionFilter.XMLPipeAdapter(
86: new XSPExpressionFilter(markup), filter), filename,
87: language);
88: }
89: }
90: }
|