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;
}
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;
}
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();
}
}
}
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;
}
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();
}
}
}
Aggregations