blob: 7cffd7eb8415984f1fadb8c2d5670ab8e26b9c5e [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 org.apache.lenya.cms.publication.Area;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.URLInformation;
import org.apache.lenya.cms.usecase.AbstractUsecase;
/**
* Index all documents of the current publication in the current area.
*/
public class IndexSite extends AbstractUsecase {
public void doExecute() throws Exception {
String url = getSourceURL();
URLInformation info = new URLInformation(url);
String pubId = info.getPublicationId();
DocumentFactory factory = getDocumentFactory();
Publication pub = factory.getPublication(pubId);
Area area = pub.getArea(info.getArea());
Document[] docs = area.getDocuments();
IndexUpdater updater = null;
try {
updater = (IndexUpdater) this.manager.lookup(IndexUpdater.ROLE);
for (int i = 0; i < docs.length; i++) {
try {
updater.index(getSession(), docs[i].getResourceType(), pubId, area.getName(),
docs[i].getUUID(), docs[i].getLanguage());
} catch (Exception e) {
String message = "Error indexing document [" + docs[i].getPath() + ":"
+ docs[i].getLanguage() + "], UUID=" + docs[i].getUUID();
addErrorMessage(e + ", see logfiles for more information.");
getLogger().error(message, e);
}
}
} finally {
if (updater != null) {
this.manager.release(updater);
}
}
}
}