/**
   * Saves the ServerInfo Registry if the current configuration allows a persistant Registry !
   *
   * <p>By default this is false, but when MyVle is initialized by the VBrowser the persistant
   * ServerInfo Registry will be enabled.
   */
  public void save() {
    // Check new Configuration Manager !
    ConfigManager confMan = this.context.getConfigManager();

    if (confMan.getUsePersistantUserConfiguration() == false) return;

    VRL loc = confMan.getServerRegistryLocation();

    // is synchronized will return consistant list of configs

    ArrayList<AttributeSet> sets = this.getInfoAttrSets();
    // ResourceLoader loader=new ResourceLoader(context);

    XMLData xmlifier = new XMLData();
    xmlifier.setVAttributeElementName("vlet:ServerInfoProperty");
    xmlifier.setVAttributeSetElementName("vlet:ServerInfo");
    // xmlifier.setPersistanteNodeElementName("vlet:ServerInfo2"); // No
    // Nodes!

    try {
      // bootstrap warning: use default ResourceLoader here: VRS might not be initialized!
      ResourceLoader writer = new ResourceLoader();
      String xmlString =
          xmlifier.createXMLString(XML_SERVER_CONFIG_HEADER_TAG, sets, XML_SERVER_CONFIG_HEADER);
      writer.writeTextTo(loc.toURI(), xmlString);
      this.isSaved = true;
    } catch (Exception e) {
      // check persistant user configuration:
      logger.logException(ClassLogger.ERROR, e, "Couldn't save ServerInfo registry to:%s\n", loc);
      // but continue!
    }
  }
  /**
   * Load saved server configuration.
   *
   * <p>Currently when MyVLe object is initialized the ServerInfoRegistry will be loaded.
   */
  protected void load() throws VrsException {
    logger.debugPrintf(">>> load() <<<\n");

    //
    // use serverInfo as mutex !
    //
    synchronized (this.serverInfos) {
      // Use new Configuration Manager
      ConfigManager confMan = this.context.getConfigManager();
      VRL loc = confMan.getServerRegistryLocation();

      // is synchronized will return consistant list of configs

      ArrayList<AttributeSet> sets = this.getInfoAttrSets();
      // No Context!
      ResourceLoader loader = new ResourceLoader();

      XMLData xmlifier = new XMLData();
      xmlifier.setVAttributeElementName("vlet:ServerInfoProperty");
      xmlifier.setVAttributeSetElementName("vlet:ServerInfo");

      InputStream inps;
      try {
        inps = loader.createInputStream(loc.toURL());
      } catch (IOException e) {
        throw new NestedIOException(e);
      } catch (Exception e) {
        throw new VRLSyntaxException(e);
      }

      sets = xmlifier.parseVAttributeSets(inps, XML_SERVER_CONFIG_HEADER_TAG);
      // for (VAttributeSet set:sets)
      // {
      // logger.debugPrintln(this,"Adding ServerInfo Set:"+set);
      // }

      // ===
      // Do not clear: just merge current with save ones !
      // serverInfos.clear();
      // ===
      for (AttributeSet set : sets) {
        ServerInfo info = new ServerInfo(context, set);
        logger.debugPrintf("Adding Server Config:%s\n", info);
        // actual store method:
        put(info);
      }

      this.isLoaded = true;
    }
  }
Beispiel #3
0
  public static synchronized IconProvider getDefault() {
    if (source == null) source = new JFrame();

    if (instance == null) instance = new IconProvider(source, ResourceLoader.getDefault());

    return instance;
  }
Beispiel #4
0
  /**
   * Find image and return it. Resolves URL string to absolute URL.
   *
   * @throws IOException if url is invalid
   */
  public Image getImage(String url) throws IOException {
    URL resolvedURL = resourceLoader.resolveUrl(null, url);

    if (resolvedURL == null) throw new IOException("Couldn't resolve url:" + url);

    return this.getImage(resolvedURL);
  }
Beispiel #5
0
  /** Read PROPRIATIARY: .ico file and return Icon Image */
  public BufferedImage getIcoImage(URL iconurl) throws IOException {
    try {
      InputStream inps = resourceLoader.createInputStream(iconurl);
      List<BufferedImage> icoImages = ICODecoder.read(inps);

      BufferedImage biggestImage = null;
      int biggestSize = 0;

      for (BufferedImage im : icoImages) {
        // use surface metrics to get 'biggest' image
        int size = im.getWidth() * im.getHeight();
        if (size > biggestSize) {
          biggestSize = size;
          biggestImage = im;
        }
      }

      try {
        inps.close();
      } catch (IOException e) {
      }
      ; // ignore

      return biggestImage;

    } catch (Exception e) {
      throw new IOException("Read error:" + iconurl, e);
    }
  }
Beispiel #6
0
  /**
   * Returns Icon or broken image icon. Creates ImageIcon directly from URL, works with animated
   * GIFs as the icon is not changed
   */
  public Icon createIconOrBroken(ClassLoader optClassLoader, String url) {
    logger.debugPrintf("createIconOrDefault:%s\n", url);
    // Find image and create icon. No Rendering!

    URL resolvedUrl = resourceLoader.resolveUrl(optClassLoader, url);

    Icon icon = null;
    if (resolvedUrl != null) icon = new ImageIcon(resolvedUrl);

    if (icon != null) return icon;

    logger.debugPrintf("Returning broken icon for:%s\n", url);
    return getBrokenIcon();
  }
Beispiel #7
0
  /**
   * Try to find a specified image, but do no throw an (IOL)Exception if it can't be found. Method
   * will return 'null' if the case an image can't be found.
   */
  public Image findImage(ClassLoader extraLoader, String iconURL) {
    URL resolvedurl = resourceLoader.resolveUrl(extraLoader, iconURL);

    // return url
    if (resolvedurl != null) {
      logger.debugPrintf("findIcon:found Icon:%s\n", resolvedurl);

      // Basic checks whether the icon is a valid icon ?
      try {
        Image image = loadImage(resolvedurl, true);

        if (image != null) {
          logger.debugPrintf("findIcon:returning non null icon:%s\n", resolvedurl);
          return image;
        }
      } catch (IOException e) {
        logger.logException(PLogger.DEBUG, e, "Exception when loading image:%s\n", iconURL);
      }
    }

    logger.warnPrintf("Couldn't find (icon) image:%s\n", iconURL);

    return null;
  }