001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.workplace.tools.searchindex.sourcesearch; 029 030import org.opencms.util.CmsStringUtil; 031 032import java.util.LinkedList; 033import java.util.List; 034 035/** 036 * Settings bean for the dialog. 037 * <p> 038 * 039 * @since 7.5.3 040 * 041 */ 042 043public class CmsSearchReplaceSettings { 044 045 /** The content search result list attribute name in the session. */ 046 public static final String ATTRIBUTE_NAME_SOURCESEARCH_RESULT_LIST = "sourcesearchResultList"; 047 048 /** Constant for vfs. */ 049 public static final String VFS = "vfs"; 050 051 /** The force replacement flag. */ 052 private boolean m_forceReplace; 053 054 /** When replacing XML content, replace-operation only applies to this locale. */ 055 private String m_locale; 056 057 /** Display message. */ 058 private String m_message; 059 060 /** Flag indicating if only content values should be searched and replaced. */ 061 private boolean m_onlyContentValues; 062 063 /** The paths to collect resources. */ 064 private List<String> m_paths = new LinkedList<String>(); 065 066 /** The project to use. */ 067 private String m_project; 068 069 /** The search query to filter matching resources. */ 070 private String m_query; 071 072 /** The replace pattern. */ 073 private String m_replacepattern; 074 075 /** The list of resource paths to process: all should be files. */ 076 private String[] m_resources; 077 078 /** The search pattern. */ 079 private String m_searchpattern; 080 081 /** The source to retrive the resources from. */ 082 private String m_source; 083 084 /** The resource type to use for replacement. */ 085 private String[] m_types; 086 087 /** The Xpath to perform the replacement. */ 088 private String m_xpath; 089 090 /** 091 * Bean constructor with cms object for path validation.<p> 092 */ 093 public CmsSearchReplaceSettings() { 094 095 super(); 096 m_paths.add("/"); 097 } 098 099 /** 100 * Returns the locale.<p> 101 * 102 * @return the locale 103 */ 104 public String getLocale() { 105 106 return m_locale; 107 } 108 109 /** 110 * @return the message 111 */ 112 public String getMessage() { 113 114 return m_message; 115 } 116 117 /** 118 * @return the paths 119 */ 120 public List<String> getPaths() { 121 122 return m_paths; 123 } 124 125 /** 126 * @return the project 127 */ 128 public String getProject() { 129 130 return m_project; 131 } 132 133 /** 134 * Returns the query.<p> 135 * 136 * @return the query 137 */ 138 public String getQuery() { 139 140 return m_query; 141 } 142 143 /** 144 * @return the replace pattern 145 */ 146 public String getReplacepattern() { 147 148 return m_replacepattern; 149 } 150 151 /** 152 * @return the resources 153 */ 154 public String getResources() { 155 156 return CmsStringUtil.arrayAsString(m_resources, ","); 157 } 158 159 /** 160 * Returns the resources paths in an array.<p> 161 * 162 * @return the resources paths in an array. 163 */ 164 public String[] getResourcesArray() { 165 166 return m_resources; 167 } 168 169 /** 170 * @return the search pattern 171 */ 172 public String getSearchpattern() { 173 174 return m_searchpattern; 175 } 176 177 /** 178 * Returns the source.<p> 179 * 180 * @return the source 181 */ 182 public String getSource() { 183 184 return m_source; 185 } 186 187 /** 188 * Returns the type.<p> 189 * 190 * @return the type 191 */ 192 public String getTypes() { 193 194 return m_types != null ? CmsStringUtil.arrayAsString(m_types, ",") : ""; 195 } 196 197 /** 198 * Returns the type.<p> 199 * 200 * @return the type 201 */ 202 public String[] getTypesArray() { 203 204 return m_types; 205 } 206 207 /** 208 * Returns the xpath.<p> 209 * 210 * @return the xpath 211 */ 212 public String getXpath() { 213 214 return m_xpath; 215 } 216 217 /** 218 * Returns the force replace flag, if <code>true</code> the replacement 219 * will also be performed if the replacement String is empty.<p> 220 * 221 * @return the force replace flag 222 */ 223 public boolean isForceReplace() { 224 225 return m_forceReplace; 226 } 227 228 /** 229 * Returns if only content values should be searched and replaced.<p> 230 * 231 * @return if only content values should be searched and replaced 232 */ 233 public boolean isOnlyContentValues() { 234 235 return m_onlyContentValues; 236 } 237 238 /** 239 * Returns <code>true</code> if Solr index is selected and a query was entered.<p> 240 * 241 * @return <code>true</code> if Solr index is selected and a query was entered 242 */ 243 public boolean isSolrSearch() { 244 245 if (VFS.equals(m_source)) { 246 // VFS search selected 247 return false; 248 } 249 // index selected and query entered --> Solr search else VFS 250 return (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_source) 251 && CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_query)); 252 } 253 254 /** 255 * Sets the force replace flag.<p> 256 * 257 * @param forceReplace the force replace flag to set 258 */ 259 public void setForceReplace(boolean forceReplace) { 260 261 m_forceReplace = forceReplace; 262 } 263 264 /** 265 * Sets the locale.<p> 266 * 267 * @param locale the locale to set 268 */ 269 public void setLocale(String locale) { 270 271 m_locale = locale; 272 } 273 274 /** 275 * @param message the message to set 276 */ 277 public void setMessage(final String message) { 278 279 // nop, this is hardcoded... just has to be here for "bean - convention". 280 } 281 282 /** 283 * Sets if only content values should be searched and replaced.<p> 284 * 285 * @param onlyContentValue if only content values should be searched and replaced 286 */ 287 public void setOnlyContentValues(boolean onlyContentValue) { 288 289 m_onlyContentValues = onlyContentValue; 290 } 291 292 /** 293 * Sets the paths.<p> 294 * 295 * @param paths the paths to set 296 */ 297 public void setPaths(final List<String> paths) { 298 299 m_paths = paths; 300 } 301 302 /** 303 * @param project the project to work in 304 */ 305 public void setProject(String project) { 306 307 m_project = project; 308 } 309 310 /** 311 * Sets the query.<p> 312 * 313 * @param query the query to set 314 */ 315 public void setQuery(String query) { 316 317 m_query = query; 318 } 319 320 /** 321 * Sets the replace pattern.<p> 322 * 323 * @param replacepattern the replace pattern 324 */ 325 public void setReplacepattern(String replacepattern) { 326 327 m_replacepattern = replacepattern; 328 } 329 330 /** 331 * @param resources 332 * the resources to set 333 */ 334 public void setResources(final String resources) { 335 336 m_resources = CmsStringUtil.splitAsArray(resources, ","); 337 338 } 339 340 /** 341 * Sets the search pattern.<p> 342 * 343 * @param searchpattern the search pattern 344 */ 345 public void setSearchpattern(String searchpattern) { 346 347 m_searchpattern = searchpattern; 348 } 349 350 /** 351 * Sets the source.<p> 352 * 353 * @param source the source to set 354 */ 355 public void setSource(String source) { 356 357 m_source = source; 358 } 359 360 /** 361 * Sets the type.<p> 362 * 363 * @param types the type to set 364 */ 365 public void setTypes(String types) { 366 367 m_types = CmsStringUtil.splitAsArray(types, ","); 368 } 369 370 /** 371 * Sets the xpath.<p> 372 * 373 * @param xpath the xpath to set 374 */ 375 public void setXpath(String xpath) { 376 377 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(xpath)) { 378 xpath = xpath.trim(); 379 if (xpath.startsWith("/")) { 380 xpath = xpath.substring(1); 381 } 382 if (xpath.endsWith("/")) { 383 xpath = xpath.substring(0, xpath.length() - 1); 384 } 385 } 386 m_xpath = xpath; 387 } 388}