01: /*
02: * Copyright (C) 2004 TiongHiang Lee
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Email: thlee@onemindsoft.org
19: */
20:
21: package org.onemind.jxp;
22:
23: import java.io.Writer;
24: import java.util.*;
25:
26: /**
27: * A jxp context encapsulate the pagesource and default environment.
28: * It creates the JxpProcessingContext to the JxpProcessor.
29: * @author TiongHiang Lee (thlee@onemindsoft.org)
30: */
31: public class JxpContext {
32:
33: /** the page source **/
34: private final JxpPageSource _source;
35:
36: /** the default environment **/
37: private final Map _defaultEnv;
38:
39: /**
40: * Constructor
41: * @param source the page source
42: */
43: public JxpContext(JxpPageSource source) {
44: this (source, Collections.EMPTY_MAP);
45: }
46:
47: /**
48: * Constructor
49: * @param source the source
50: * @param env the environment
51: */
52: public JxpContext(JxpPageSource source, Map defaultEnv) {
53: _source = source;
54: _defaultEnv = defaultEnv;
55: }
56:
57: /**
58: * Get the page source
59: * @return the page source
60: */
61: public JxpPageSource getPageSource() {
62: return _source;
63: }
64:
65: /**
66: * Get the environment
67: * @return the environment
68: */
69: public Map getEnvironment() {
70: return _defaultEnv;
71: }
72:
73: /**
74: * Create processing context
75: * @param page the page
76: */
77: public JxpProcessingContext createProcessingContext(Map pageEnv,
78: Writer writer) throws Exception {
79: HashMap env = new HashMap(_defaultEnv);
80: env.putAll(pageEnv);
81: env.put("writer", writer);
82: JxpProcessingContext context = new JxpProcessingContext(writer,
83: env);
84: return context;
85: }
86: }
|