Package org.geoserver.catalog.impl

Examples of org.geoserver.catalog.impl.StyleInfoImpl


        catalog.add(namespaceInfo);

        workspaceInfo = new WorkspaceInfoImpl();
        catalog.setDefaultWorkspace(workspaceInfo);

        defaultStyle = new StyleInfoImpl(catalog) {
            /**
             * Override so it does not try to load a file from disk
             */
            @Override
            public Style getStyle() throws IOException {
View Full Code Here


    public MapInfo createMap() {
        return new MapInfoImpl();
    }

    public StyleInfo createStyle() {
        return new StyleInfoImpl(catalog);
    }
View Full Code Here

        Object obj = event.getSource();
       
        if(obj instanceof StyleInfoImpl) {
           // TODO First pass only considers default styles,
           // which is all GWC will accept anyway
           StyleInfoImpl si = (StyleInfoImpl) 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()) {
               LayerInfo li = liter.next();
               if(li.getDefaultStyle().getName().equals(styleName)) {
                   String prefixedName = li.getResource().getPrefixedName();
                   layerNameList.add(prefixedName);
                   cleanser.deleteLayer(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

        String layerName = getNodeValue(n_layerName); //.split("_styleLayerName")[0];
        String styleName = getNodeValue(n_styleName);
        LOGGER.info("PutStyles SLD:\nLayer: " + layerName + ", style: " + styleName);

        // store the SLD
        StyleInfoImpl style = new StyleInfoImpl(getCatalog());
        style.setId(styleName);

        // make the SLD file in the data_dir/styles directory
        File data_dir = GeoserverDataDirectory.getGeoserverDataDirectory();
        File style_dir;

        try {
            style_dir = GeoserverDataDirectory.findConfigDir(data_dir, "styles");
        } catch (ConfigurationException cfe) {
            LOGGER.warning("no style dir found, creating new one");
            //if for some bizarre reason we don't fine the dir, make a new one.
            style_dir = new File(data_dir, "styles");
        }

        File styleFile = new File(style_dir, styleName + ".sld"); // styleName.sld
                                                                  //styleFile.createNewFile();

        LOGGER.info("Saving new SLD file to " + styleFile.getPath());

        // populate it with the style code
        StringBuffer sldText = new StringBuffer();
        sldText.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        sldText.append("<StyledLayerDescriptor version=\"1.0.0\"\n");
        sldText.append(
            "  xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\"\n");
        sldText.append(
            "  xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\"\n");
        sldText.append("  xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n");
        sldText.append("  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n");

        FileOutputStream style_fos = new FileOutputStream(styleFile); // save the sld to a file

        String sldBody = serviceRequest.getSldBody();
        int start = sldBody.indexOf("<NamedLayer>");
        int end = sldBody.indexOf("</NamedLayer>");

        sldText.append(sldBody.substring(start, end));
        sldText.append("</NamedLayer>\n");
        sldText.append("</StyledLayerDescriptor>");
        style_fos.write(sldText.toString().getBytes());
        style_fos.flush();
        style_fos.close();

        style.setFilename(styleFile.getAbsolutePath());

        // update the data config to tell it about our new style
        getCatalog().add(style);

        // SLD is set up now, so tell the feature type to use it
View Full Code Here

        vectorLayer.setEnabled(true);
        vectorLayer.setName("vectorLayer");
        vectorLayer.setId("vectorLayerId");
        vectorLayer.setType(LayerInfo.Type.VECTOR);

        defaultStyle = new StyleInfoImpl(null);
        defaultStyle.setName("default");
        defaultStyle.setId("defaultStyle_id");
        vectorLayer.setDefaultStyle(defaultStyle);

        style1 = new StyleInfoImpl(null);
        style1.setName("style1");
        style1.setId("style1_id");

        style2 = new StyleInfoImpl(null);
        style2.setName("style2");
        style2.setId("style2_id");

        vectorLayer.getStyles().add(style1);
        vectorLayer.getStyles().add(style2);
View Full Code Here

        catalog.add(namespaceInfo);

        workspaceInfo = new WorkspaceInfoImpl();
        catalog.setDefaultWorkspace(workspaceInfo);

        defaultStyle = new StyleInfoImpl(catalog) {
            /**
             * Override so it does not try to load a file from disk
             */
            @Override
            public Style getStyle() throws IOException {
View Full Code Here

        layerInfo.setId(layerInfoId);
        layerInfo.setResource(resource);
        layerInfo.setEnabled(true);
        layerInfo.setName("MockLayerInfoName");
        layerInfo.setType(Type.VECTOR);
        StyleInfo defaultStyle = new StyleInfoImpl(null);
        defaultStyle.setName("default_style");

        layerInfo.setDefaultStyle(defaultStyle);

        StyleInfo alternateStyle1 = new StyleInfoImpl(null);
        alternateStyle1.setName("alternateStyle-1");
        StyleInfo alternateStyle2 = new StyleInfoImpl(null);
        alternateStyle2.setName("alternateStyle-2");
        Set<StyleInfo> alternateStyles = new HashSet<StyleInfo>(Arrays.asList(alternateStyle1,
                alternateStyle2));
        layerInfo.setStyles(alternateStyles);

        layerGroup = new LayerGroupInfoImpl();
View Full Code Here

        layerGroupInfoTileLayer = new GeoServerTileLayer(layerGroup, defaults, gridSetBroker);

        assertEquals("default_style", layerInfoTileLayer.getStyles());
        assertNull(layerGroupInfoTileLayer.getStyles());

        StyleInfo newDefaultStyle = new StyleInfoImpl(null);
        newDefaultStyle.setName("newDefault");
        layerInfo.setDefaultStyle(newDefaultStyle);

        assertEquals("newDefault", layerInfoTileLayer.getStyles());
    }
View Full Code Here

                return new ResourceState() {

                    @Override
                    public byte[] getData() {
                        GeoServerDataDirectory dd = GeoServerExtensions.bean(GeoServerDataDirectory.class, getGeoServerApplication().getApplicationContext());
                        StyleInfo si = new StyleInfoImpl(getCatalog());
                        String styleName = "tmp" + UUID.randomUUID().toString();
                        String styleFileName =  styleName + ".sld";
                        si.setFilename(styleFileName);
                        si.setName(styleName);
                        si.setWorkspace(wsChoice.getModel().getObject());
                        File styleFile = null;
                        try {
                            styleFile = dd.findOrCreateStyleSldFile(si);
                            FileUtils.writeStringToFile(styleFile, lastStyle);
                            StyledLayerDescriptor sld = styleHandler().parse(styleFile, null, null, null);
View Full Code Here

        LayerInfoImpl layer = new LayerInfoImpl();
        layer.setId("id-" + resource.prefixedName());
        layer.setResource(resource);
        layer.setEnabled(true);

        StyleInfoImpl defaultStyle = new StyleInfoImpl(null);
        defaultStyle.setName("default");
        layer.setDefaultStyle(defaultStyle);

        if (extraStyles != null) {
            Set styles = new HashSet();
            for (String name : extraStyles) {
                StyleInfoImpl extra = new StyleInfoImpl(null);
                extra.setName(name);
                styles.add(extra);
            }
            layer.setStyles(styles);
        }
View Full Code Here

TOP

Related Classes of org.geoserver.catalog.impl.StyleInfoImpl

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.