*/
protected ServerResponseHandler getInsertWikiResponseHandler(HttpRequest request) throws org.dbwiki.exception.WikiException, MalformedURLException, IOException {
DatabaseWikiProperties properties = new DatabaseWikiProperties(request.parameters());
DatabaseSchema databaseSchema = null;
//
// Validate parameter values.
//
int message = DatabaseWikiFormPrinter.MessageNone;
//
// Validate name
//
if (properties.getName().equals("")) {
message = DatabaseWikiFormPrinter.MessageNoName;
} else if (!this.isValidWikiName(properties.getName())) {
message = DatabaseWikiFormPrinter.MessageInvalidName;
} else {
for (int iWiki = 0; iWiki < this.size(); iWiki++) {
if (this.get(iWiki).name().equalsIgnoreCase(properties.getName())) {
message = DatabaseWikiFormPrinter.MessageDuplicateName;
}
}
}
//
// Validate title
//
if ((message == DatabaseWikiFormPrinter.MessageNone) && (properties.getTitle().equals(""))) {
message = DatabaseWikiFormPrinter.MessageNoTitle;
}
//
// Validate schema
//
if ((message == DatabaseWikiFormPrinter.MessageNone) && (!properties.getSchema().equals(""))) {
try {
databaseSchema = new SchemaParser().parse(properties.getSchema());
} catch (org.dbwiki.exception.WikiException wikiException) {
wikiException.printStackTrace();
message = DatabaseWikiFormPrinter.MessageErroneousSchema;
}
}
//
// Validate resource. If no schema is specified then generate schema from
// given resource and let the user edit/verify the schema.
//
if ((message == DatabaseWikiFormPrinter.MessageNone) && (!properties.getResource().equals(""))) {
InputStream in = null;
try {
if (properties.getResource().endsWith(".gz")) {
in = new GZIPInputStream(new URL(properties.getResource()).openStream());
} else {
in = new URL(properties.getResource()).openStream();
}
} catch (java.net.MalformedURLException mue) {
message = DatabaseWikiFormPrinter.MessageFileNotFound;
} catch (java.io.IOException ioe) {
message = DatabaseWikiFormPrinter.MessageFileNotFound;
}
if ((message == DatabaseWikiFormPrinter.MessageNone) && (properties.getSchema().equals(""))) {
try {
// FIXME #schemaparsing: Make this a method somewhere...
StructureParser structureParser = new StructureParser();
new SAXCallbackInputHandler(structureParser, false).parse(in, false, false);
if (structureParser.hasException()) {
throw structureParser.getException();
}
databaseSchema = structureParser.getDatabaseSchema();
properties.setSchema(databaseSchema.printSchema());
} catch (Exception excpt) {
throw new WikiFatalException(excpt);
}
message = DatabaseWikiFormPrinter.MessageEditSchema;
}
if (in != null) {
try {
in.close();
} catch (java.io.IOException ioe) {
}
}
}
if (message != DatabaseWikiFormPrinter.MessageNone) {
//
// If parameter validation results in an error message the create wiki
// form is re-displayed showing the error message.
//
ServerResponseHandler responseHandler = new ServerResponseHandler(request, _wikiTitle + " - Create Database Wiki");
responseHandler.put(HtmlContentGenerator.ContentContent, new DatabaseWikiFormPrinter(properties, RequestParameterAction.ActionInsert, "Create Database Wiki", message));
return responseHandler;
} else {
//
// If the parameter values are valid the database wiki is created
//
if ((request.user() == null) && (_authenticationMode != DatabaseWikiProperties.AuthenticateNever)) {
throw new WikiFatalException("User information is missing");
}
if (databaseSchema != null) {
// Path is either the value of the form parameter SCHEMA_PATH or
// the path of the schema root node;
String path = null;
if (!properties.getSchemaPath().equals("")) {
path = properties.getSchemaPath();
databaseSchema = databaseSchema.getSubSchema(path);
} else {
path = databaseSchema.root().path();
}
URL resourceURL = null;
if (!properties.getResource().equals("")) {
resourceURL = new URL(properties.getResource());