/** Populate the state object, if needed, concerning paging */
  protected void initState(SessionState state, VelocityPortlet portlet, JetspeedRunData rundata) {
    super.initState(state, portlet, rundata);

    if (state.getAttribute(STATE_PAGESIZE) == null) {
      state.setAttribute(STATE_PAGESIZE, new Integer(DEFAULT_PAGE_SIZE));
      PortletConfig config = portlet.getPortletConfig();

      try {
        Integer size = new Integer(config.getInitParameter(PARAM_PAGESIZE));
        if (size.intValue() <= 0) {
          size = new Integer(DEFAULT_PAGE_SIZE);
          if (Log.getLogger("chef").isDebugEnabled())
            Log.debug(
                "chef",
                this
                    + ".initState: size parameter invalid: "
                    + config.getInitParameter(PARAM_PAGESIZE));
        }
        state.setAttribute(STATE_PAGESIZE, size);
      } catch (Exception any) {
        if (Log.getLogger("chef").isDebugEnabled())
          Log.debug("chef", this + ".initState: size parameter invalid: " + any.toString());
        state.setAttribute(STATE_PAGESIZE, new Integer(DEFAULT_PAGE_SIZE));
      }
    }
  } // initState
Example #2
0
 public static RuntimeException generateException(
     Throwable e, MethodDeclaration methodDecl, ASTNode node) {
   String msg = generateExceptionMessage(methodDecl, node);
   J2JSCompiler.errorCount++;
   Log.getLogger().error(msg);
   return new RuntimeException(msg, e);
 }
Example #3
0
 static {
   properties = new Properties();
   try {
     properties.load(Utils.class.getClassLoader().getResourceAsStream(propertiesFile));
   } catch (Exception e) {
     J2JSCompiler.errorCount++;
     Log.getLogger().error("Could not read from classpath: " + propertiesFile);
     throw new RuntimeException(e);
   }
 }
Example #4
0
 /** Import the sqlite database schema */
 private static void importSQLiteSchema() {
   InputStream is = ClassLoader.class.getResourceAsStream(SQLite_Schema);
   if (is != null) {
     try {
       BufferedReader bf = new BufferedReader(new InputStreamReader(is));
       String sql = "";
       String line = "";
       while (true) {
         line = bf.readLine();
         if (line == null) {
           break;
         }
         line = line.trim();
         if (line.endsWith(";")) {
           sql += line;
           Connection conn = DatabaseConnection.getInstance().getConnection();
           Statement stat = conn.createStatement();
           Log.getLogger().log(Level.FINEST, "import table {0}", sql);
           stat.executeUpdate(sql);
           sql = "";
           line = "";
         } else {
           sql += line;
         }
       }
     } catch (FileNotFoundException e) {
       Log.getLogger().log(Level.WARNING, "schema file missing: " + e.getMessage(), e);
     } catch (SQLException e) {
       Log.getLogger().log(Level.WARNING, "schema file import failed: " + e.getMessage(), e);
     } catch (IOException e) {
       Log.getLogger().log(Level.WARNING, "schema file ioerror: " + e.getMessage(), e);
     }
   } else {
     Log.getLogger().log(Level.WARNING, "schema file missing");
   }
 }
Example #5
0
  // initialization
  static {
    Properties p = new Properties();
    File f = new File("redpin.properties");
    if (f.exists()) {
      try {
        FileInputStream reader = new FileInputStream(f);
        p.load(reader);

        try {
          ServerPort = new Integer(p.getProperty("port", ServerPort.toString()));
        } catch (NumberFormatException e) {
        }

        ImageUploadPath = p.getProperty("image.upload.path", ImageUploadPath);
        if (ImageUploadPath.charAt(ImageUploadPath.length() - 1) == '/') {
          ImageUploadPath = ImageUploadPath.substring(0, ImageUploadPath.length() - 1);
        }
        LogFile = p.getProperty("log.file", LogFile);

        String format = "";
        try {
          format = p.getProperty("log.format", LogFormat.name());
          LogFormat = LoggerFormat.valueOf(format.toUpperCase());

        } catch (IllegalArgumentException e) {
          Log.getLogger()
              .log(Level.CONFIG, "No such log format type " + format + ": " + e.getMessage(), e);
        }

        String level = "";
        try {
          level = p.getProperty("log.level", LogLevel.getName());
          LogLevel = Level.parse(level);
        } catch (IllegalArgumentException e) {
          Log.getLogger()
              .log(Level.CONFIG, "No such log format type " + format + ": " + e.getMessage(), e);
        }

        LogRequests =
            Boolean.valueOf(p.getProperty("requests.log", Boolean.valueOf(LogRequests).toString()));
        LogRequestPath = p.getProperty("requests.log.path", LogRequestPath);
        if (LogRequestPath.charAt(LogRequestPath.length() - 1) == '/') {
          LogRequestPath = LogRequestPath.substring(0, LogRequestPath.length() - 1);
        }

        if (LogRequests) {
          File lrp = new File(LogRequestPath);
          if (!lrp.exists()) {
            lrp.mkdirs();
          }
        }

        String type = "";
        try {
          type = p.getProperty("db.type", DatabaseType.name());
          DatabaseType = DatabaseTypes.valueOf(type.toUpperCase());

        } catch (IllegalArgumentException e) {
          Log.getLogger()
              .log(Level.CONFIG, "No such database type " + type + ": " + e.getMessage(), e);
        }

        if (DatabaseType == DatabaseTypes.SQLITE) {
          DatabaseLocation = p.getProperty("db.location", DatabaseLocation);
          DatabaseDriver = "org.sqlite.JDBC";
        }

        if (DatabaseType == DatabaseTypes.MYSQL) {
          DatabaseDriver = "com.mysql.jdbc.Driver";
          DatabaseLocation = p.getProperty("db.location", DatabaseLocation);
        }

        if (DatabaseType == DatabaseTypes.POSTGRESQL) {
          DatabaseDriver = "org.postgresql.Driver";
          DatabaseLocation = p.getProperty("db.location", DatabaseLocation);
        }

        LibSVMDirectory = p.getProperty("svm.libdir", LibSVMDirectory);
        try {
          SVMTrainRate = Long.parseLong(p.getProperty("svm.trainrate", SVMTrainRate + ""));
        } catch (NumberFormatException e) {
        }

      } catch (Exception e) {
        Log.getLogger().log(Level.SEVERE, "Config initialization failed: " + e.getMessage(), e);
        e.printStackTrace();
      }
    }

    File dir = new File(ImageUploadPath);
    if (!dir.exists()) {
      if (!dir.mkdirs()) {
        Log.getLogger().log(Level.WARNING, "Image Upload Path could not be created");
      } else {
        Log.getLogger()
            .log(Level.FINE, "No image upload dir found, now creating {0}", ImageUploadPath);
      }
    }

    if ((DatabaseType == DatabaseTypes.SQLITE) && (!new File(DatabaseLocation).exists())) {
      Log.getLogger().fine("No database file found, now importing database schema");
      importSQLiteSchema();
    }

    dir = new File(LibSVMDirectory);
    if (dir.isDirectory() && dir.exists()) {

      File trainPl = new File(SVMSupport.TRAIN_SCRIPT);
      try {
        if (!trainPl.exists()) {
          try (Writer w = new FileWriter(trainPl)) {
            w.write(generateTrainScript(LibSVMDirectory));
            w.flush();
          }
          trainPl.setExecutable(true);
        }
      } catch (Exception e) {
        Log.getLogger().fine("could not create " + SVMSupport.TRAIN_SCRIPT);
      }
    }
  }