Search in sources :

Example 6 with SLDTransformer

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;
}
Also used : SLDTransformer(org.geotools.styling.SLDTransformer) TransformerException(javax.xml.transform.TransformerException)

Example 7 with SLDTransformer

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;
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SLDTransformer(org.geotools.styling.SLDTransformer) TransformerException(javax.xml.transform.TransformerException)

Aggregations

SLDTransformer (org.geotools.styling.SLDTransformer)7 TransformerException (javax.xml.transform.TransformerException)6 IOException (java.io.IOException)2 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 OutputStream (java.io.OutputStream)1 StringWriter (java.io.StringWriter)1 Document (org.eclipse.jface.text.Document)1 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 IDocument (org.eclipse.jface.text.IDocument)1 IDocumentListener (org.eclipse.jface.text.IDocumentListener)1 CompositeRuler (org.eclipse.jface.text.source.CompositeRuler)1 LineNumberRulerColumn (org.eclipse.jface.text.source.LineNumberRulerColumn)1 SourceViewer (org.eclipse.jface.text.source.SourceViewer)1 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Display (org.eclipse.swt.widgets.Display)1 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)1 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)1 Timer (org.polymap.core.runtime.Timer)1