String newPublicationId, String publicationsUri) throws MalformedURLException,
IOException, ParserConfigurationException, SAXException, SourceNotFoundException,
TransformerConfigurationException, TransformerException, ServiceException,
ConfigurationException {
ModifiableSource indexSource = null;
IndexManager indexManager = null;
try {
// RGE: Soc addition
// First, patch the xconf patchfile with the new publication name
String indexDir = "lenya/pubs/" + newPublicationId + "/work/lucene/index";
indexSource = (ModifiableSource) resolver
.resolveURI(publicationsUri
+ "/"
+ newPublicationId
+ "/config/"
+ org.apache.cocoon.components.search.components.impl.IndexManagerImpl.INDEX_CONF_FILE);
Document indexDoc = DocumentHelper.readDocument(indexSource.getInputStream());
Element[] indexElement = DocumentHelper.getChildren(indexDoc.getDocumentElement(),
null, "index");
for (int i = 0; i < indexElement.length; i++) {
String id = indexElement[i].getAttribute("id");
String area = id.split("-")[1];
indexElement[i].setAttribute("id", newPublicationId + "-" + area);
indexElement[i].setAttribute("directory", indexDir + "/" + area + "/index");
}
save(indexDoc, indexSource);
// Second, configure the index and add it to the IndexManager
indexManager = (IndexManager) manager.lookup(IndexManager.ROLE);
indexManager.addIndexes(indexSource);
// TODO: release all objects!
// RGE: End Soc addition