KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > staticexport > CmsStaticExportRfsRule


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/staticexport/CmsStaticExportRfsRule.java,v $
3  * Date : $Date: 2005/07/18 12:27:48 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2002 - 2005 Alkacon Software (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.staticexport;
33
34 import org.opencms.main.CmsIllegalArgumentException;
35 import org.opencms.main.OpenCms;
36
37 import java.util.ArrayList JavaDoc;
38 import java.util.Collections JavaDoc;
39 import java.util.List JavaDoc;
40 import java.util.regex.Pattern JavaDoc;
41
42 /**
43  * Help class for storing of rfs-rules..<p>
44  *
45  * @author Michael Moossen
46  * @version $Revision: 1.2 $
47  * @since 6.0.0
48  */

49 public class CmsStaticExportRfsRule {
50
51     /** Description of the rule. */
52     private String JavaDoc m_description;
53
54     /** Rfs export path. */
55     private String JavaDoc m_exportPath;
56
57     /** configured Rfs export path. */
58     private final String JavaDoc m_exportPathConfigured;
59
60     /** Name of rule. */
61     private String JavaDoc m_name;
62
63     /** List of regular expresions to determine related system resources. */
64     private List JavaDoc m_relatedSystemResources;
65
66     /** configured Url prefix. */
67     private final String JavaDoc m_rfsPreConfigured;
68
69     /** Url prefix pattern. */
70     private String JavaDoc m_rfsPrefix;
71
72     /** Source regex. */
73     private final Pattern JavaDoc m_source;
74
75     /** Relative links value. */
76     private Boolean JavaDoc m_useRelativeLinks;
77
78     /**
79      * Default constructor.<p>
80      *
81      * @param name the name of the rule
82      * @param description the description for the rule
83      * @param source the source regex
84      * @param rfsPrefix the url prefix
85      * @param exportPath the rfs export path
86      * @param useRelativeLinks Relative links value
87      */

88     public CmsStaticExportRfsRule(
89         String JavaDoc name,
90         String JavaDoc description,
91         String JavaDoc source,
92         String JavaDoc rfsPrefix,
93         String JavaDoc exportPath,
94         Boolean JavaDoc useRelativeLinks) {
95
96         m_name = name;
97         m_description = description;
98         m_source = Pattern.compile(source);
99         m_rfsPreConfigured = rfsPrefix;
100         m_exportPathConfigured = exportPath;
101         m_useRelativeLinks = useRelativeLinks;
102         m_relatedSystemResources = new ArrayList JavaDoc();
103     }
104
105     /**
106      * Full constructor.<p>
107      *
108      * @param name the name of the rule
109      * @param description the description for the rule
110      * @param source the source regex
111      * @param rfsPrefix the url prefix
112      * @param exportPath the rfs export path
113      * @param useRelativeLinks Relative links value
114      * @param relatedSystemRes list of <code>{@link Pattern}</code>s
115      */

116     public CmsStaticExportRfsRule(
117         String JavaDoc name,
118         String JavaDoc description,
119         String JavaDoc source,
120         String JavaDoc rfsPrefix,
121         String JavaDoc exportPath,
122         Boolean JavaDoc useRelativeLinks,
123         List JavaDoc relatedSystemRes) {
124
125         this(name, description, source, rfsPrefix, exportPath, useRelativeLinks);
126         m_relatedSystemResources.addAll(relatedSystemRes);
127     }
128
129     /**
130      * Adds a regex of related system resources.<p>
131      *
132      * @param regex the regex to add
133      */

134     public void addRelatedSystemRes(String JavaDoc regex) {
135
136         m_relatedSystemResources.add(Pattern.compile(regex));
137     }
138
139     /**
140      * Returns the description.<p>
141      *
142      * @return the description
143      */

144     public String JavaDoc getDescription() {
145
146         return m_description;
147     }
148
149     /**
150      * Returns the rfs export Path.<p>
151      *
152      * @return the rfs export Path
153      */

154     public String JavaDoc getExportPath() {
155
156         return m_exportPath;
157     }
158
159     /**
160      * Returns the configured rfs export Path with unstubstituted context values.<p>
161      *
162      * @return the configured rfs export Path
163      */

164     public String JavaDoc getExportPathConfigured() {
165
166         return m_exportPathConfigured;
167     }
168
169     /**
170      * Returns the name.<p>
171      *
172      * @return the name
173      */

174     public String JavaDoc getName() {
175
176         return m_name;
177     }
178
179     /**
180      * Returns the related system resources list as list of <code>{@link Pattern}</code>.<p>
181      *
182      * @return the related resources list as list of <code>{@link Pattern}</code>
183      */

184     public List JavaDoc getRelatedSystemResources() {
185
186         return Collections.unmodifiableList(m_relatedSystemResources);
187     }
188
189     /**
190      * Returns the url Prefix with macro replacement.<p>
191      *
192      * @return the url Prefix
193      */

194     public String JavaDoc getRfsPrefix() {
195
196         return m_rfsPrefix;
197     }
198
199     /**
200      * Returns the configured url Prefix with unstubstituted context values.<p>
201      *
202      * @return the configured url Prefix
203      */

204     public String JavaDoc getRfsPrefixConfigured() {
205
206         return m_rfsPreConfigured;
207     }
208
209     /**
210      * Returns the source regex pattern.<p>
211      *
212      * @return the source regex pattern
213      */

214     public Pattern JavaDoc getSource() {
215
216         return m_source;
217     }
218
219     /**
220      * Returns true if the links in the static export should be relative.<p>
221      *
222      * @return true if the links in the static export should be relative
223      */

224     public Boolean JavaDoc getUseRelativeLinks() {
225
226         return m_useRelativeLinks;
227     }
228
229     /**
230      * Checks if a vfsName matches the given related system resource patterns.<p>
231      *
232      * @param vfsName the vfs name of a resource to check
233      * @return true if the name matches one of the given related system resource patterns
234      */

235     public boolean match(String JavaDoc vfsName) {
236
237         for (int j = 0; j < m_relatedSystemResources.size(); j++) {
238             Pattern JavaDoc pattern = (Pattern JavaDoc)m_relatedSystemResources.get(j);
239             if (pattern.matcher(vfsName).matches()) {
240                 return true;
241             }
242         }
243         return false;
244     }
245
246     /**
247      * Sets the rfs export Path after normalizing.<p>
248      *
249      * @param exportPath the rfs export Path to set
250      */

251     public void setExportPath(String JavaDoc exportPath) {
252
253         if (exportPath.equals(OpenCms.getSystemInfo().getWebApplicationRfsPath())) {
254             // not allowed because a full static export would delete the opencms directory
255
throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_INVALID_EXPORT_PATH_1, m_name));
256         }
257         m_exportPath = exportPath;
258     }
259
260     /**
261      * Sets the url Prefix after normalizing.<p>
262      *
263      * @param rfsPrefix the url Prefix to set
264      */

265     public void setRfsPrefix(String JavaDoc rfsPrefix) {
266
267         m_rfsPrefix = rfsPrefix;
268     }
269
270     /**
271      * @see java.lang.Object#toString()
272      */

273     public String JavaDoc toString() {
274
275         StringBuffer JavaDoc ret = new StringBuffer JavaDoc(getClass().getName());
276         ret.append(":[");
277         ret.append("name: ").append(m_name).append("; ");
278         ret.append("description: ").append(m_description).append("; ");
279         ret.append("source: ").append(m_source).append("; ");
280         ret.append("exportPath: ").append(m_exportPath).append("; ");
281         ret.append("rfsPrefix: ").append(m_rfsPrefix).append("; ");
282         ret.append("useRelativeLinks: ").append(m_useRelativeLinks).append("; ");
283         ret.append("relatedSystemRes: ").append(m_relatedSystemResources).append("; ");
284         return ret.append("]").toString();
285     }
286
287 }
288
Popular Tags