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