use of org.geotools.styling.SLDTransformer in project sldeditor by robward-scisys.
the class SLDWriterImpl method encodeSLD.
/**
* Encode sld to a string
*
* @param sld the sld
* @return the string
*/
public String encodeSLD(StyledLayerDescriptor sld) {
String xml = "";
if (sld != null) {
SLDTransformer transformer = new SLDTransformer();
transformer.setIndentation(2);
try {
xml = transformer.transform(sld);
} catch (TransformerException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
return xml;
}
use of org.geotools.styling.SLDTransformer in project sldeditor by robward-scisys.
the class SLDWriterImpl method encodeSLD.
/**
* Encode sld to a string.
*
* @param resourceLocator the resource locator
* @param sld the sld
* @return the string
*/
@Override
public String encodeSLD(URL resourceLocator, StyledLayerDescriptor sld) {
String xml = "";
if (sld != null) {
InlineDatastoreVisitor duplicator = new InlineDatastoreVisitor();
sld.accept(duplicator);
StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicator.getCopy();
if (resourceLocator != null) {
SLDExternalImages.updateOnlineResources(resourceLocator, sldCopy);
}
SLDTransformer transformer = new SLDTransformer();
transformer.setIndentation(2);
try {
xml = transformer.transform(sldCopy);
if (xml.startsWith(START_OF_XML_HEADER)) {
int pos = xml.indexOf(END_OF_XML_HEADER, 0);
if (pos > 1) {
pos = pos + END_OF_XML_HEADER.length() + 1;
String xmlHeader = xml.substring(0, pos);
String sldBody = xml.substring(pos);
xml = xmlHeader + getHeader() + sldBody;
}
}
} catch (TransformerException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
return xml;
}
Aggregations