Package org.geoserver.catalog

Examples of org.geoserver.catalog.StyleInfo


            l.getStyles().clear();
            for (int i = 0; i < styles.getLength(); i++) {
                Element e = (Element) styles.item(i);
                String styleName = pullStyleName(e);
                if (styleName != null) {
                    StyleInfo style = catalog.getStyleByName(workspace, styleName);
                    if (style != null) {
                        l.getStyles().add(style);
                    }
                }
            }
View Full Code Here


                    }
                }
            }
            @Override
            public void visit(LayerInfo layer) {
                StyleInfo style = layer.getDefaultStyle();
                if( style != null ){
                    try {
                        style.accept(this);
                    }
                    catch( Throwable t ){
                        LOG.log(Level.FINE,String.format("Trouble checking layer %s for icon use:%s", layer.getName(),t));
                    }
                }
                else {
                    LOG.fine(String.format("Layer %s has no default style", layer.getName()));
                }
            }
            @Override
            public void visit(StyleInfo s) {
                Style style = null;
                try {
                    style = s.getStyle();
                } catch (IOException e) {
                    LOG.log(Level.FINE,"Unable to access style "+s.getName()+":"+e,e);
                }       
                if( style != null ){
                    style.accept(new StyleAdaptor() {
                        public Object visit(OnLineResource resource, Object data) {
                            try {
                                URI uri = resource.getLinkage();
                                if (uri != null) {
                                    String path = uri.toString();
View Full Code Here

            throw new UnsupportedOperationException("Copy for non vector/raster layer currently unsupported");
        }
    }

    StyleInfo copyStyle(LayerInfo l, WorkspaceInfo ws, Catalog cat) throws IOException {
        StyleInfo orig = l.getDefaultStyle();
        StyleInfo dup = cat.getFactory().createStyle();

        new CatalogBuilder(cat).updateStyle(dup, orig);
        dup.setWorkspace(ws);

        // find a unique name for the style
        String name = findUniqueStyleName(l.getName(), ws, cat);
        dup.setName(name);

        // update it's file name
        dup.setFilename(name + "." + FilenameUtils.getExtension(orig.getFilename()));

        // copy over the style contents
        try (
            BufferedReader reader = cat.getResourcePool().readStyle(orig);
        ) {
View Full Code Here

        return dup;
    }

    String findUniqueStyleName(String name, WorkspaceInfo ws, Catalog cat) {
        StyleInfo style = cat.getStyleByName(ws, name);
        if (style == null) {
            return name;
        }

        String styleName = null;
View Full Code Here

        Catalog cat = geoServer.getCatalog();
        WorkspaceInfo ws = findWorkspace(wsName, cat);
        LayerInfo l = findLayer(wsName, name, cat);

        StyleInfo s = l.getDefaultStyle();

        if (s == null) {
            // create one
            s = cat.getFactory().createStyle();
            s.setName(findUniqueStyleName(wsName, name, cat));
            s.setFilename(s.getName()+".yaml");
            s.setWorkspace(ws);
        }
        else {
            // we are converting from normal SLD?
            if (!YsldHandler.FORMAT.equalsIgnoreCase(s.getFormat())) {
                // reuse base file name
                String base = FilenameUtils.getBaseName(s.getFilename());
                s.setFilename(base + ".yaml");
            }
         }

        s.setFormat(YsldHandler.FORMAT);
        s.setFormatVersion(new Version("1.0.0"));

        // write out the resource
        OutputStream output = dataDir().style(s).out();
        try {
            try {
                IOUtils.copy(ByteSource.wrap(rawStyle).openStream(), output);
                output.flush();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        finally {
            IOUtils.closeQuietly(output);
        }

        if (s.getId() == null) {
            cat.add(s);
        }
        else {
            cat.save(s);
        }
View Full Code Here

    @RequestMapping(value="/{wsName}/{name}/style", method = RequestMethod.GET, produces = YsldHandler.MIMETYPE)
    public @ResponseBody Object style(@PathVariable String wsName, @PathVariable String name)
        throws IOException {
        Catalog cat = geoServer.getCatalog();
        LayerInfo l = findLayer(wsName, name, cat);
        StyleInfo s = l.getDefaultStyle();
        if (s == null) {
            throw new NotFoundException(String.format("Layer %s:%s has no default style", wsName, name));
        }

        // if the style is already stored in ySLD format just pull it directly, otherwise encode the style
        if (YsldHandler.FORMAT.equalsIgnoreCase(s.getFormat())) {
            return dataDir().style(s);
        }
        else {           
            GeoServerResourceLoader rl = cat.getResourceLoader();
            String path;
            if( s.getWorkspace() == null ){
                path = Paths.path("styles",s.getFilename());
            }
            else {
                path = Paths.path("workspaces",s.getWorkspace().getName(),"styles",s.getFilename());
            }
            final Resource r = rl.get(path);
           
            // Similar to s.getStyle() and GeoServerDataDirectory.parsedStyle(s)
            // But avoid resolving external graphics to absolute file references
            if ( r == null || r.getType() == Type.UNDEFINED ){
                throw new IOException( "No such resource: " + s.getFilename());
            }
            // Force use of unmodified URI, avoiding absolute file references
            ResourceLocator locator = new ResourceLocator(){
                public URL locateResource(String spec) {
                    return null;
                }
            };           
            StyleHandler handler = Styles.handler(s.getFormat());
            StyledLayerDescriptor sld = handler.parse(r, s.getFormatVersion(), locator, null);
           
            final Style style = Styles.style(sld); // extract 1st style
            return Styles.sld(style);              // encode in generated SLD
        }
    }
View Full Code Here

        Object obj = event.getSource();

        if (obj instanceof StyleInfo) {
            // TODO First pass only considers default styles,
            // which is all GWC will accept anyway
            StyleInfo si = (StyleInfo) obj;
            String styleName = si.getName();

            LinkedList<String> layerNameList = new LinkedList<String>();

            // First we collect all the layers that use this style
            Iterator<LayerInfo> liter = cat.getLayers().iterator();
            while (liter.hasNext()) {
                final LayerInfo li = liter.next();
                final StyleInfo defaultStyle = li.getDefaultStyle();
                if (defaultStyle != null && defaultStyle.getName().equals(styleName)) {
                    String prefixedName = li.getResource().getPrefixedName();
                    layerNameList.add(prefixedName);
                    //TODO: truncate/delete only the tileset associated to the style
                    gwc.truncate(prefixedName);
                }
            }

            // Now we check for layer groups that are affected
            Iterator<LayerGroupInfo> lgiter = cat.getLayerGroups().iterator();
            while (lgiter.hasNext()) {
                LayerGroupInfo lgi = lgiter.next();
                boolean truncate = false;

                // First we check for referenced to affected layers
                liter = lgi.getLayers().iterator();
                while (!truncate && liter.hasNext()) {
                    LayerInfo li = liter.next();
                    if (layerNameList.contains(li.getResource().getPrefixedName())) {
                        truncate = true;
                    }
                }

                // Finally we need to check whether the style is used explicitly
                if (!truncate) {
                    Iterator<StyleInfo> siiter = lgi.getStyles().iterator();
                    while (!truncate && siiter.hasNext()) {
                        StyleInfo si2 = siiter.next();
                        if (si2 != null && si2.getName().equals(si.getName())) {
                            truncate = true;
                        }
                    }
                }
View Full Code Here

                    Style style = oldStyles.isEmpty() ? null : (Style) oldStyles.get(i);

                    if (o instanceof LayerGroupInfo) {
                        LayerGroupInfo groupInfo = (LayerGroupInfo) o;
                        for (int j = 0; j < groupInfo.getStyles().size(); j++) {
                            StyleInfo si = groupInfo.getStyles().get(j);
                            if (si != null){
                                newStyles.add(si.getStyle());
                            } else {
                                LayerInfo layer = groupInfo.getLayers().get(j);
                                newStyles.add(getDefaultStyle(layer));
                            }
                        }
View Full Code Here

            NamedStyle namedStyle = CommonFactoryFinder.getStyleFactory(null)
                    .createNamedStyle();
            namedStyle.setName(null);
            return namedStyle;
        } else {
            StyleInfo defaultStyle = layer.getDefaultStyle();
            return defaultStyle.getStyle();
        }
    }
View Full Code Here

                    if (wms.getLayerGroupByName(layerName) != null) {
                        LayerGroupInfo group = wms.getLayerGroupByName(layerName);
                        for (int i = 0; i < group.getLayers().size(); i++) {
                            LayerInfo layer = group.getLayers().get(i);
                            layers.add(new MapLayerInfo(layer));
                            StyleInfo style = group.getStyles().get(i);
                            if (style != null) {
                                styles.add(style.getStyle());
                            } else {
                                styles.add(layer.getDefaultStyle().getStyle());
                            }
                        }
                        // move to the next named layer
View Full Code Here

TOP

Related Classes of org.geoserver.catalog.StyleInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.