001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE 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 Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixcore.lucefix;
021:
022: import java.io.IOException;
023:
024: import org.apache.lucene.queryParser.ParseException;
025: import org.apache.lucene.search.BooleanQuery;
026:
027: import de.schlund.pfixcore.editor2.core.dom.Project;
028: import de.schlund.pfixcore.editor2.frontend.resources.ProjectsResource;
029: import de.schlund.pfixcore.editor2.frontend.util.EditorResourceLocator;
030: import de.schlund.pfixcore.generator.IHandler;
031: import de.schlund.pfixcore.generator.IWrapper;
032: import de.schlund.pfixcore.lucefix.wrappers.Search;
033: import de.schlund.pfixcore.workflow.Context;
034: import de.schlund.util.statuscodes.StatusCodeLib;
035:
036: public class SearchHandler implements IHandler {
037:
038: private static final String CSEARCH = "de.schlund.pfixcore.lucefix.ContextSearch";
039:
040: public void handleSubmittedData(Context context, IWrapper wrapper)
041: throws ParseException {
042:
043: ContextSearch csearch = (ContextSearch) context
044: .getContextResourceManager().getResource(CSEARCH);
045: Search search = (Search) wrapper;
046:
047: if (search.getDoit() != null && search.getDoit().booleanValue()) {
048: String content = search.getContents();
049: String tags = search.getTags();
050: if (tags != null) {
051: // replace ":" with "\:" - needed for searching for "pfx:button"
052: tags = tags.replace(":", "\\:");
053: }
054: String attribKey = search.getAttribkeys();
055: String attribValue = search.getAttribvalues();
056: String comments = search.getComments();
057: try {
058: csearch.search(content, tags, attribKey, attribValue,
059: comments);
060: } catch (IOException e) {
061: search
062: .addSCodeDoit(StatusCodeLib.PFIXCORE_LUCEFIX_INDEX_NOT_INITED);
063: } catch (BooleanQuery.TooManyClauses tmce) {
064: search
065: .addSCodeDoit(StatusCodeLib.PFIXCORE_LUCEFIX_TOO_MANY_CLAUSES);
066: }
067: }
068: }
069:
070: public void retrieveCurrentStatus(Context context, IWrapper wrapper)
071: throws Exception {
072: ContextSearch csearch = (ContextSearch) context
073: .getContextResourceManager().getResource(CSEARCH);
074: Search search = (Search) wrapper;
075:
076: String tmp;
077:
078: if ((tmp = csearch.getAttribkey()) != null) {
079: search.setAttribkeys(tmp);
080: }
081: if ((tmp = csearch.getAttribvalue()) != null) {
082: search.setAttribvalues(tmp);
083: }
084: if ((tmp = csearch.getContent()) != null) {
085: search.setContents(tmp);
086: }
087: if ((tmp = csearch.getComments()) != null) {
088: search.setComments(tmp);
089: }
090: if ((tmp = csearch.getTags()) != null) {
091: search.setTags(tmp);
092: }
093: }
094:
095: public boolean isActive(Context context) throws Exception {
096: ProjectsResource pcon = EditorResourceLocator
097: .getProjectsResource(context);
098: if (pcon == null)
099: return false;
100: Project currentProject = pcon.getSelectedProject();
101: return currentProject != null;
102: }
103:
104: public boolean needsData(Context context) throws Exception {
105: return false;
106: }
107:
108: public boolean prerequisitesMet(Context context) throws Exception {
109: return true;
110: }
111: }
|