1 31 32 package org.opencms.workplace.tools.searchindex; 33 34 import org.opencms.configuration.CmsSearchConfiguration; 35 import org.opencms.jsp.CmsJspActionElement; 36 import org.opencms.main.CmsIllegalStateException; 37 import org.opencms.main.OpenCms; 38 import org.opencms.search.CmsSearchIndexSource; 39 import org.opencms.search.CmsSearchManager; 40 import org.opencms.workplace.CmsWidgetDialog; 41 import org.opencms.workplace.CmsWorkplaceSettings; 42 43 import java.util.ArrayList ; 44 import java.util.HashMap ; 45 import java.util.List ; 46 import java.util.Map ; 47 48 import javax.servlet.http.HttpServletRequest ; 49 import javax.servlet.http.HttpServletResponse ; 50 import javax.servlet.jsp.PageContext ; 51 52 72 public abstract class A_CmsEditIndexSourceDialog extends CmsWidgetDialog { 73 74 75 public static final String KEY_PREFIX = "indexsource"; 76 77 78 public static final String [] PAGES = {"page1"}; 79 80 87 public static final String PARAM_INDEXSOURCE = "indexsource"; 88 89 90 protected CmsSearchIndexSource m_indexsource; 91 92 93 protected CmsSearchManager m_searchManager; 94 95 96 private String m_paramIndexSource; 97 98 103 public A_CmsEditIndexSourceDialog(CmsJspActionElement jsp) { 104 105 super(jsp); 106 } 107 108 115 public A_CmsEditIndexSourceDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 116 117 this(new CmsJspActionElement(context, req, res)); 118 } 119 120 124 protected static void writeConfiguration() { 125 126 OpenCms.writeConfiguration(CmsSearchConfiguration.class); 128 } 129 130 133 public void actionCommit() { 134 135 List errors = new ArrayList (); 136 137 try { 138 139 if (!m_searchManager.getSearchIndexSources().keySet().contains(m_indexsource.getName())) { 141 m_searchManager.addSearchIndexSource(m_indexsource); 142 } 143 writeConfiguration(); 144 145 } catch (Throwable t) { 146 errors.add(t); 147 } 148 149 setCommitErrors(errors); 151 } 152 153 158 public String getParamIndexsource() { 159 160 return m_paramIndexSource; 161 } 162 163 168 public void setParamIndexsource(String indexsource) { 169 170 m_paramIndexSource = indexsource; 171 } 172 173 183 protected void defineWidgets() { 184 185 initUserObject(); 186 setKeyPrefix(KEY_PREFIX); 187 188 } 189 190 193 protected String [] getPageArray() { 194 195 return PAGES; 196 } 197 198 203 protected String getToolPath() { 204 205 return "/searchindex/indexsources/indexsource"; 206 } 207 208 211 protected void initMessages() { 212 213 addMessages(Messages.get().getBundleName()); 215 super.initMessages(); 217 } 218 219 228 protected void initUserObject() { 229 230 if (m_indexsource == null) { 231 try { 232 m_indexsource = m_searchManager.getIndexSource(getParamIndexsource()); 233 if (m_indexsource == null) { 234 m_indexsource = new CmsSearchIndexSource(); 235 } 236 } catch (Exception e) { 237 m_indexsource = new CmsSearchIndexSource(); 238 } 239 } 240 } 241 242 248 protected void initWorkplaceMembers(CmsJspActionElement jsp) { 249 250 m_searchManager = OpenCms.getSearchManager(); 251 super.initWorkplaceMembers(jsp); 252 } 253 254 257 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 258 259 super.initWorkplaceRequestValues(settings, request); 261 262 Map dialogObject = (Map )getDialogObject(); 264 if (dialogObject == null) { 265 dialogObject = new HashMap (); 266 dialogObject.put(PARAM_INDEXSOURCE, m_indexsource); 267 setDialogObject(dialogObject); 268 } 269 270 } 271 272 277 protected boolean isNewIndexSource() { 278 279 return DIALOG_INITIAL.equals(getParamAction()); 280 } 281 282 285 protected void validateParamaters() throws Exception { 286 287 if (!isNewIndexSource()) { 288 if (getParamIndexsource() == null && getJsp().getRequest().getParameter("name.0") == null) { 290 throw new CmsIllegalStateException(Messages.get().container( 291 Messages.ERR_SEARCHINDEX_EDIT_MISSING_PARAM_1, 292 PARAM_INDEXSOURCE)); 293 } 294 } 295 } 296 } | Popular Tags |