Search in sources :

Example 1 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.

the class YSLDToolTest method getSLDDataFile.

/**
 * Gets the SLD/YSLD file.
 *
 * @param testfile the testfile
 * @return the SLD data file
 */
private static SLDData getSLDDataFile(String testfile) {
    SLDData sldData = null;
    InputStream inputStream = YSLDToolTest.class.getResourceAsStream(testfile);
    if (inputStream == null) {
        Assert.assertNotNull("Failed to find test file : " + testfile, inputStream);
    } else {
        File f = null;
        try {
            String fileExtension = ExternalFilenames.getFileExtension(testfile);
            f = stream2file(inputStream, ExternalFilenames.addFileExtensionSeparator(fileExtension));
            String sldContents = readFile(f.getAbsolutePath());
            if (fileExtension.compareTo("ysld") == 0) {
                StyledLayerDescriptor sld = Ysld.parse(sldContents);
                // Convert YSLD to SLD string
                SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
                sldContents = sldWriter.encodeSLD(null, sld);
            }
            sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
            sldData.setSLDFile(f);
            SelectedSymbol.getInstance().setSld(SLDUtils.createSLDFromString(sldData));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    return sldData;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) InputStream(java.io.InputStream) SLDWriterInterface(com.sldeditor.common.output.SLDWriterInterface) IOException(java.io.IOException) File(java.io.File)

Example 2 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.

the class LegendManagerTest method testSLD1.

/**
 * Create test SLD
 *
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor testSLD1() {
    String sldContents = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" " + "    xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" " + "    xmlns=\"http://www.opengis.net/sld\" " + "    xmlns:sld=\"http://www.opengis.net/sld\" " + "    xmlns:ogc=\"http://www.opengis.net/ogc\" " + "    xmlns:gml=\"http://www.opengis.net/gml\" " + "    xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<sld:UserLayer>" + "<sld:Name>Inline</sld:Name>" + "<sld:InlineFeature>" + "  <FeatureCollection>" + "    <featureMember>" + "      <gml:_Feature>" + "        <geometryProperty>" + "          <Polygon>" + "            <outerBoundaryIs>" + "              <LinearRing>" + "              <coordinates>-127,51 -110,51 -110,41 -127,41 -127,51</coordinates>" + "              </LinearRing>" + "            </outerBoundaryIs>" + "          </Polygon>" + "        </geometryProperty>" + "        <title>Pacific NW</title>" + "      </gml:_Feature>" + "    </featureMember>" + "  </FeatureCollection>" + "</sld:InlineFeature>" + "<sld:LayerFeatureConstraints>" + "  <sld:FeatureTypeConstraint/>" + "</sld:LayerFeatureConstraints>" + "<sld:UserStyle>" + "  <sld:Name>Default Styler</sld:Name>" + "  <sld:FeatureTypeStyle>" + "    <sld:Name>name</sld:Name>" + "    <sld:Rule>" + "      <sld:PolygonSymbolizer>" + "        <sld:Stroke>" + "          <sld:CssParameter name=\"stroke\">#FF0000</sld:CssParameter>" + "          <sld:CssParameter name=\"stroke-width\">2</sld:CssParameter>" + "        </sld:Stroke>" + "      </sld:PolygonSymbolizer>" + "      <sld:TextSymbolizer>" + "        <sld:Label>" + "          <ogc:PropertyName>title</ogc:PropertyName>" + "        </sld:Label>" + "        <sld:LabelPlacement>" + "          <sld:PointPlacement>" + "            <sld:AnchorPoint>" + "              <sld:AnchorPointX>0.0</sld:AnchorPointX>" + "              <sld:AnchorPointY>0.5</sld:AnchorPointY>" + "            </sld:AnchorPoint>" + "          </sld:PointPlacement>" + "        </sld:LabelPlacement>" + "        <sld:Fill>" + "          <sld:CssParameter name=\"fill\">#FF0000</sld:CssParameter>" + "        </sld:Fill>" + "      </sld:TextSymbolizer>" + "    </sld:Rule>" + "  </sld:FeatureTypeStyle>" + "</sld:UserStyle>" + "</sld:UserLayer>" + "</StyledLayerDescriptor>";
    SLDData sldData = new SLDData(new StyleWrapper(null, "test.sld"), sldContents);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
    return sld;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper)

Example 3 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.

the class SLDEditor method saveFile.

/**
 * Save file.
 *
 * @param urlToSave the url to save
 */
/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.SLDEditorInterface#saveFile(java.net.URL)
     */
@Override
public void saveFile(URL urlToSave) {
    String sldContents = getSLDString();
    SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
    sldData.updateSLDContents(sldContents);
    if (RelativePath.isLocalFile(urlToSave)) {
        StyleWrapper style = null;
        try {
            File f = new File(urlToSave.toURI());
            style = new StyleWrapper(f.getName());
        } catch (URISyntaxException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
        sldData.updateStyleWrapper(style);
    }
    ReloadManager.getInstance().setFileSaved();
    saveSLDData(sldData);
    SLDEditorFile.getInstance().fileOpenedSaved();
    UndoManager.getInstance().fileSaved();
}
Also used : SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) URISyntaxException(java.net.URISyntaxException) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Example 4 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.

the class SLDFileHandler method internalOpenFile.

/**
 * Internal open file.
 *
 * @param f the file
 * @param list the list
 */
private void internalOpenFile(File f, List<SLDDataInterface> list) {
    if (f.isFile() && FileSystemUtils.isFileExtensionSupported(f, getFileExtensionList())) {
        try {
            String sldContents = readFile(f, Charset.defaultCharset());
            SLDDataInterface sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
            sldData.setSLDFile(f);
            sldData.setReadOnly(false);
            list.add(sldData);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) IOException(java.io.IOException)

Example 5 with StyleWrapper

use of com.sldeditor.common.data.StyleWrapper in project sldeditor by robward-scisys.

the class SLDEditorFileHandler method readSLDEditorFile.

/**
 * Read sld editor file.
 *
 * @param file the file
 * @return the SLD data
 */
private SLDDataInterface readSLDEditorFile(File file) {
    SLDDataInterface sldData = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder;
    try {
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.parse(file);
        String sldFile = extractTextData(document, SLDEditorFileHandler.SLD_ELEMENT);
        DataSourcePropertiesInterface dataSourceProperties = DataSourceProperties.decodeXML(document, SLDEditorFileHandler.DATASOURCE_ELEMENT);
        List<VersionData> vendorOptionList = extractVendorOptionData(document, SLDEditorFileHandler.VENDOR_OPTION_ELEMENT);
        File f = new File(sldFile);
        String sldContents = readFile(f, Charset.defaultCharset());
        sldData = new SLDData(new StyleWrapper(sldFile), sldContents);
        sldData.setDataSourceProperties(dataSourceProperties);
        sldData.setVendorOptionList(vendorOptionList);
        List<DataSourceAttributeData> fieldList = null;
        sldData.setFieldList(fieldList);
        sldData.setSLDFile(f);
        sldData.setReadOnly(false);
        sldData.setSldEditorFile(file);
        List<EnvVar> envVarList = extractEnvironmentVariables(document, SLDEditorFileHandler.ENVVAR_ELEMENT);
        sldData.setEnvVarList(envVarList);
        LegendOptionData legendOption = LegendOptionData.decodeXML(document, SLDEditorFileHandler.LEGEND_OPTION_ELEMENT);
        sldData.setLegendOptions(legendOption);
    } catch (ParserConfigurationException e) {
        ConsoleManager.getInstance().exception(this, e);
    } catch (SAXException e) {
        ConsoleManager.getInstance().exception(this, e);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    return sldData;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) DataSourceAttributeData(com.sldeditor.datasource.attribute.DataSourceAttributeData) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) IOException(java.io.IOException) Document(org.w3c.dom.Document) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) LegendOptionData(com.sldeditor.ui.legend.option.LegendOptionData) SAXException(org.xml.sax.SAXException) SLDDataInterface(com.sldeditor.common.SLDDataInterface) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StyleWrapper(com.sldeditor.common.data.StyleWrapper) VersionData(com.sldeditor.common.vendoroption.VersionData) EnvVar(com.sldeditor.filter.v2.envvar.EnvVar) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Aggregations

StyleWrapper (com.sldeditor.common.data.StyleWrapper)59 SLDData (com.sldeditor.common.data.SLDData)35 Test (org.junit.Test)31 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)15 File (java.io.File)14 SLDDataInterface (com.sldeditor.common.SLDDataInterface)12 ArrayList (java.util.ArrayList)12 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)10 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)9 List (java.util.List)9 GeoServerLayer (com.sldeditor.common.data.GeoServerLayer)8 IOException (java.io.IOException)8 GeoServerInput (com.sldeditor.extension.filesystem.geoserver.GeoServerInput)7 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 GeoServerStyleNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode)5 GeoServerWorkspaceNode (com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode)5 HashMap (java.util.HashMap)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)4 NamedLayer (org.geotools.styling.NamedLayer)4