private synchronized void updateFilter() {

        String filterRegex = this.getText();
        boolean enabled = filterRegex.length() > 0;

        if (enabled) {

            java.util.List<Pattern> list = new ArrayList<Pattern>();
            try {
                if (JsonConfig.create(GeneralSettings.class).isFilterRegex()) {
                    list.add(LinkgrabberFilterRuleWrapper.createPattern(filterRegex, true));
                } else {
                    String[] filters = filterRegex.split("\\|");
                    for (String filter : filters) {
                        list.add(LinkgrabberFilterRuleWrapper.createPattern(filter, false));
                    }

                }
                filterPatterns = list;

                updaterFilter();

            } catch (final Throwable e) {
                Log.exception(e);
            }
        } else {
            filterPatterns = null;
            updaterFilter();
        }
        updaterFilter();

    }
示例#2
0
文件: IconIO.java 项目: munix/jdget
 public static BufferedImage getImage(final URL resource, final boolean allowDummy) {
   if (resource != null) {
     InputStream is = null;
     /*
      * workaround for
      * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7166379
      */
     /*
      * http://stackoverflow.com/questions/10441276/jdk-1-7-too-many-open-
      * files-due-to-posix-semaphores
      */
     try {
       is = resource.openStream();
       final BufferedImage ret = ImageIO.read(is);
       if (ret != null) {
         return ret;
       }
     } catch (final IOException e) {
       Log.exception(Level.WARNING, e);
     } finally {
       try {
         is.close();
       } catch (final Throwable e) {
       }
     }
   }
   if (allowDummy) {
     return ImageProvider.createIcon("DUMMY", 48, 48);
   }
   return null;
 }
示例#3
0
    /**
     * 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);
        }
    }
示例#4
0
 /**
  * Sets the column visible or invisible. This information is stored in database interface for
  * cross session use.
  *
  * @param column
  * @param visible
  */
 public void setVisible(final int column, final boolean visible) {
   final ExtColumn<E> col = this.getExtColumn(column);
   try {
     JSonStorage.getStorage("ExtTableModel_" + this.modelID)
         .put("VISABLE_COL_" + col.getName(), visible);
   } catch (final Exception e) {
     Log.exception(e);
   }
 }
示例#5
0
 /**
  * checks if this column is allowed to be hidden
  *
  * @param column
  * @return
  */
 public boolean isHidable(final int column) {
   final ExtColumn<E> col = this.getExtColumn(column);
   try {
     return col.isHidable();
   } catch (final Exception e) {
     Log.exception(e);
     return true;
   }
 }
示例#6
0
 /**
  * Retrieves visible information form database interface to determine if the column is visible or
  * not
  *
  * @param column
  * @return
  */
 public boolean isVisible(final int column) {
   final ExtColumn<E> col = this.getExtColumn(column);
   try {
     return JSonStorage.getStorage("ExtTableModel_" + this.modelID)
         .get("VISABLE_COL_" + col.getName(), col.isDefaultVisible());
   } catch (final Exception e) {
     Log.exception(e);
     return true;
   }
 }
示例#7
0
  /**
   * Sorts the model with the column's rowsorter
   *
   * @param column
   * @param sortOrderToggle
   */
  public void sort(final ExtColumn<E> column, final boolean sortOrderToggle) {
    this.sortColumn = column;
    this.sortOrderToggle = sortOrderToggle;

    try {
      JSonStorage.getStorage("ExtTableModel_" + this.modelID).put("SORTCOLUMN", column.getID());
      JSonStorage.getStorage("ExtTableModel_" + this.modelID).put("SORTORDER", sortOrderToggle);
    } catch (final Exception e) {
      Log.exception(e);
    }
    Collections.sort(this.getTableData(), column.getRowSorter(sortOrderToggle));
  }
示例#8
0
    /**
     * Creates a HashMap with the data obtained from the localization file. <br>
     * <b>Warning:</b> Overwrites any previously created HashMap
     * 
     * @param file
     *            {@link RFSFile} object to the localization file
     * @throws IllegalArgumentException
     *             if the parameter is null or doesn't exist
     * @see Loc#DATA
     */
    public static void parseLocalization(final URL file) throws IllegalArgumentException {
        if (file == null) { throw new IllegalArgumentException(); }

        if (Loc.DATA != null) {
            Log.L.finer("Previous HashMap will be overwritten!");
        }
        Loc.DATA = new HashMap<Integer, String>();

        BufferedReader reader = null;
        InputStreamReader isr = null;
        InputStream fis = null;
        try {
            reader = new BufferedReader(isr = new InputStreamReader(fis = file.openStream(), "UTF8"));

            String line;
            String key;
            String value;
            int split;
            while ((line = reader.readLine()) != null) {
                if (line.startsWith("#")) {
                    continue;
                }

                if ((split = line.indexOf('=')) <= 0) {
                    continue;
                }

                key = line.substring(0, split).toLowerCase().trim();
                value = line.substring(split + 1).trim();
                value = value.replace("\\n", "\n").replace("\\r", "\r");

                Loc.DATA.put(key.hashCode(), value);
            }
        } catch (final FileNotFoundException e) {
            throw new IllegalArgumentException(e);
        } catch (final Exception e) {
            org.appwork.utils.logging.Log.exception(e);
        } finally {
            try {
                reader.close();
            } catch (final Throwable e) {
            }
            try {
                isr.close();
            } catch (final Throwable e) {
            }
            try {
                fis.close();
            } catch (final Throwable e) {
            }
        }
    }
示例#9
0
 @SuppressWarnings("unchecked")
 public <T extends ExtColumn<E>> T getColumnByClass(final Class<T> clazz) {
   try {
     for (final ExtColumn<?> column : this.columns) {
       if (column.getClass().equals(clazz)) {
         return (T) column;
       }
     }
   } catch (final Exception e) {
     Log.exception(e);
   }
   return null;
 }
    public CompiledFiletypeFilter(FiletypeFilter filetypeFilter) {
        java.util.List<Pattern> list = new ArrayList<Pattern>();
        if (filetypeFilter.isArchivesEnabled()) {
            for (ArchiveExtensions ae : ArchiveExtensions.values()) {
                list.add(ae.getPattern());
            }
        }

        if (filetypeFilter.isAudioFilesEnabled()) {
            for (AudioExtensions ae : AudioExtensions.values()) {
                list.add(ae.getPattern());
            }
        }

        if (filetypeFilter.isImagesEnabled()) {
            for (ImageExtensions ae : ImageExtensions.values()) {
                list.add(ae.getPattern());
            }
        }
        if (filetypeFilter.isVideoFilesEnabled()) {
            for (VideoExtensions ae : VideoExtensions.values()) {
                list.add(ae.getPattern());
            }
        }
        try {
            if (filetypeFilter.getCustoms() != null) {
                if (filetypeFilter.isUseRegex()) {
                    list.add(Pattern.compile(filetypeFilter.getCustoms(), Pattern.DOTALL | Pattern.CASE_INSENSITIVE));
                } else {

                    for (String s : filetypeFilter.getCustoms().split("\\,")) {
                        list.add(LinkgrabberFilterRuleWrapper.createPattern(s, false));
                    }
                }
            }
        } catch (final IllegalArgumentException e) {
            /* custom regex may contain errors */
            Log.exception(e);
        }
        matchType = filetypeFilter.getMatchType();
        this.list = list.toArray(new Pattern[list.size()]);
    }
示例#11
0
  /**
   * converts from old subconfig to new JSOnstorage
   *
   * @param string
   * @param ret
   */
  private static void convert(String string, JSonWrapper ret) {
    SubConfiguration subConfig = SubConfiguration.getConfig(string);
    HashMap<String, Object> props = subConfig.getProperties();
    if (props != null && props.size() > 0) {
      Entry<String, Object> next;
      for (Iterator<Entry<String, Object>> it = props.entrySet().iterator(); it.hasNext(); ) {
        next = it.next();
        try {
          ret.setProperty(next.getKey(), next.getValue());
        } catch (Throwable e) {
          Log.exception(e);
        }
        it.remove();
      }

      subConfig.setProperties(props);
      subConfig.save();
      ret.save();
    }
  }
示例#12
0
  public Object getProperty(final String key, final Object def) {
    try {
      if (storage.hasProperty(key)) {
        return this.storage.get(key, (String) null);
      } else if (getObjectKey(key).exists()) {

        if (def != null) {
          return JSonStorage.restoreFromFile(getObjectKey(key), def);
        } else {
          TypeRef<?> ref = getType(key);
          System.out.println("Read " + path + "." + key + (plain ? ".json" : ".ejs"));
          if (ref == null) {
            Log.exception(new Exception(path + ".json." + key + " type missing"));
          }
          return JSonStorage.restoreFrom(getObjectKey(key), true, null, ref, null);
        }
      }
    } catch (Throwable e) {
      e.printStackTrace();
    }
    return def;
  }
  @SuppressWarnings("unchecked")
  private void loadJared() {

    File[] addons =
        Application.getResource("extensions")
            .listFiles(
                new FilenameFilter() {
                  public boolean accept(File dir, String name) {
                    return name.endsWith(".jar");
                  }
                });
    if (addons == null) return;
    main:
    for (File jar : addons) {
      try {
        URLClassLoader cl = new URLClassLoader(new URL[] {jar.toURI().toURL()});

        final Enumeration<URL> urls =
            cl.getResources(AbstractExtension.class.getPackage().getName().replace('.', '/'));
        URL url;
        while (urls.hasMoreElements()) {
          url = urls.nextElement();
          if (url.getProtocol().equalsIgnoreCase("jar")) {
            // jarred addon (JAR)
            File jarFile =
                new File(
                    new URL(url.toString().substring(4, url.toString().lastIndexOf('!'))).toURI());
            final JarInputStream jis = new JarInputStream(new FileInputStream(jarFile));
            JarEntry e;

            while ((e = jis.getNextJarEntry()) != null) {
              try {
                Matcher matcher =
                    Pattern.compile(
                            Pattern.quote(
                                    AbstractExtension.class
                                        .getPackage()
                                        .getName()
                                        .replace('.', '/'))
                                + "/(\\w+)/(\\w+Extension)\\.class")
                        .matcher(e.getName());
                if (matcher.find()) {
                  String pkg = matcher.group(1);
                  String clazzName = matcher.group(2);
                  Class<?> clazz =
                      cl.loadClass(
                          AbstractExtension.class.getPackage().getName()
                              + "."
                              + pkg
                              + "."
                              + clazzName);

                  if (AbstractExtension.class.isAssignableFrom(clazz)) {

                    initModule((Class<AbstractExtension<?>>) clazz);
                    continue main;
                  }
                }
              } catch (Throwable e1) {
                Log.exception(e1);
              }
            }
          }
        }

      } catch (Throwable e) {
        Log.exception(e);
      }
    }
  }
  @SuppressWarnings("unchecked")
  private void loadUnpacked() {
    URL ret = getClass().getResource("/");
    File root;
    if (ret.getProtocol().equalsIgnoreCase("file")) {
      try {
        root = new File(ret.toURI());
      } catch (URISyntaxException e) {
        Log.exception(e);
        Log.L.finer("Did not load unpacked Extensions from " + ret);
        return;
      }
    } else {
      Log.L.finer("Did not load unpacked Extensions from " + ret);
      return;
    }
    root = new File(root, AbstractExtension.class.getPackage().getName().replace('.', '/'));
    Log.L.finer("Load Extensions from: " + root.getAbsolutePath());
    File[] folders =
        root.listFiles(
            new FileFilter() {

              public boolean accept(File pathname) {
                return pathname.isDirectory();
              }
            });
    ClassLoader cl = getClass().getClassLoader();
    main:
    for (File f : folders) {
      File[] modules =
          f.listFiles(
              new FilenameFilter() {

                public boolean accept(File dir, String name) {
                  return name.endsWith("Extension.class");
                }
              });
      boolean loaded = false;
      for (File module : modules) {

        Class<?> cls;
        try {
          cls =
              cl.loadClass(
                  AbstractExtension.class.getPackage().getName()
                      + "."
                      + module.getParentFile().getName()
                      + "."
                      + module.getName().substring(0, module.getName().length() - 6));

          if (AbstractExtension.class.isAssignableFrom(cls)) {
            loaded = true;
            initModule((Class<AbstractExtension<?>>) cls);
            continue main;
          }
        } catch (IllegalArgumentException e) {
          Log.L.warning("Did not init Extension " + module + " : " + e.getMessage());
        } catch (Throwable e) {
          Log.exception(e);
          Dialog.getInstance().showExceptionDialog("Error", e.getMessage(), e);
        }
      }
      if (!loaded) {
        Log.L.warning("Could not load any Extension Module from " + f);
      }
    }
  }
示例#15
0
    /**
     * @return
     */
    public static String[] getLocales() {
        final java.util.List<String> ret = new ArrayList<String>();

        // first look out for all translations in filesystem
        String[] files;

        files = Application.getResource("languages/").list(new FilenameFilter() {

            public boolean accept(final File dir, final String name) {
                return name.endsWith(".loc");

            }

        });

        if (files != null) {
            for (final String file : files) {
                ret.add(file.substring(0, file.length() - 4));
            }
        }

        // Search in jar:
        try {
            URL url = Application.getRessourceURL("languages/");
            if (url != null) {
                Enumeration<URL> resources;

                resources = Thread.currentThread().getContextClassLoader().getResources("languages/");

                while (resources.hasMoreElements()) {

                    url = resources.nextElement();
                    if (url.getProtocol().equalsIgnoreCase("jar")) {
                        final String path = url.getPath();
                        final int index = path.lastIndexOf('!');

                        final String jarPath = path.substring(0, index);
                        final String internPath = path.substring(index + 2);

                        final JarInputStream jarFile = new JarInputStream(new FileInputStream(new File(new URL(jarPath).toURI())));
                        JarEntry e;

                        String jarName;
                        while ((e = jarFile.getNextJarEntry()) != null) {
                            jarName = e.getName();
                            if (jarName.startsWith(internPath) && jarName.endsWith(".loc")) {
                                String filename = new File(jarName).getName();
                                filename = filename.substring(0, filename.length() - 4);
                                ret.remove(filename);
                                ret.add(filename);
                            }
                        }
                    } else {
                        files = new File(url.toURI()).list(new FilenameFilter() {

                            public boolean accept(final File dir, final String name) {
                                return name.endsWith(".loc");

                            }

                        });

                        if (files != null) {
                            for (final String file : files) {
                                ret.add(file.substring(0, file.length() - 4));
                            }
                        }
                    }
                }
            }
        } catch (final Exception e) {
            Log.exception(e);
        }
        return ret.toArray(new String[] {});

    }