コード例 #1
0
  private AbstractExtensionWrapper getCache(Class<AbstractExtension<?>> cls)
      throws StartException, InstantiationException, IllegalAccessException, IOException {
    String id = cls.getName().substring(27);
    // File cache = Application.getResource("tmp/extensioncache/" + id +
    // ".json");
    // AbstractExtensionWrapper cached = JSonStorage.restoreFrom(cache,
    // true, (byte[]) null, new TypeRef<AbstractExtensionWrapper>() {

    AbstractExtensionWrapper cached = cache.get(id);

    int v = AbstractExtension.readVersion(cls);
    if (cached != null) {
      cached._setClazz(cls);
      if (cached.getVersion() != v
          || !cached.getLng().equals(_JDT.getLanguage())
          || cached._getSettings() == null) {
        // update cache
        cached = null;
      }
    }
    if (cached == null) {
      Log.L.info("Update Cache " + cache);
      cached = AbstractExtensionWrapper.create(id, cls);
      cache.put(id, cached);
      cacheChanged = true;
    } else {
      cached._setClazz(cls);
    }
    return cached;
  }
コード例 #2
0
ファイル: Loc.java プロジェクト: amicom/my-project
    /**
     * Set-up this class by creating the HashMap for the key-string-pairs.
     * 
     * @param loc
     *            name of the localization file
     * @see Loc#parseLocalization(RFSFile)
     */
    public static void setLocale(String loc) {
        try {
            if (loc == null) {

                loc = Loc.CFG.get(Loc.PROPERTY_LOCALE, Loc.getDefaultLocale());
            }
            // first check filesystem
            final URL file = Loc.getResourceURL(loc);

            Loc.locale = loc;
            if (file != null) {
                // TODO

                Loc.CFG.put(Loc.PROPERTY_LOCALE, loc);
                Loc.parseLocalization(file);
            } else {
                Log.L.info("The language " + loc + " isn't available! Parsing default (" + Loc.FALLBACK_LOCALE + ".loc) one!");
                Loc.locale = Loc.getDefaultLocale();
                final String[] locs = Loc.locale.split("_");
                Locale.setDefault(new Locale(locs[0], locs[1]));
                Loc.parseLocalization(Loc.getResourceURL(Loc.FALLBACK_LOCALE));
            }
        } catch (final Exception e) {
            org.appwork.utils.logging.Log.exception(e);
        }
    }
コード例 #3
0
  public void validate(Login login, String url) {

    if (StringUtils.isEmpty(url)) {
      return;
    }
    AuthenticationInfo.Type type = null;
    if (url.startsWith("ftp")) {
      type = Type.FTP;
    } else if (url.startsWith("http")) {
      type = Type.HTTP;
    } else {
      Log.L.info("Unknown Protocoll: " + url);
      return;
    }

    String urlHost = Browser.getHost(url, true);
    for (AuthenticationInfo info : list) {
      if (!info.isEnabled()) {
        continue;
      }
      String authHost = info.getHostmask();
      if (info.getType().equals(type) && !StringUtils.isEmpty(authHost)) {
        boolean contains = false;
        if (authHost.length() > urlHost.length()) {
          /* hostMask of AuthenticationInfo is longer */
          contains = authHost.contains(urlHost);
        } else {
          /* hostMask of urlHost is longer */
          contains = urlHost.contains(authHost);
        }
        if (contains) {
          if (StringUtils.equals(info.getUsername(), login.getUsername())
              && StringUtils.equals(info.getPassword(), login.getPassword())) {
            info.setLastValidated(System.currentTimeMillis());
          }
        }
      }
    }
  }
コード例 #4
0
  public List<Login> getSortedLoginsList(String url) {
    if (StringUtils.isEmpty(url)) {
      return null;
    }
    AuthenticationInfo.Type type = null;
    if (url.startsWith("ftp")) {
      type = Type.FTP;
    } else if (url.startsWith("http")) {
      type = Type.HTTP;
    } else {
      Log.L.info("Unknown Protocoll: " + url);
      return null;
    }
    final ArrayList<AuthenticationInfo> possibleInfos = new ArrayList<AuthenticationInfo>();

    String urlHost = Browser.getHost(url, true);
    for (AuthenticationInfo info : list) {
      if (!info.isEnabled()) {
        continue;
      }
      final String authHost = info.getHostmask();
      if (info.getType().equals(type) && !StringUtils.isEmpty(authHost)) {
        boolean contains = false;
        if (authHost.length() > urlHost.length()) {
          /* hostMask of AuthenticationInfo is longer */
          contains = authHost.contains(urlHost);
        } else {
          /* hostMask of urlHost is longer */
          contains = urlHost.contains(authHost);
        }
        if (contains) {
          possibleInfos.add(info);
        }
      }
    }
    try {
      Collections.sort(
          possibleInfos,
          new Comparator<AuthenticationInfo>() {

            @Override
            public int compare(AuthenticationInfo o1, AuthenticationInfo o2) {
              int ret = Integer.compare(o2.getHostmask().length(), o1.getHostmask().length());
              if (ret == 0) {
                ret = Long.compare(o2.getLastValidated(), o1.getLastValidated());
              }
              if (ret == 0) {
                ret = Long.compare(o2.getCreated(), o1.getCreated());
              }
              return ret;
            }
          });

    } catch (Throwable e) {
      logger.log(e);
    }
    final ArrayList<Login> ret = new ArrayList<Login>();
    for (AuthenticationInfo info : possibleInfos) {
      ret.add(new Login(info.getUsername(), info.getPassword()));
    }
    return ret;
  }