001: /*
002: * (C) Copyright 2004 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portlet.search;
020:
021: import java.io.File;
022: import java.io.IOException;
023:
024: import javax.portlet.ActionRequest;
025: import javax.portlet.ActionResponse;
026: import javax.portlet.PortletException;
027:
028: import org.w3c.dom.Element;
029:
030: import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
031: import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
032: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
033: import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
034:
035: /**
036: *
037: *
038: * @author Padmanabh Dabke
039: * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
040: */
041: public class RebuildIndex extends BaseRequestProcessor implements
042: ActionProcessor {
043:
044: String riSeedURL = "http://localhost/stringbeans";
045: String riIndexDir = "C:/temp/index";
046: String[] riIncludeRegex = { "http://localhost" };
047: String[] riExcludeRegex = { ".*maximized.*", ".*minimized.*",
048: ".*process_action.*" };
049: int riMaxSearchDepth = 20;
050:
051: public void init(Element xmlConfig, ControllerPortletConfig config)
052: throws PortletException {
053: super .init(xmlConfig, config);
054: riSeedURL = config.getParameter("seed-url");
055: if (riSeedURL == null)
056: throw new PortletException(
057: "Missing required global parameter: seed-url");
058: riIndexDir = config.getParameter("index-dir");
059: if (riIndexDir == null) {
060: throw new PortletException(
061: "Missing required global parameter: index-dir");
062: }
063: riIndexDir = getRealPath(brpConfig.getPortletContext(),
064: riIndexDir);
065: File indexDir = new File(riIndexDir);
066: if (!indexDir.exists()) {
067: boolean success = indexDir.mkdirs();
068: if (!success) {
069: throw new PortletException(
070: "Failed to create index dir: " + riIndexDir);
071: }
072: }
073:
074: riIncludeRegex = config.getParameterValues("include-regex");
075: if (riIncludeRegex == null || riIncludeRegex.length == 0)
076: throw new PortletException(
077: "Missing required global parameter: include-regex");
078:
079: riExcludeRegex = config.getParameterValues("exclude-regex");
080: if (riExcludeRegex == null || riExcludeRegex.length == 0)
081: throw new PortletException(
082: "Missing required global parameter: exclude-regex");
083:
084: String temp = config.getParameter("max-search-depth");
085: if (temp != null) {
086: try {
087: riMaxSearchDepth = Integer.parseInt(temp);
088: } catch (Exception ex) {
089: throw new PortletException("Invalid max search depth: "
090: + temp + ".", ex);
091: }
092: }
093: }
094:
095: /**
096: * @param request
097: * @param response
098: * @param actionConfig
099: * @return
100: * @throws PortletException
101: * @throws IOException
102: */
103: public String process(ActionRequest request,
104: ActionResponse response, ActionConfig actionConfig)
105: throws PortletException, IOException {
106: WebSiteIndexer.createSiteIndex(riSeedURL, riIndexDir,
107: riIncludeRegex, riExcludeRegex, riMaxSearchDepth);
108: return "success";
109: }
110:
111: }
|