Search in sources :

Example 6 with SLDData

use of com.sldeditor.common.data.SLDData 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 7 with SLDData

use of com.sldeditor.common.data.SLDData 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 8 with SLDData

use of com.sldeditor.common.data.SLDData 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 9 with SLDData

use of com.sldeditor.common.data.SLDData 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)

Example 10 with SLDData

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

the class YSLDFileHandler 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 contents = readFile(f, Charset.defaultCharset());
            StyledLayerDescriptor sld = Ysld.parse(contents);
            // Convert YSLD to SLD string
            if (sldWriter == null) {
                sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
            }
            String sldContents = sldWriter.encodeSLD(null, sld);
            SLDDataInterface sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
            sldData.setSLDFile(f);
            sldData.setReadOnly(false);
            sldData.setOriginalFormat(SLDOutputFormatEnum.YSLD);
            list.add(sldData);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) IOException(java.io.IOException)

Aggregations

SLDData (com.sldeditor.common.data.SLDData)68 Test (org.junit.Test)54 StyleWrapper (com.sldeditor.common.data.StyleWrapper)35 File (java.io.File)27 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)24 SLDDataInterface (com.sldeditor.common.SLDDataInterface)20 IOException (java.io.IOException)20 URL (java.net.URL)16 ArrayList (java.util.ArrayList)14 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)8 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)8 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)7 FileNotFoundException (java.io.FileNotFoundException)7 URISyntaxException (java.net.URISyntaxException)7 MalformedURLException (java.net.MalformedURLException)6 NamedLayer (org.geotools.styling.NamedLayer)6 Style (org.geotools.styling.Style)6 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)5 VersionData (com.sldeditor.common.vendoroption.VersionData)4