private void checkLayerGroupResourceIsInWorkspace(StyleInfo style, WorkspaceInfo ws) { if (style == null) return; if (style.getWorkspace() != null && !ws.equals(style.getWorkspace())) { throw new IllegalArgumentException( "Layer group within a workspace (" + ws.getName() + ") can not contain styles from other workspace: " + style.getWorkspace()); } }
/** * Retrieve a resource in the the configuration directory of a Resource. An empty path will * retrieve the directory itself. * * @param si The store * @return A {@link Resource} */ public @Nonnull Resource get(StyleInfo si, String... path) { WorkspaceInfo workspace = si != null ? si.getWorkspace() : null; final Resource r = getStyles(workspace, path); assert r != null; return r; }
/** * Checks if the provided style is visible in the current context. * * @param style the style to check, may be NULL * @return the style if visible, otherwise NULL */ private <T extends StyleInfo> T enforceStyleIsolation(T style) { if (style == null) { // nothing to do, the style is already NULL return null; } WorkspaceInfo workspace = style.getWorkspace(); // check if the style workspace is visible in this context return canSeeWorkspace(workspace) ? style : null; }
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())); }
public List<StyleInfo> getStylesByWorkspace(WorkspaceInfo workspace) { // TODO: support ANY_WORKSPACE? List<StyleInfo> matches; if (workspace == NO_WORKSPACE) { matches = styles.list(StyleInfo.class, s -> s.getWorkspace() == null); } else { WorkspaceInfo ws; if (workspace == null) { ws = getDefaultWorkspace(); } else { ws = workspace; } matches = styles.list(StyleInfo.class, s -> ws.equals(s.getWorkspace())); } return ModificationProxy.createList(matches, StyleInfo.class); }
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()); }
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; }
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; }
WorkspaceInfo ws = style.getWorkspace(); StyleInfo existing = getStyleByName(ws, style.getName()); if (existing != null && (isNew || !existing.getId().equals(style.getId()))) { WorkspaceInfo ews = existing.getWorkspace(); String msg = "Style named '" + style.getName() + "' already exists"; if (ews != null) { throw new IllegalArgumentException("Cannot rename default styles"); if (null != style.getWorkspace()) { throw new IllegalArgumentException( "Cannot change the workspace of default styles");
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"); } } }
/** * Retrieve the styled layer descriptor prepared for direct GeoTools use. All file references * have been made absolute. * * @param s The style * @return A {@link StyledLayerDescriptor} */ public @Nonnull StyledLayerDescriptor parsedSld(final StyleInfo s) throws IOException { final Resource styleResource = style(s); if (styleResource.getType() == Type.UNDEFINED) { throw new IOException( "No such resource: " + s.getFilename() + (s.getWorkspace() != null ? " in workspace " + s.getWorkspace() : "")); } File input = styleResource.file(); DefaultResourceLocator locator = new GeoServerResourceLocator(); locator.setSourceUrl(Resources.toURL(styleResource)); EntityResolver entityResolver = getEntityResolver(); final StyledLayerDescriptor sld = Styles.handler(s.getFormat()) .parse(input, s.getFormatVersion(), locator, getEntityResolver()); return sld; }
expect(s1.getWorkspace()).andReturn(ws1).anyTimes(); replay(s1); expect(s2.getWorkspace()).andReturn(ws2).anyTimes(); replay(s2);
@Test public void testCreateInWorkspace() throws Exception { ResourcePool rp = createNiceMock(ResourcePool.class); Catalog cat = createNiceMock(Catalog.class); expect(cat.getFactory()).andReturn(new CatalogFactoryImpl(null)).anyTimes(); expect(cat.getResourcePool()).andReturn(rp).anyTimes(); WorkspaceInfo ws = createNiceMock(WorkspaceInfo.class); FeatureTypeInfo ft = createNiceMock(FeatureTypeInfo.class); expect(ft.getName()).andReturn("foo").anyTimes(); replay(rp, ft, ws, cat); StyleGenerator gen = new StyleGenerator(cat); gen.setWorkspace(ws); SimpleFeatureType schema = DataUtilities.createType("foo", "geom:Point"); StyleInfo style = gen.createStyle(new SLDHandler(), ft, schema); assertNotNull(style); assertNotNull(style.getWorkspace()); }
@Test public void testWorkspaceStyle() throws Exception { Catalog catalog = new CatalogImpl(); CatalogFactory cFactory = catalog.getFactory(); WorkspaceInfo ws = cFactory.createWorkspace(); ws.setName("foo"); StyleInfo s1 = cFactory.createStyle(); s1.setName("bar"); s1.setFilename("bar.sld"); s1.setWorkspace(ws); ByteArrayOutputStream out = out(); persister.save(s1, out); ByteArrayInputStream in = in(out); StyleInfo s2 = persister.load(in, StyleInfo.class); assertEquals("bar", s2.getName()); assertNotNull(s2.getWorkspace()); assertEquals("foo", s2.getWorkspace().getId()); Document dom = dom(in(out)); assertEquals("style", dom.getDocumentElement().getNodeName()); catalog.add(ws); catalog.add(s2); // Make sure the catalog resolves the workspace assertEquals("foo", s2.getWorkspace().getName()); }
@Test public void testStyle() throws Exception { Catalog catalog = new CatalogImpl(); CatalogFactory cFactory = catalog.getFactory(); StyleInfo s1 = cFactory.createStyle(); s1.setName("foo"); s1.setFilename("foo.sld"); ByteArrayOutputStream out = out(); persister.save(s1, out); ByteArrayInputStream in = in(out); StyleInfo s2 = persister.load(in, StyleInfo.class); assertEquals(s1, s2); Document dom = dom(in(out)); assertEquals("style", dom.getDocumentElement().getNodeName()); catalog.add(s2); assertNull(s2.getWorkspace()); }
assertNotNull(style.getWorkspace());
StyleInfo style = gen.createStyle(new SLDHandler(), ft, schema); assertNotNull(style); assertNotNull(style.getWorkspace());
if (info instanceof StyleInfo) { limits = accessManager.getAccessLimits(user, (StyleInfo) info); ws = ((StyleInfo) info).getWorkspace(); } else { limits = accessManager.getAccessLimits(user, (LayerGroupInfo) info, containers);
/** * Gets a unique name for a style, considering the workspace definition, in the form * worspacename:stylename (or stylename if the style is global). * * @param styleInfo */ private String getStyleName(StyleInfo styleInfo) { return styleInfo.getWorkspace() != null ? (styleInfo.getWorkspace().getName() + ":" + styleInfo.getName()) : styleInfo.getName(); }
@Override protected Component getContents(String id) { return imagePanel = new ChooseImagePanel(id, styleModel.getObject().getWorkspace()); }