Package org.dbwiki.data.schema

Examples of org.dbwiki.data.schema.DatabaseSchema


   */
  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());
View Full Code Here


      schema.add(schemaNode);
    }
  }
 
  private DatabaseSchema buildRoot(ElementNode node) throws WikiException {
    DatabaseSchema schema = new DatabaseSchema();
    GroupSchemaNode rootSchemaNode = new GroupSchemaNode(schema.size(), node.label(), null);
    schema.add(rootSchemaNode);
   
    for (int i = 0; i < node.children().size(); i++) {
      buildSchema(schema, node.children().get(i), rootSchemaNode);
    }
   
View Full Code Here

      new SAXCallbackInputHandler(structureParser, false).parse(in, false, false);
      in.close();
      if (structureParser.hasException()) {
        throw structureParser.getException();
      }
      DatabaseSchema databaseSchema = structureParser.getDatabaseSchema(args.path);
     
     
      User user = _server.users().get(args.username);
      // register the database with the server
      _server.registerDatabase(args.name, args.title, args.path, inputFile.toURI().toURL(), databaseSchema, user, 1, 0);
View Full Code Here

      new SAXCallbackInputHandler(structureParser, false).parse(in, false, false);
      in.close();
      if (structureParser.hasException()) {
        throw structureParser.getException();
      }
      DatabaseSchema databaseSchema = structureParser.getDatabaseSchema(path);
     
      // register the database with the server
      server.registerDatabase(name, title, path, inputURL, databaseSchema, server.users().get(user), 1, 0);
    } catch (Exception exception) {
      exception.printStackTrace();
View Full Code Here

TOP

Related Classes of org.dbwiki.data.schema.DatabaseSchema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.