示例#1
0
  void createCssTemplate(String name) {
    try {
      Catalog catalog = getCatalog();
      if (catalog.getStyleByName(name) == null) {
        StyleInfo style = catalog.getFactory().createStyle();
        style.setName(name);
        style.setFilename(name + ".sld");
        catalog.add(style);

        File sld = findStyleFile(style.getFilename());
        if (sld == null || !sld.exists()) {
          catalog
              .getResourcePool()
              .writeStyle(
                  style, new ByteArrayInputStream(cssText2sldText(defaultStyle).getBytes()));
        }

        File css = findStyleFile(name + ".css");
        if (!css.exists()) {
          FileWriter writer = new FileWriter(css);
          writer.write(defaultStyle);
          writer.close();
        }
      }
    } catch (IOException ioe) {
      throw new WicketRuntimeException(ioe);
    }
  }
示例#2
0
  /** Copies a well known style out to the data directory and adds a catalog entry for it. */
  void initializeStyle(Catalog catalog, String styleName, String sld) throws IOException {

    // copy the file out to the data directory if necessary
    if (resourceLoader.find("styles", sld) == null) {
      FileUtils.copyURLToFile(
          GeoServerLoader.class.getResource(sld),
          new File(resourceLoader.findOrCreateDirectory("styles"), sld));
    }

    // create a style for it
    StyleInfo s = catalog.getFactory().createStyle();
    s.setName(styleName);
    s.setFilename(sld);
    catalog.add(s);
  }
示例#3
0
  /**
   * Adds a style to the test setup.
   *
   * <p>To set up the style a file named <tt>filename</tt> is copied from the classpath relative to
   * the <tt>scope</tt> parameter.
   *
   * @param name The name of the style.
   * @param filename The filename to copy from classpath.
   * @param scope Class from which to load sld resource from.
   */
  public void addStyle(String name, String filename, Class scope, Catalog catalog)
      throws IOException {
    File styles = catalog.getResourceLoader().findOrCreateDirectory(data, "styles");

    catalog.getResourceLoader().copyFromClassPath(filename, new File(styles, filename), scope);

    StyleInfo style = catalog.getStyleByName(name);
    if (style == null) {
      style = catalog.getFactory().createStyle();
      style.setName(name);
    }
    style.setFilename(filename);
    if (style.getId() == null) {
      catalog.add(style);
    } else {
      catalog.save(style);
    }
  }