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); } }
@Test public void testAddStyle() throws Exception { StyleInfo s = dao.getCatalog().getFactory().createStyle(); s.setName("blue"); dao.add(s); assertEquals(s, dao.getStyleByName("blue")); }
@Test public void testModifyStyle() throws Exception { testAddStyle(); StyleInfo st = dao.getStyleByName("blue"); st.setName("red"); dao.save(st); assertNull(dao.getStyleByName("blue")); assertNotNull(dao.getStyleByName("red")); }
/** 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); }
/** * 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); } }