use of org.geotools.styling.SLDParser in project hale by halestudio.
the class XMLStylePage3 method getStyle.
/**
* @see FeatureStylePage#getStyle(boolean)
*/
@Override
public Style getStyle(boolean force) throws Exception {
if (viewer == null || (!force && !changed)) {
return null;
}
IDocument doc = viewer.getDocument();
SLDParser parser = new SLDParser(styleFactory, new StringReader(doc.get()));
Style[] styles = parser.readXML();
return styles[0];
}
use of org.geotools.styling.SLDParser in project hale by halestudio.
the class StyleServiceImpl method addStyles.
/**
* @see StyleService#addStyles(URL)
*/
@Override
public boolean addStyles(URL url) {
SLDParser stylereader;
try {
stylereader = new SLDParser(styleFactory, url);
Style[] styles = stylereader.readXML();
addStyles(styles);
return true;
} catch (Exception e) {
// $NON-NLS-1$
_log.error("Error reading styled layer descriptor", e);
return false;
}
}
use of org.geotools.styling.SLDParser in project sldeditor by robward-scisys.
the class SLDUtils method createSLDFromString.
/**
* Creates a StyledLayerDescriptor object containing a SLD from a string.
*
* @param sldData the sld data
* @return the styled layer descriptor
*/
public static StyledLayerDescriptor createSLDFromString(SLDDataInterface sldData) {
if ((sldData == null) || (sldData.getSld() == null)) {
return null;
}
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
InputStream stream = new ByteArrayInputStream(sldData.getSld().getBytes());
SLDParser styleReader = new SLDParser(styleFactory, stream);
URL resourceLocator = getResourceLocator(sldData);
sldData.setResourceLocator(resourceLocator);
setResourcelocator(styleReader, resourceLocator);
StyledLayerDescriptor sld = null;
try {
sld = styleReader.parseSLD();
} catch (RuntimeException e) {
String errorMessage = String.format("SLD Parser error : %s", sldData.getStyle().toString());
ConsoleManager.getInstance().error(SLDUtils.class, errorMessage);
ConsoleManager.getInstance().error(SLDUtils.class, e.getMessage());
}
return sld;
}
use of org.geotools.styling.SLDParser in project sldeditor by robward-scisys.
the class SLDUtils method readSLDFile.
/**
* Creates a StyledLayerDescriptor object containing a SLD by reading the contents of a file.
*
* @param file the file
* @return the styled layer descriptor
*/
public static StyledLayerDescriptor readSLDFile(File file) {
StyledLayerDescriptor sld = null;
if (file != null) {
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
try {
// By using URL here allows external graphics to loaded properly
URL url = file.toURI().toURL();
SLDParser styleReader = new SLDParser(styleFactory, url);
setResourcelocator(styleReader, file.toURI().toURL());
sld = styleReader.parseSLD();
} catch (MalformedURLException e) {
ConsoleManager.getInstance().exception(SLDUtils.class, e);
} catch (IOException e) {
ConsoleManager.getInstance().exception(SLDUtils.class, e);
}
}
return sld;
}
use of org.geotools.styling.SLDParser in project hale by halestudio.
the class SLDStyleReader method execute.
/**
* @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
*/
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin("Load styles from SLD", ProgressIndicator.UNKNOWN);
StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null);
InputStream in = getSource().getInput();
try {
SLDParser stylereader = new SLDParser(styleFactory, in);
styles = stylereader.readXML();
reporter.setSuccess(true);
} catch (Exception e) {
reporter.error(new IOMessageImpl("Loading styles from SLD failed.", e));
reporter.setSuccess(false);
} finally {
in.close();
progress.end();
}
return reporter;
}
Aggregations