blob: 40b2bb796a087595d659a574cda21368fee18e1e [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.lenya.cms.lucene;
import java.util.Arrays;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.publication.Node;
import org.apache.lenya.cms.usecase.DocumentUsecase;
import org.apache.lenya.cms.usecase.UsecaseException;
/**
* Usecase to maintain lucene index.
*/
public class IndexDocument extends DocumentUsecase {
private SourceResolver sourceResolver;
/**
* The URI to copy the document source from.
*/
public static final String SOURCE_URI = "sourceUri";
public static final String INDEX_ACTION = "indexAction";
public static final String INDEX = "index";
public static final String DELETE = "delete";
public static final String INDEX_AREA = "indexArea";
/**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
*/
protected void doExecute() throws Exception {
super.doExecute();
SourceResolver resolver = getSourceResolver();
Source source = null;
String action = super.getParameterAsString(INDEX_ACTION);
String area = super.getParameterAsString(INDEX_AREA);
try {
String[] formats = getSourceDocument().getResourceType().getFormats();
if (!Arrays.asList(formats).contains("luceneIndex")) {
getLogger().warn(
"Document [" + getSourceDocument()
+ "] is not being indexed because resource type ["
+ getSourceDocument().getResourceType().getName()
+ "] does not support indexing!");
return;
}
if (action.equals(INDEX)) {
// index
source = resolver.resolveURI("cocoon://modules/lucene/index-" + area + ".xml");
org.apache.cocoon.components.source.SourceUtil.getInputSource(source);
} else if (action.equals(DELETE)) {
// delete
source = resolver.resolveURI("cocoon://modules/lucene/delete-" + area + ".xml");
org.apache.cocoon.components.source.SourceUtil.getInputSource(source);
}
} finally {
if (source != null) {
resolver.release(source);
}
}
}
/**
* @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
*/
protected Node[] getNodesToLock() throws UsecaseException {
if (getLogger().isDebugEnabled()) {
getLogger().debug(
"IndexDocument::getObjectsToLock() called on source document ["
+ getSourceDocument() + "]");
}
Node[] objects = { getSourceDocument() };
return objects;
}
/**
* TODO: Bean wiring
*/
public void setSourceResolver(SourceResolver sourceResolver) {
this.sourceResolver = sourceResolver;
}
public SourceResolver getSourceResolver() {
return sourceResolver;
}
}