private boolean isDefaultStyle(StyleInfo s) { return s.getWorkspace() == null && (StyleInfo.DEFAULT_POINT.equals(s.getName()) || StyleInfo.DEFAULT_LINE.equals(s.getName()) || StyleInfo.DEFAULT_POLYGON.equals(s.getName()) || StyleInfo.DEFAULT_RASTER.equals(s.getName()) || StyleInfo.DEFAULT_GENERIC.equals(s.getName())); }
/** * Given a {@link StyleInfo} and a user, returns it back if the user can access it. * * @return <code>null</code> if the user can't acess the style, otherwise the original style. */ protected StyleInfo checkAccess( Authentication user, StyleInfo style, MixedModeBehavior mixedModeBehavior) { if (style == null) return null; WrapperPolicy policy = buildWrapperPolicy(user, style, style.getName(), mixedModeBehavior); // if we don't need to hide it, then we can return it as is since it // can only provide metadata. if (policy.level == AccessLevel.HIDDEN) return null; else return style; }
private void addStyle(StyleInfo s) throws IOException { LOGGER.fine("Persisting style " + s.getName()); Resource xml = dd.config(s); persist(s, xml); }
private void renameStyle(StyleInfo s, String newName) throws IOException { LOGGER.fine("Renaming style " + s.getName() + " to " + newName); // rename xml configuration file Resource xml = dd.config(s); renameRes(xml, newName + ".xml"); }
private void removeStyle(StyleInfo s) throws IOException { LOGGER.fine("Removing style " + s.getName()); Resource xml = dd.config(s); rmRes(xml); }
/** * Retrieve the style configuration XML as a Resource * * @param c The style * @return A {@link Resource} */ public @Nonnull Resource config(StyleInfo s) { // special case for styles, if the file name (minus the suffix) matches the id of the style // and the suffix is xml (rather than sld) we need to avoid overwritting the actual // style file final String filename; if (s.getFilename() != null && s.getFilename().endsWith(".xml") && s.getFilename().startsWith(s.getName() + ".")) { // append a second .xml suffix filename = s.getName() + ".xml.xml"; } else { filename = s.getName() + ".xml"; } Resource r = get(s, filename); assert r != null; return r; }
/** * Imports all styles and loads them into the catalog * * @param factory * @param styles */ void importStyles(CatalogFactory factory, Map styles) { for (Iterator s = styles.entrySet().iterator(); s.hasNext(); ) { Map.Entry entry = (Map.Entry) s.next(); StyleInfo style = factory.createStyle(); style.setName((String) entry.getKey()); style.setFilename((String) entry.getValue()); catalog.add(style); LOGGER.info("Loaded style '" + style.getName() + "'"); } }
private void modifyStyle(StyleInfo s) throws IOException { LOGGER.fine("Persisting style " + s.getName()); Resource xml = dd.config(s); persist(s, xml); /* //save out sld File f = file(s); BufferedOutputStream out = new BufferedOutputStream( new FileOutputStream( f ) ); SLDTransformer tx = new SLDTransformer(); try { tx.transform( s.getSLD(),out ); out.flush(); } catch (TransformerException e) { throw (IOException) new IOException().initCause( e ); } finally { out.close(); } */ }
public StyleInfo getStyleByName(String name) { StyleInfo match = styles.findByName(new NameImpl(null, name), StyleInfo.class); if (match == null) { match = styles.findFirst(StyleInfo.class, s -> name.equals(s.getName())); } return wrapInModificationProxy(match, StyleInfo.class); }
public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof StyleInfo)) return false; final StyleInfo other = (StyleInfo) obj; if (filename == null) { if (other.getFilename() != null) return false; } else if (!filename.equals(other.getFilename())) return false; if (id == null) { if (other.getId() != null) return false; } else if (!id.equals(other.getId())) return false; if (name == null) { if (other.getName() != null) return false; } else if (!name.equals(other.getName())) return false; if (workspace == null) { if (other.getWorkspace() != null) return false; } else if (!workspace.equals(other.getWorkspace())) return false; if (format == null) { if (other.getFormat() != null) return false; } else { if (!format.equals(other.getFormat())) return false; } if (languageVersion == null) { if (other.getFormatVersion() != null) return false; } else if (!languageVersion.equals(other.getFormatVersion())) return false; return true; }
protected void resolve(StyleInfo style) { setId(style); // resolve the workspace WorkspaceInfo ws = style.getWorkspace(); if (ws != null) { WorkspaceInfo resolved = ResolvingProxy.resolve(getCatalog(), ws); if (resolved != null) { resolved = unwrap(resolved); style.setWorkspace(resolved); } else { LOGGER.log( Level.INFO, "Failed to resolve workspace for style \"" + style.getName() + "\". This means the workspace has not yet been added to the catalog, keep the proxy around"); } } }
void loadStyles(Resource styles, Catalog catalog, XStreamPersister xp) throws IOException { Filter<Resource> styleFilter = r -> XML_FILTER.accept(r) && !Resources.exists(styles.get(r.name() + ".xml")); try (AsynchResourceIterator<byte[]> it = new AsynchResourceIterator<>(styles, styleFilter, r -> r.getContents())) { while (it.hasNext()) { try { StyleInfo s = depersist(xp, it.next(), StyleInfo.class); catalog.add(s); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Loaded style '" + s.getName() + "'"); } } catch (Exception e) { LOGGER.log(Level.WARNING, "Failed to load style", e); } } } }
public boolean hideStyle(StyleInfo style) { if (style.getWorkspace() == null) { // global style, hide it if a local workspace style shars the same name, ie overrides it if (LocalWorkspace.get() != null) { if (catalog.getStyleByName(LocalWorkspace.get(), style.getName()) != null) { return true; } } return false; } return hideWorkspace(style.getWorkspace()); }
private void renameStyle(StyleInfo s, String newName) throws IOException { // rename style definition file Resource style = dd.style(s); StyleHandler format = Styles.handler(s.getFormat()); Resource target = uniqueResource(style, newName, format.getFileExtension()); renameRes(style, target.name()); s.setFilename(target.name()); // rename generated sld if appropriate if (!SLDHandler.FORMAT.equals(format.getFormat())) { Resource sld = style.parent().get(FilenameUtils.getBaseName(style.name()) + ".sld"); if (sld.getType() == Type.RESOURCE) { LOGGER.fine("Renaming style resource " + s.getName() + " to " + newName); Resource generated = uniqueResource(sld, newName, "sld"); renameRes(sld, generated.name()); } } }
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 testGetStyleByName() { addStyle(); StyleInfo s2 = catalog.getStyleByName(s.getName()); assertNotNull(s2); assertNotSame(s, s2); assertEquals(s, s2); }
@Test public void testCascadeStyle() { Catalog catalog = getCatalog(); StyleInfo style = catalog.getStyleByName(LAKES.getLocalPart()); assertNotNull(style); new CascadeDeleteVisitor(catalog).visit(style); assertNull(catalog.getStyleByName(LAKES.getLocalPart())); LayerInfo layer = catalog.getLayerByName(getLayerId(LAKES)); assertEquals("polygon", layer.getDefaultStyle().getName()); } }
@Test public void testGenericStyle() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.GENERICENTITY.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.GENERICENTITY)); LayerInfo li = cb.buildLayer(fti); // check we assigned the generic style assertEquals("generic", li.getDefaultStyle().getName()); }
@Test public void testModifyStyle() { addStyle(); StyleInfo s2 = catalog.getStyleByName(s.getName()); s2.setName(null); s2.setFilename(null); StyleInfo s3 = catalog.getStyleByName(s.getName()); assertEquals(s, s3); try { catalog.save(s2); fail("setting name to null should fail"); } catch (Exception e) { } s2.setName("s2Name"); try { catalog.save(s2); fail("setting filename to null should fail"); } catch (Exception e) { } s2.setFilename("s2Filename"); catalog.save(s2); s3 = catalog.getStyleByName("styleName"); assertNull(s3); s3 = catalog.getStyleByName(s2.getName()); assertEquals(s2, s3); }