KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > forrest > locationmap > lm > LocationNode


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation or its licensors,
3  * as applicable.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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.forrest.locationmap.lm;
18
19 import java.util.Map JavaDoc;
20
21 import org.apache.avalon.framework.configuration.Configuration;
22 import org.apache.avalon.framework.configuration.ConfigurationException;
23 import org.apache.avalon.framework.service.ServiceManager;
24 import org.apache.cocoon.components.treeprocessor.InvokeContext;
25 import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
26 import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory;
27 import org.apache.cocoon.sitemap.PatternException;
28
29 /**
30  * locationmap leaf statement identifying a location.
31  *
32  * <p>
33  * The <code>&lt;location&gt;</code> element has one
34  * required attribute <code>src</code> that contains the
35  * location string.
36  * </p>
37  */

38 public class LocationNode extends AbstractNode {
39
40     private final LocatorNode m_ln;
41
42     // the resolvable location source
43
private VariableResolver m_src;
44
45     public LocationNode(final LocatorNode ln, final ServiceManager manager) {
46         super(manager);
47         m_ln = ln;
48     }
49
50     public void build(final Configuration configuration) throws ConfigurationException {
51         try {
52             m_src = VariableResolverFactory.getResolver(
53                     configuration.getAttribute("src"), super.m_manager);
54         } catch (PatternException e) {
55             final String JavaDoc message = "Illegal pattern syntax at for location attribute 'src'" +
56                     " at " + configuration.getLocation();
57             throw new ConfigurationException(message,e);
58         }
59     }
60     
61     /**
62      * Resolve the location string against the InvokeContext.
63      */

64     public String JavaDoc locate(Map JavaDoc om, InvokeContext context) throws Exception JavaDoc {
65         return m_src.resolve(context, om);
66     }
67
68 }
69
Popular Tags