Search in sources :

Example 1 with SLDTransformer

use of org.geotools.styling.SLDTransformer in project hale by halestudio.

the class SLDStyleWriter method execute.

/**
 * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
 */
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Save styles to SLD", ProgressIndicator.UNKNOWN);
    SLDTransformer trans = new SLDTransformer();
    trans.setIndentation(2);
    OutputStream out = getTarget().getOutput();
    try {
        trans.transform(getStyle(), out);
        reporter.setSuccess(true);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl("Saving the style as SLD failed.", e));
        reporter.setSuccess(false);
    } finally {
        out.close();
        progress.end();
    }
    return reporter;
}
Also used : SLDTransformer(org.geotools.styling.SLDTransformer) OutputStream(java.io.OutputStream) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 2 with SLDTransformer

use of org.geotools.styling.SLDTransformer in project sldeditor by robward-scisys.

the class InlineFeatureUtils method getInlineFeaturesText.

/**
 * Gets the inline features text.
 *
 * @param userLayer the user layer
 * @return the inline features text
 */
public static String getInlineFeaturesText(UserLayer userLayer) {
    if (userLayer == null) {
        return "";
    }
    // Handle the case where there is a featurecollection but no features
    if (userLayer.getInlineFeatureDatastore() != null) {
        String typeName = userLayer.getInlineFeatureType().getTypeName();
        SimpleFeatureSource featureSource;
        try {
            featureSource = userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);
            if (featureSource.getFeatures().isEmpty()) {
                return "";
            }
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(InlineFeatureUtils.class, e);
            return "";
        }
    }
    // Inline features
    SLDTransformer transform = new SLDTransformer();
    StringWriter stringWriter = new StringWriter();
    try {
        transform.setIndentation(2);
        transform.setOmitXMLDeclaration(true);
        transform.createTransformer();
        transform.transform(userLayer, stringWriter);
    } catch (TransformerException e) {
        ConsoleManager.getInstance().exception(InlineFeatureUtils.class, e);
        return null;
    }
    String userLayerXML = stringWriter.toString();
    // Check to see if there are any inline features
    if (!userLayerXML.contains(SLD_INLINE_FEATURE_START)) {
        return "";
    }
    int beginIndex = userLayerXML.indexOf(GML_START);
    StringBuilder sb = new StringBuilder();
    sb.append("\n");
    int index = beginIndex - 1;
    while (index > 0) {
        if (userLayerXML.charAt(index) != ' ') {
            break;
        } else {
            sb.append(" ");
            index--;
        }
    }
    int endIndex = userLayerXML.lastIndexOf(GML_END) + GML_END.length();
    if (beginIndex < 0) {
        beginIndex = 0;
    }
    String extract = userLayerXML.substring(beginIndex, endIndex);
    extract = extract.replace(sb.toString(), "\n");
    return (extract);
}
Also used : StringWriter(java.io.StringWriter) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) SLDTransformer(org.geotools.styling.SLDTransformer) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException)

Example 3 with SLDTransformer

use of org.geotools.styling.SLDTransformer in project polymap4-core by Polymap4.

the class DefaultStyles method serialize.

public static String serialize(Style style) {
    try {
        SLDTransformer styleTransform = new SLDTransformer();
        styleTransform.setIndentation(4);
        styleTransform.setOmitXMLDeclaration(false);
        return styleTransform.transform(style);
    } catch (TransformerException e) {
        throw new RuntimeException("Unable to transform style.", e);
    }
}
Also used : SLDTransformer(org.geotools.styling.SLDTransformer) TransformerException(javax.xml.transform.TransformerException)

Example 4 with SLDTransformer

use of org.geotools.styling.SLDTransformer in project polymap4-core by Polymap4.

the class StyleRepository method toSLD.

protected String toSLD(org.geotools.styling.Style style) {
    Timer timer = new Timer();
    try {
        SLDTransformer styleTransform = new SLDTransformer();
        styleTransform.setIndentation(4);
        styleTransform.setOmitXMLDeclaration(false);
        return styleTransform.transform(style);
    } catch (TransformerException e) {
        throw new RuntimeException("Unable to transform style.", e);
    } finally {
        log.info("Style to SLD: " + timer.elapsedTime() + "ms.");
    }
}
Also used : Timer(org.polymap.core.runtime.Timer) SLDTransformer(org.geotools.styling.SLDTransformer) TransformerException(javax.xml.transform.TransformerException)

Example 5 with SLDTransformer

use of org.geotools.styling.SLDTransformer in project hale by halestudio.

the class XMLStylePage3 method createControl.

/**
 * @see IDialogPage#createControl(Composite)
 */
@Override
public void createControl(Composite parent) {
    changed = false;
    final Display display = parent.getDisplay();
    FillLayout fillLayout = new FillLayout();
    fillLayout.type = SWT.VERTICAL;
    parent.setLayout(fillLayout);
    CompositeRuler ruler = new CompositeRuler(3);
    LineNumberRulerColumn lineNumbers = new LineNumberRulerColumn();
    // SWT.COLOR_INFO_BACKGROUND));
    lineNumbers.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
    // SWT.COLOR_INFO_FOREGROUND));
    lineNumbers.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
    lineNumbers.setFont(JFaceResources.getTextFont());
    ruler.addDecorator(0, lineNumbers);
    viewer = new SourceViewer(parent, ruler, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.getTextWidget().setFont(JFaceResources.getTextFont());
    SourceViewerConfiguration conf = new SourceViewerConfiguration();
    viewer.configure(conf);
    SLDTransformer trans = new SLDTransformer();
    trans.setIndentation(2);
    String xml;
    try {
        xml = trans.transform(getParent().getStyle());
    } catch (TransformerException e) {
        // $NON-NLS-1$
        xml = "Error: " + e.getMessage();
    }
    IDocument doc = new Document();
    doc.set(xml);
    doc.addDocumentListener(new IDocumentListener() {

        @Override
        public void documentChanged(DocumentEvent event) {
            changed = true;
        }

        @Override
        public void documentAboutToBeChanged(DocumentEvent event) {
        // ignore
        }
    });
    viewer.setInput(doc);
    setControl(viewer.getControl());
}
Also used : LineNumberRulerColumn(org.eclipse.jface.text.source.LineNumberRulerColumn) SourceViewer(org.eclipse.jface.text.source.SourceViewer) IDocumentListener(org.eclipse.jface.text.IDocumentListener) CompositeRuler(org.eclipse.jface.text.source.CompositeRuler) FillLayout(org.eclipse.swt.layout.FillLayout) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DocumentEvent(org.eclipse.jface.text.DocumentEvent) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) SLDTransformer(org.geotools.styling.SLDTransformer) TransformerException(javax.xml.transform.TransformerException) IDocument(org.eclipse.jface.text.IDocument) Display(org.eclipse.swt.widgets.Display)

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