Examples of StyleInfo


Examples of org.geoserver.catalog.StyleInfo

    }

    public LayerInfo update(LayerInfo entity) {
        if (entity.getDefaultStyle() != null && entity.getDefaultStyle().getId() != null) {
            LOGGER.info("Refreshing style in layer " + entity + " --> style id: " + entity.getDefaultStyle().getId());
            StyleInfo style = (StyleInfo)entityManager.find(HibMapper.mapHibernableClass(StyleInfo.class), entity.getDefaultStyle().getId());
            entity.setDefaultStyle(style);
        }
       
        return super.merge(entity);
    }
View Full Code Here

Examples of org.geoserver.catalog.StyleInfo

    @Override
    protected Object handleObjectGet() {
        String style = getAttribute("style");
       
        LOGGER.fine( "GET style " + style );
        StyleInfo sinfo = catalog.getStyleByName( style );
       
        //check the format, if specified as sld, return the sld itself
        DataFormat format = getFormatGet();
        if ( format instanceof SLDFormat ) {
            try {
                return sinfo.getStyle();
            }
            catch (IOException e) {
                throw new RestletException( "", Status.SERVER_ERROR_INTERNAL, e );
            }
        }
View Full Code Here

Examples of org.geoserver.catalog.StyleInfo

    @Override
    protected String handleObjectPost(Object object) throws Exception {
        String layer = getAttribute( "layer" );
       
        if ( object instanceof StyleInfo ) {
            StyleInfo style = (StyleInfo) object;
           
            if ( layer != null ) {
                StyleInfo existing = catalog.getStyleByName( style.getName() );
                if ( existing == null ) {
                    //TODO: add a new style to catalog
                    throw new RestletException( "No such style: " + style.getName(), Status.CLIENT_ERROR_NOT_FOUND );
                }
               
                LayerInfo l = catalog.getLayerByName( layer );
                l.getStyles().add( existing );
               
                //check for default
                String def = getRequest().getResourceRef().getQueryAsForm().getFirstValue("default");
                if ( "true".equals( def ) ) {
                    l.setDefaultStyle( existing );
                }
                catalog.save(l);
                LOGGER.info( "POST style " + style.getName() + " to layer " + layer);
            }
            else {
                catalog.add( style  );
                LOGGER.info( "POST style " + style.getName() );
            }

            return style.getName();
        }
        else if ( object instanceof Style ) {
            Style style = (Style) object;
           
            //figure out the name of the new style, first check if specified directly
            String name = getRequest().getResourceRef().getQueryAsForm().getFirstValue( "name");
           
            if ( name == null ) {
                //infer name from sld
                name = style.getName();
            }
           
            if ( name == null ) {
                throw new RestletException( "Style must have a name.", Status.CLIENT_ERROR_BAD_REQUEST );
            }
           
            //ensure that the style does not already exist
            if ( catalog.getStyleByName( name ) != null ) {
                throw new RestletException( "Style " + name + " already exists.", Status.CLIENT_ERROR_FORBIDDEN  );
            }
           
            //serialize the style out into the data directory
            GeoServerResourceLoader loader = catalog.getResourceLoader();
            File f;
            try {
                f = loader.find( "styles/" +  name + ".sld" );
            }
            catch (IOException e) {
                throw new RestletException( "Error looking up file", Status.SERVER_ERROR_INTERNAL, e );
            }
           
            if ( f != null ) {
                String msg = "SLD file " + name + ".sld already exists.";
                throw new RestletException( msg, Status.CLIENT_ERROR_FORBIDDEN);
            }
           
            //TODO: have the writing out of the style delegate to ResourcePool.writeStyle()
            try {
                f = loader.createFile( "styles/" + name + ".sld") ;
               
                //serialize the file to the styles directory
                BufferedOutputStream out = new BufferedOutputStream( new FileOutputStream ( f ) );
               
                SLDFormat format = new SLDFormat(true);
                format.toRepresentation(style).write(out);
               
                out.flush();
                out.close();
            }
            catch (IOException e) {
                throw new RestletException( "Error creating file", Status.SERVER_ERROR_INTERNAL, e );
            }
           
            //create a style info object
            StyleInfo sinfo = catalog.getFactory().createStyle();
            sinfo.setName( name );
            sinfo.setFilename( f.getName() );
            catalog.add( sinfo );
           
            LOGGER.info( "POST SLD " + name);
            return name;
        }
View Full Code Here

Examples of org.geoserver.catalog.StyleInfo

    @Override
    protected void handleObjectPut(Object object) throws Exception {
        String style = getAttribute("style");
       
        if ( object instanceof StyleInfo ) {
            StyleInfo s = (StyleInfo) object;
            StyleInfo original = catalog.getStyleByName( style );
    
            new CatalogBuilder( catalog ).updateStyle( original, s );
            catalog.save( original );
        }
        else if ( object instanceof Style ) {
            StyleInfo s = catalog.getStyleByName( style );
            catalog.getResourcePool().writeStyle( s, (Style) object, true );
        }
       
        LOGGER.info( "PUT style " + style);
    }
View Full Code Here

Examples of org.geoserver.catalog.StyleInfo

    }
   
    @Override
    protected void handleObjectDelete() throws Exception {
        String style = getAttribute("style");
        StyleInfo s = catalog.getStyleByName(style);
       
        //ensure that no layers reference the style
        List<LayerInfo> layers = catalog.getLayers(s);
        if ( !layers.isEmpty() ) {
            throw new RestletException( "Can't delete style referenced by existing layers.", Status.CLIENT_ERROR_FORBIDDEN );
View Full Code Here

Examples of org.geoserver.catalog.StyleInfo

            gt = GeometryType.POINT;
        }

        // find a new style name
        String styleName = featureType.getStore().getWorkspace().getName() + "_" + featureType.getName();
        StyleInfo style = catalog.getStyleByName(styleName);
        int i = 1;
        while(style != null) {
            styleName = featureType.getStore().getWorkspace().getName() + "_" + featureType.getName() + i;
            style = catalog.getStyleByName(styleName);
            i++;
        }
       
        // variable replacement
        String colorCode = Integer.toHexString(color.getRGB());
        colorCode = colorCode.substring(2, colorCode.length());
        String sld = TEMPLATES.get(gt).replace("${colorName}", colorName).replace(
                "${colorCode}", "#" + colorCode);

        // let's store it
        style = catalog.getFactory().createStyle();
        style.setName(styleName);
        style.setFilename(styleName + ".sld");
        catalog.add(style);
        catalog.getResourcePool().writeStyle(style, new ByteArrayInputStream(sld.getBytes()));

        return style;
    }
View Full Code Here

Examples of org.geoserver.catalog.StyleInfo

              
               // 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

Examples of org.geoserver.catalog.StyleInfo

       
        LayerInfo l = catalog.getFactory().createLayer();
        // l.setName("foo");
        l.setResource( catalog.getFeatureTypeByName( "bar", "foo") );
       
        StyleInfo s = catalog.getStyleByName( "foostyle");
        l.setDefaultStyle(s);
        catalog.add( l );
       
        assertTrue( f.exists() );
    }
View Full Code Here

Examples of org.geoserver.catalog.StyleInfo

       
        File f = new File( testData.getDataDirectoryRoot(),
            "styles/foostyle.xml");
        assertFalse( f.exists() );
       
        StyleInfo s = catalog.getFactory().createStyle();
        s.setName("foostyle");
        s.setFilename( "foostyle.sld");
        catalog.add( s );
       
        assertTrue( f.exists() );
    }
View Full Code Here

Examples of org.geoserver.catalog.StyleInfo

    }
   
    public void testModifyStyle() throws Exception {
        testAddStyle();
       
        StyleInfo s = catalog.getStyleByName( "foostyle" );
        s.setFilename( "foostyle2.sld");
        catalog.save( s );
       
        File f = new File( testData.getDataDirectoryRoot(),
            "styles/foostyle.xml");
        Document dom = dom( f );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.