/** * Serializes a style to configuration. * * @param info The configuration for the style. * @param style The style object. */ public void writeStyle(StyleInfo info, Style style) throws IOException { writeStyle(info, style, false); }
/** * Writes a raw style to configuration. * * @param style The configuration for the style. * @param in input stream representing the raw a style. */ public void writeStyle(StyleInfo style, InputStream in) throws IOException { synchronized (styleCache) { Resource styleFile = dataDir().style(style); writeStyle(in, styleFile); clear(style); } }
StyleInfo doCreateStyle(StyleHandler handler, StyleType styleType, ResourceInfo resource) throws IOException { // find a new style name String styleName = generateUniqueStyleName(resource); // variable replacement String styleData = generateStyle(handler, styleType, styleName); // let's store it StyleInfo style = catalog.getFactory().createStyle(); style.setName(styleName); style.setFilename(styleName + "." + handler.getFileExtension()); style.setFormat(handler.getFormat()); if (workspace != null) { style.setWorkspace(workspace); } catalog.getResourcePool().writeStyle(style, new ByteArrayInputStream(styleData.getBytes())); return style; }
StyleInfo backupStyle(StyleInfo s) throws IOException { StyleInfo backup = catalog.getFactory().createStyle(); new CatalogBuilder(catalog).updateStyle(backup, s); backup.setWorkspace(s.getWorkspace()); // find a unique name for the style String name = findUniqueStyleName( s.getWorkspace() == null ? null : s.getWorkspace().getName(), s.getName() + "_BACKUP"); backup.setName(name); // update it's file name backup.setFilename(name + "." + FilenameUtils.getExtension(s.getFilename())); // copy over the style contents try (BufferedReader reader = catalog.getResourcePool().readStyle(s)) { catalog.getResourcePool() .writeStyle(backup, new ByteArrayInputStream(IOUtils.toByteArray(reader))); } return backup; }
@Test public void testRasterStyle() throws Exception { ResourcePool rp = createNiceMock(ResourcePool.class); rp.writeStyle((StyleInfo) anyObject(), (InputStream) anyObject()); expectLastCall() .andAnswer(
@Test public void testGenericStyle() throws Exception { ResourcePool rp = createNiceMock(ResourcePool.class); rp.writeStyle((StyleInfo) anyObject(), (InputStream) anyObject()); expectLastCall() .andAnswer(
/** * Writes the content of an input stream to a style resource, without validation * * @param info Style info object, containing details about the style format and location * @param input The style contents * @throws IOException if there was an error persisting the style */ private void writeStyleRaw(StyleInfo info, InputStream input) throws IOException { try { catalog.getResourcePool().writeStyle(info, input); } finally { IOUtils.closeQuietly(input); } }
@Override protected void onStyleFormSubmit() { // write out the file and save name modifications try { StyleInfo style = (StyleInfo) styleForm.getModelObject(); Version version = Styles.findVersion(new ByteArrayInputStream(rawSLD.getBytes())); style.setSLDVersion(version); // write out the SLD try { getCatalog().getResourcePool().writeStyle(style, new ByteArrayInputStream(rawSLD.getBytes())); } catch (IOException e) { throw new WicketRuntimeException(e); } getCatalog().save(style); doReturn( StylePage.class ); } catch( Exception e ) { LOGGER.log(Level.SEVERE, "Error occurred saving the style", e); styleForm.error( e ); } }
StyleInfo doCreateStyle(StyleType styleType, ResourceInfo resource) throws IOException { // find a new style name String styleName = findUniqueStyleName(resource); // variable replacement String sld = loadSLDFromTemplate(styleType, ramp.next(), resource); // let's store it StyleInfo style = catalog.getFactory().createStyle(); style.setName(styleName); style.setFilename(styleName + ".sld"); catalog.getResourcePool().writeStyle(style, new ByteArrayInputStream(sld.getBytes())); //catalog.add(style); //catalog.getResourcePool().writeStyle(style, new ByteArrayInputStream(sld.getBytes())); return style; } String findUniqueStyleName(ResourceInfo resource) {
@Override protected void onStyleFormSubmit() { // add the style Catalog catalog = getCatalog(); StyleInfo s = (StyleInfo) styleForm.getModelObject(); // write out the SLD before creating the style try { if (s.getFilename() == null) { // TODO: check that this does not overriDe any existing files s.setFilename(s.getName() + ".sld"); } catalog.getResourcePool().writeStyle(s, new ByteArrayInputStream(rawSLD.getBytes())); } catch (IOException e) { throw new WicketRuntimeException(e); } // store in the catalog try { Version version = Styles.findVersion(new ByteArrayInputStream(rawSLD.getBytes())); s.setSLDVersion(version); getCatalog().add(s); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error occurred saving the style", e); error(e); return; } doReturn(StylePage.class); }
style.setName(styleName); style.setFilename(styleName + ".sld"); catalog.getResourcePool().writeStyle(style, new ByteArrayInputStream(sld.getBytes())); catalog.add(style);
catalog.getResourcePool().writeStyle(info, in);
&& SLDHandler.VERSION_10.equals(version)) { info.setFormat(handler.getFormat()); resourcePool.writeStyle(info, style, true); } else { info.setFormat(handler.getFormat());
catalog.getResourcePool().writeStyle( s, (Style) object, true );
catalog.getResourcePool().writeStyle(s, new ByteArrayInputStream(rawStyle.getBytes())); } catch (IOException e) { throw new WicketRuntimeException(e);
getCatalog() .getResourcePool() .writeStyle(stylePath, new ByteArrayInputStream(rawStyle.getBytes())); } catch (IOException e) { throw new WicketRuntimeException(e);
getCatalog() .getResourcePool() .writeStyle( styleInfo, JmsStylesTest.class.getResourceAsStream("/test_style_modified.sld"));
si.setWorkspace(catalog.getWorkspaceByName(layerConfiguration.getWorkspace())); si.setFilename(layerInfo.getName() + ".sld"); catalog.getResourcePool().writeStyle(si, style); catalog.add(si);
cat.getResourcePool().writeStyle(style, s); cat.save(style);
final YsldHandler handler = new YsldHandler(); ResourcePool rp = createNiceMock(ResourcePool.class); rp.writeStyle((StyleInfo) anyObject(), (InputStream) anyObject()); expectLastCall().andAnswer(new IAnswer<Void>() {