001: /*
002: * Copyright 2007 Hippo.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package nl.hippo.cms.searchandreplace;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.Locale;
023: import nl.hippo.cms.searchandreplace.log.NoOperationLog;
024: import nl.hippo.cms.searchandreplace.log.SearchAndReplaceLog;
025: import org.apache.commons.httpclient.HttpState;
026:
027: /**
028: * <p>
029: * A simple bean implementation of {@link SearchAndReplaceConfiguration}.
030: * </p>
031: */
032: public class SearchAndReplaceConfigurationBean implements
033: SearchAndReplaceConfiguration {
034: /**
035: * <p>
036: * The default scope XPath. It will return all text nodes of a document.
037: * </p>
038: */
039: private static final String DEFAULT_SCOPE_XPATH = "//text()";
040:
041: private String m_documentsBaseUrl;
042:
043: private List m_documentUrls = new ArrayList();
044:
045: private String m_scopeXpath = DEFAULT_SCOPE_XPATH;
046:
047: private String m_textToReplace;
048:
049: private boolean m_isSearchCaseSensitive = true;
050:
051: private Locale m_locale = Locale.getDefault();
052:
053: private String m_replacementText;
054:
055: private HttpState m_httpState;
056:
057: private SearchAndReplaceListener m_listener = NoOperationListener
058: .getInstance();
059:
060: private SearchAndReplaceLog m_log = NoOperationLog.getInstance();
061:
062: /**
063: * <p>
064: * Create an instance of this class. The following attributes will be
065: * set to default values:
066: * </p>
067: * <table>
068: * <tr>
069: * <th>Attribute</th>
070: * <th>Default value</th>
071: * </tr>
072: * <tr>
073: * <td>documentUrls</td>
074: * <td>Empty list.</td>
075: * </tr>
076: * <tr>
077: * <td>scopeXpath</td>
078: * <td><code>//text()</code> (all text and CDATA nodes of the
079: * document)</td>
080: * </tr>
081: * <tr>
082: * <td>isSearchCaseSensitive</td>
083: * <td><code>true</code></td>
084: * </tr>
085: * <tr>
086: * <td>locale</td>
087: * <td>The default locale of the system.</td>
088: * </tr>
089: * <tr>
090: * <td>listener</td>
091: * <td>A instance of {@link NoOperationListener}.</td>
092: * </tr>
093: * <tr>
094: * <td>log</td>
095: * <td>A instance of {@link NoOperationLog}.</td>
096: * </tr>
097: * </table>
098: */
099: public SearchAndReplaceConfigurationBean() {
100: super ();
101:
102: // No action needed. The attributes are initialized using initializers.
103: }
104:
105: public String getDocumentsBaseUrl() {
106: return m_documentsBaseUrl;
107: }
108:
109: public void setDocumentsBaseUrl(String url) {
110: m_documentsBaseUrl = url;
111: }
112:
113: public Iterator documentUrlsIterator() {
114: return m_documentUrls.iterator();
115: }
116:
117: /**
118: * <p>
119: * Add a relative document URL to the list of document URLs in which to
120: * replace text. The order in which the URLs are added is preserved.
121: * </p>
122: *
123: * @param url
124: * the relative document URL.
125: */
126: public void addDocumentUrl(String url) {
127: m_documentUrls.add(url);
128: }
129:
130: /**
131: * <p>
132: * Add a collection of relative document URLs to the list of document
133: * URLs in which to replace text. The order in which the URLs are added
134: * is preserved.
135: * </p>
136: *
137: * @param urls
138: * the relative document URLs.
139: */
140: public void addDocumentUrls(Collection urls) {
141: m_documentUrls.addAll(urls);
142: }
143:
144: public String getScopeXpath() {
145: return m_scopeXpath;
146: }
147:
148: public void setScopeXpath(String xpath) {
149: m_scopeXpath = xpath;
150: }
151:
152: public String getTextToReplace() {
153: return m_textToReplace;
154: }
155:
156: public void setTextToReplace(String textToReplace) {
157: m_textToReplace = textToReplace;
158: }
159:
160: public boolean isSearchCaseSensitive() {
161: return m_isSearchCaseSensitive;
162: }
163:
164: public void setIsSearchCaseSensitive(boolean isSearchCaseSensitive) {
165: m_isSearchCaseSensitive = isSearchCaseSensitive;
166: }
167:
168: public Locale getLocale() {
169: return m_locale;
170: }
171:
172: public void setLocale(Locale locale) {
173: m_locale = locale;
174: }
175:
176: public String getReplacementText() {
177: return m_replacementText;
178: }
179:
180: public void setReplacementText(String replacementText) {
181: m_replacementText = replacementText;
182: }
183:
184: public HttpState getHttpState() {
185: return m_httpState;
186: }
187:
188: public void setHttpState(HttpState httpState) {
189: m_httpState = httpState;
190: }
191:
192: public SearchAndReplaceListener getListener() {
193: return m_listener;
194: }
195:
196: public void setListener(SearchAndReplaceListener listener) {
197: m_listener = listener;
198: }
199:
200: public SearchAndReplaceLog getLog() {
201: return m_log;
202: }
203:
204: public void setLog(SearchAndReplaceLog log) {
205: m_log = log;
206: }
207: }
|