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.sitemap;
18:
19: import java.util.HashMap;
20:
21: import org.apache.avalon.framework.parameters.Parameters;
22: import org.apache.cocoon.util.location.Locatable;
23: import org.apache.cocoon.util.location.Location;
24:
25: /**
26: * Extension to the Avalon Parameters to give location information
27: *
28: * @version CVS $Id: SitemapParameters.java 433543 2006-08-22 06:22:54Z crossley $
29: */
30: public class SitemapParameters extends Parameters implements Locatable {
31:
32: private Location location = Location.UNKNOWN;
33:
34: public SitemapParameters(Location location) {
35: this .location = location;
36: }
37:
38: /*
39: * Get the location of the statement defining these parameters.
40: *
41: * @since 2.1.8
42: * @see org.apache.cocoon.util.location.Locatable#getLocation()
43: */
44: public Location getLocation() {
45: return this .location;
46: }
47:
48: /**
49: * Get the location of a <code>Parameters</code> object, returning
50: * {@link Location#UNKNOWN} if no location could be found.
51: *
52: * @param param
53: * @return the location
54: * @since 2.1.8
55: */
56: public static Location getLocation(Parameters param) {
57: Location loc = null;
58: if (param instanceof Locatable) {
59: loc = ((Locatable) param).getLocation();
60: }
61: return loc == null ? Location.UNKNOWN : loc;
62: }
63:
64: /**
65: * @deprecated use {@link #getLocation(Parameters)}
66: */
67: public static String getStatementLocation(Parameters param) {
68: return getLocation(param).toString();
69: }
70:
71: /**
72: * For internal use only.
73: */
74: public static class LocatedHashMap extends HashMap implements
75: Locatable {
76: private Location loc;
77:
78: public Location getLocation() {
79: return this .loc;
80: }
81:
82: public LocatedHashMap(Location loc) {
83: this .loc = loc;
84: }
85:
86: public LocatedHashMap(Location loc, int size) {
87: super(size);
88: this.loc = loc;
89: }
90: }
91: }
|