@Override
  public void init() throws ServletException {
    super.init();
    ServletContext sc = getServletContext();

    // Read configuration file
    Properties config = Config.load(sc);

    // Call only once during initialization time of your application
    // @see http://issues.openkm.com/view.php?id=1577
    SLF4JBridgeHandler.install();

    // Get OpenKM version
    WarUtils.readAppVersion(sc);
    log.info("*** Application version: {} ***", WarUtils.getAppVersion());

    // Database initialize
    log.info("*** Hibernate initialize ***");
    HibernateUtil.getSessionFactory();

    // Create missing directories
    // NOTE: Should be executed AFTER Hibernate initialization because if in created mode
    // initialization will drop these directories
    createMissingDirs();

    try {
      // Initialize property groups
      log.info("*** Initialize property groups... ***");
      FormUtils.parsePropertyGroupsForms(Config.PROPERTY_GROUPS_XML);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
    }

    // Initialize language detection engine
    try {
      log.info("*** Initialize language detection engine... ***");
      DetectorFactory.loadProfile(Config.LANG_PROFILES_BASE);
    } catch (LangDetectException e) {
      log.error(e.getMessage(), e);
    }

    // Load database configuration
    Config.reload(sc, config);

    // Invoke start
    start();

    // Activity log
    UserActivity.log(Config.SYSTEM_USER, "MISC_OPENKM_START", null, null, null);
  }
Esempio n. 2
0
  /** Create XPath related to property groups. */
  private Object preparePropertyGroups(QueryParams params) throws IOException, ParseException {
    StringBuilder sb = new StringBuilder();

    if (!params.getProperties().isEmpty()) {
      Map<PropertyGroup, List<FormElement>> formsElements =
          FormUtils.parsePropertyGroupsForms(Config.PROPERTY_GROUPS_XML);

      for (Iterator<Entry<String, String>> it = params.getProperties().entrySet().iterator();
          it.hasNext(); ) {
        Entry<String, String> ent = it.next();
        FormElement fe = FormUtils.getFormElement(formsElements, ent.getKey());

        if (fe != null && ent.getValue() != null) {
          String valueTrimmed = ent.getValue().trim();

          if (!valueTrimmed.equals("")) {
            sb.append(" " + params.getOperator() + " ");

            if (fe instanceof Select) {
              sb.append("@" + ent.getKey() + "='" + escapeXPath(valueTrimmed) + "'");
            } else if (fe instanceof Input && ((Input) fe).getType().equals(Input.TYPE_DATE)) {
              String[] date = valueTrimmed.split(",");

              if (date.length == 2) {
                sb.append("@" + ent.getKey() + " >= '" + date[0] + "'");
                sb.append(" and ");
                sb.append("@" + ent.getKey() + " <= '" + date[1] + "'");
              }
            } else {
              sb.append(
                  "jcr:contains(@" + ent.getKey() + ",'" + escapeContains(valueTrimmed) + "')");
            }
          }
        }
      }
    }

    return sb.toString();
  }