%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.rewriter.rules.impl.RulesetImpl |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. 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.jetspeed.rewriter.rules.impl; |
|
18 | ||
19 | import java.util.ArrayList; |
|
20 | import java.util.Collection; |
|
21 | import java.util.HashMap; |
|
22 | import java.util.Iterator; |
|
23 | import java.util.Map; |
|
24 | ||
25 | import org.apache.jetspeed.rewriter.rules.Attribute; |
|
26 | import org.apache.jetspeed.rewriter.rules.Rule; |
|
27 | import org.apache.jetspeed.rewriter.rules.Ruleset; |
|
28 | import org.apache.jetspeed.rewriter.rules.Tag; |
|
29 | ||
30 | /** |
|
31 | * RulesetImpl |
|
32 | * |
|
33 | * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a> |
|
34 | * @version $Id: RulesetImpl.java 516448 2007-03-09 16:25:47Z ate $ |
|
35 | */ |
|
36 | /** |
|
37 | * Ruleset |
|
38 | * |
|
39 | * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a> |
|
40 | * @version $Id: RulesetImpl.java 516448 2007-03-09 16:25:47Z ate $ |
|
41 | */ |
|
42 | 0 | public class RulesetImpl extends IdentifiedImpl implements Ruleset |
43 | { |
|
44 | 0 | private Collection rules = new ArrayList(); |
45 | 0 | private Collection tags = new ArrayList(); |
46 | 0 | private Map ruleMap = new HashMap(); |
47 | 0 | private Map tagMap = new HashMap(); |
48 | 0 | private boolean removeComments = false; |
49 | ||
50 | /* (non-Javadoc) |
|
51 | * @see org.apache.jetspeed.cps.rewriter.rules.Ruleset#getTag(java.lang.String) |
|
52 | */ |
|
53 | public Tag getTag(String tagId) |
|
54 | { |
|
55 | 0 | return (Tag)tagMap.get(tagId); |
56 | } |
|
57 | ||
58 | /* (non-Javadoc) |
|
59 | * @see org.apache.jetspeed.cps.rewriter.rules.Ruleset#getRule(java.lang.String) |
|
60 | */ |
|
61 | public Rule getRule(String ruleId) |
|
62 | { |
|
63 | 0 | return (Rule)ruleMap.get(ruleId); |
64 | } |
|
65 | ||
66 | public String toString() |
|
67 | { |
|
68 | 0 | StringBuffer buffer = new StringBuffer("Ruleset:" + id); |
69 | 0 | if (rules.size() == 0) |
70 | { |
|
71 | 0 | buffer.append(", no rules defined, "); |
72 | } |
|
73 | else |
|
74 | { |
|
75 | 0 | buffer.append(", rules: "); |
76 | 0 | Iterator it = rules.iterator(); |
77 | 0 | while (it.hasNext()) |
78 | { |
|
79 | 0 | RuleImpl rule = (RuleImpl)it.next(); |
80 | 0 | buffer.append(rule.toString()); |
81 | 0 | buffer.append(", "); |
82 | 0 | } |
83 | } |
|
84 | 0 | if (tags.size() == 0) |
85 | { |
|
86 | 0 | buffer.append(" no tags defined."); |
87 | } |
|
88 | else |
|
89 | { |
|
90 | 0 | buffer.append("tags: "); |
91 | 0 | Iterator it = tags.iterator(); |
92 | 0 | while (it.hasNext()) |
93 | { |
|
94 | 0 | TagImpl tag = (TagImpl)it.next(); |
95 | 0 | buffer.append(tag.toString()); |
96 | 0 | buffer.append(", "); |
97 | 0 | } |
98 | } |
|
99 | 0 | return buffer.toString(); |
100 | } |
|
101 | ||
102 | /* (non-Javadoc) |
|
103 | * @see org.apache.jetspeed.cps.rewriter.rules.Ruleset#sync() |
|
104 | */ |
|
105 | public void sync() |
|
106 | { |
|
107 | 0 | ruleMap.clear(); |
108 | 0 | Iterator it = rules.iterator(); |
109 | 0 | while (it.hasNext()) |
110 | { |
|
111 | 0 | Rule rule = (Rule)it.next(); |
112 | 0 | ruleMap.put(rule.getId(), rule); |
113 | 0 | } |
114 | ||
115 | 0 | tagMap.clear(); |
116 | 0 | it = tags.iterator(); |
117 | 0 | while (it.hasNext()) |
118 | { |
|
119 | 0 | Tag tag = (Tag)it.next(); |
120 | 0 | tagMap.put(tag.getId(), tag); |
121 | 0 | Iterator attributes = tag.getAttributes().iterator(); |
122 | 0 | while (attributes.hasNext()) |
123 | { |
|
124 | 0 | Attribute attribute = (Attribute)attributes.next(); |
125 | 0 | if (attribute instanceof AttributeImpl) |
126 | { |
|
127 | 0 | String ruleId = ((AttributeImpl)attribute).getRuleId(); |
128 | 0 | Rule rule = (Rule)ruleMap.get(ruleId); |
129 | 0 | if (rule != null) |
130 | { |
|
131 | 0 | attribute.setRule(rule); |
132 | } |
|
133 | } |
|
134 | 0 | } |
135 | 0 | } |
136 | 0 | } |
137 | ||
138 | /** |
|
139 | * Castor setter |
|
140 | * |
|
141 | * @param rules |
|
142 | */ |
|
143 | public void setRules(Collection rules) |
|
144 | { |
|
145 | 0 | this.rules = rules; |
146 | 0 | } |
147 | ||
148 | /* (non-Javadoc) |
|
149 | * @see org.apache.jetspeed.cps.rewriter.rules.Ruleset#getRules() |
|
150 | */ |
|
151 | public Collection getRules() |
|
152 | { |
|
153 | 0 | return this.rules; |
154 | } |
|
155 | ||
156 | /** |
|
157 | * Castor setter |
|
158 | * |
|
159 | * @param rules |
|
160 | */ |
|
161 | public void setTags(Collection tags) |
|
162 | { |
|
163 | 0 | this.tags = tags; |
164 | 0 | } |
165 | ||
166 | /* (non-Javadoc) |
|
167 | * @see org.apache.jetspeed.cps.rewriter.rules.Ruleset#getTags() |
|
168 | */ |
|
169 | public Collection getTags() |
|
170 | { |
|
171 | 0 | return this.tags; |
172 | } |
|
173 | ||
174 | /* (non-Javadoc) |
|
175 | * @see org.apache.jetspeed.cps.rewriter.rules.Ruleset#getRemoveComments() |
|
176 | */ |
|
177 | public boolean getRemoveComments() |
|
178 | { |
|
179 | 0 | return removeComments; |
180 | } |
|
181 | ||
182 | /* (non-Javadoc) |
|
183 | * @see org.apache.jetspeed.cps.rewriter.rules.Ruleset#setRemoveComments(boolean) |
|
184 | */ |
|
185 | public void setRemoveComments(boolean b) |
|
186 | { |
|
187 | 0 | removeComments = b; |
188 | 0 | } |
189 | ||
190 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |