Exemple #1
0
 @Override
 public void init(final ServletConfig config) throws ServletException {
   super.init(config);
   try {
     HTTPContext.init(config.getServletContext());
     final Enumeration<String> en = config.getInitParameterNames();
     while (en.hasMoreElements()) {
       String key = en.nextElement().toLowerCase(Locale.ENGLISH);
       final String val = config.getInitParameter(key);
       if (key.startsWith(Prop.DBPREFIX)) key = key.substring(Prop.DBPREFIX.length());
       if (key.equalsIgnoreCase(MainProp.USER[0].toString())) {
         user = val;
       } else if (key.equalsIgnoreCase(MainProp.PASSWORD[0].toString())) {
         pass = val;
       }
     }
   } catch (final IOException ex) {
     throw new ServletException(ex);
   }
 }
  /**
   * Initializes the servlet context, based on the servlet context. Parses all context parameters
   * and passes them on to the database context.
   *
   * @param sc servlet context
   * @throws IOException I/O exception
   */
  static synchronized void init(final ServletContext sc) throws IOException {
    // skip process if context has already been initialized
    if (context != null) return;

    // set servlet path as home directory
    final String path = sc.getRealPath("/");
    System.setProperty(Prop.PATH, path);

    // parse all context parameters
    final HashMap<String, String> map = new HashMap<String, String>();
    // store default web root
    map.put(MainProp.HTTPPATH[0].toString(), path);

    final Enumeration<?> en = sc.getInitParameterNames();
    while (en.hasMoreElements()) {
      final String key = en.nextElement().toString();
      if (!key.startsWith(Prop.DBPREFIX)) continue;

      // only consider parameters that start with "org.basex."
      String val = sc.getInitParameter(key);
      if (eq(key, DBUSER, DBPASS, DBMODE, DBVERBOSE)) {
        // store servlet-specific parameters as system properties
        System.setProperty(key, val);
      } else {
        // prefix relative paths with absolute servlet path
        if (key.endsWith("path") && !new File(val).isAbsolute()) {
          val = path + File.separator + val;
        }
        // store remaining parameters (without project prefix) in map
        map.put(key.substring(Prop.DBPREFIX.length()).toUpperCase(Locale.ENGLISH), val);
      }
    }
    context = new Context(map);

    if (SERVER.equals(System.getProperty(DBMODE))) {
      new BaseXServer(context);
    } else {
      context.log = new Log(context);
    }
  }
Exemple #3
0
 @Override
 public void init(final ServletConfig config) throws ServletException {
   super.init(config);
   try {
     HTTPContext.init(config.getServletContext());
     final Enumeration<String> en = config.getInitParameterNames();
     while (en.hasMoreElements()) {
       String key = en.nextElement().toLowerCase(Locale.ENGLISH);
       final String val = config.getInitParameter(key);
       if (key.startsWith(Prop.DBPREFIX)) key = key.substring(Prop.DBPREFIX.length());
       if (key.equalsIgnoreCase(StaticOptions.USER.name())) {
         username = val;
       } else if (key.equalsIgnoreCase(StaticOptions.PASSWORD.name())) {
         password = val;
       } else if (key.equalsIgnoreCase(StaticOptions.AUTHMETHOD.name())) {
         auth = AuthMethod.valueOf(val);
       }
     }
   } catch (final IOException ex) {
     throw new ServletException(ex);
   }
 }