/*
* 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.
*
* $Id: CreateCollectionViewer.java 541515 2007-05-25 02:45:06Z vgritsenko $
*/
package org.apache.xindice.webadmin.viewer.components;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.xindice.core.Collection;
import org.apache.xindice.util.Configuration;
import org.apache.xindice.webadmin.util.CollectionConfigurationHelper;
import org.apache.xindice.webadmin.viewer.HtmlCollectionViewer;
import org.apache.xindice.webadmin.viewer.HtmlViewerComponent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Xindice Html Viewer for creating a new collection.
*
* @author <a href="mailto:jmetzner@apache.org">Jan Metzner</a>
* @version $Revision: 541515 $, $Date: 2007-05-24 22:45:06 -0400 (Thu, 24 May 2007) $
*/
public class CreateCollectionViewer extends HtmlViewerComponent implements HtmlCollectionViewer {
private static final Log log = LogFactory.getLog(CreateCollectionViewer.class);
public void execute(HttpServletRequest req, HttpServletResponse res, Collection col)
throws ServletException, IOException {
String path = col.getCanonicalName();
String title = "Create Subcollection in " + path;
ServletOutputStream output = startViewer(title, path, res);
String name = req.getParameter("name");
String inlineMeta = req.getParameter("meta");
String compressed = req.getParameter("compressed");
String filer = req.getParameter("filer");
if (name == null || name.length() == 0) {
printStartTable(title, output);
printStartSingleTableBox(output);
output.print(CREATE_FORM_START);
output.print(CollectionConfigurationHelper.getDefaultInlineMetadata());
output.print(CREATE_FORM_META_DEFAULT);
output.print(!CollectionConfigurationHelper.getDefaultInlineMetadata());
output.print(CREATE_FORM_META_END);
output.print(CollectionConfigurationHelper.getDefaultCompressed());
output.print(CREATE_FORM_COMPRESSED_DEFAULT);
output.print(!CollectionConfigurationHelper.getDefaultCompressed());
output.print(CREATE_FORM_COMPRESSED_END);
output.print(CollectionConfigurationHelper.getDefaultFilerClass());
output.print(CREATE_FORM_FILER);
printEndSingleTableBox(output);
printEndTable(output);
} else {
try {
Configuration config = CollectionConfigurationHelper.createConfiguration(name, compressed, inlineMeta, filer);
col.createCollection(name, config);
printStartTable(title, output);
printStartSingleTableBox(output);
output.print("<b>Collection <a href=\"./");
output.print(name);
output.print("/?viewer=default\"><b>");
output.print(name);
output.print("</b></a> created!</b>");
printEndSingleTableBox(output);
printEndTable(output);
} catch (Exception e) {
log.error(e);
title = "Error while creating new Collection!";
printStartTable(title, output);
printStartSingleTableBox(output);
output.print("<b>Could not create Collection ");
output.print(name);
output.print("!</b><br />");
output.print(e.getMessage());
printEndSingleTableBox(output);
printEndTable(output);
}
}
finishViewer(output);
}
protected String getName() {
return "create";
}
}