Package org.dbwiki.web.server

Examples of org.dbwiki.web.server.DatabaseWikiProperties


   * @throws MalformedURLException
   * @throws IOException
   */
  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());
        }
       
        try {
          registerDatabase(properties.getName(), properties.getTitle(), path, resourceURL, databaseSchema, request.user(),
              properties.getAuthentication(), properties.getAutoSchemaChanges());
        } catch (java.sql.SQLException sqlException) {
          throw new WikiFatalException(sqlException);
        }
      } else {
        throw new WikiFatalException("Empty Schema");
View Full Code Here


   
    // Validate data passed in from form
    // FIXME #security: Check that the other fields have reasonable values!
    DatabaseWiki wiki = this.getRequestWiki(request, ParameterName);
   
    DatabaseWikiProperties properties = new DatabaseWikiProperties(request.parameters());
   
    int message = DatabaseWikiFormPrinter.MessageNone;
    if (properties.getTitle().equals("")) {
      message = DatabaseWikiFormPrinter.MessageNoTitle;
    }
   
    // If invalid, pass back appropriate message.
    if (message != DatabaseWikiFormPrinter.MessageNone) {
      ServerResponseHandler responseHandler = new ServerResponseHandler(request, _wikiTitle + " - Edit Database Wiki");
      responseHandler.put(HtmlContentGenerator.ContentContent, new DatabaseWikiFormPrinter(properties, RequestParameterAction.ActionUpdate, "Edit Database Wiki", message));
      return responseHandler;
    } else {
      // Otherwise, apply the changes.
      if ((request.user() == null) && (_authenticationMode != DatabaseWikiProperties.AuthenticateNever)) {
        throw new WikiFatalException("User information is missing");
      }
      try {
        Connection con = _connector.getConnection();
        con.setAutoCommit(false);
        PreparedStatement pStmt = con.prepareStatement("UPDATE " + RelationDatabase + " " +
          "SET " + RelDatabaseColTitle + " = ?, " +
          RelDatabaseColAuthentication + " = ?, " +
          RelDatabaseColAutoSchemaChanges + " = ? " +
          "WHERE " + RelDatabaseColID + " = " + wiki.id());
        pStmt.setString(1, properties.getTitle());
        pStmt.setInt(2, properties.getAuthentication());
        pStmt.setInt(3, properties.getAutoSchemaChanges());
        pStmt.execute();
        pStmt.close();
        con.commit();
        con.close();
      } catch (java.sql.SQLException sqlException) {
        throw new WikiFatalException(sqlException);
      }
      wiki.setAuthenticationMode(properties.getAuthentication());
      wiki.setAutoSchemaChanges(properties.getAutoSchemaChanges());
      wiki.setTitle(properties.getTitle());
      sortWikiListing();
      return this.getHomepageResponseHandler(request);
    }
  }
View Full Code Here

   */

// TODO: Build properties directly, removing dependence of DatabaseWikiProperties on DatabaseWiki
   public DatabaseWikiProperties getProperties() {
    
     return new DatabaseWikiProperties(this);
    
   }
View Full Code Here

  public DatabaseWikiFormPrinter(DatabaseWikiProperties properties, String action, String headline) {
    this(properties, action, headline, MessageNone);
  }

  public DatabaseWikiFormPrinter(String headline) {
    this(new DatabaseWikiProperties(), RequestParameterAction.ActionInsert, headline, MessageNone);
  }
View Full Code Here

TOP

Related Classes of org.dbwiki.web.server.DatabaseWikiProperties

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.