Search in sources :

Example 11 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class GeoServerInput method getSLDContents.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.extension.input.FileSystemInterface#getSLDContents(com.sldeditor.extension.input.NodeInterface)
     */
@Override
public SelectedFiles getSLDContents(NodeInterface node) {
    if (node instanceof GeoServerStyleNode) {
        GeoServerStyleNode styleNode = (GeoServerStyleNode) node;
        GeoServerConnection connectionData = styleNode.getConnectionData();
        GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(connectionData);
        if (client != null) {
            String sldContent = client.getStyle(styleNode.getStyle());
            SLDDataInterface sldData = new SLDData(styleNode.getStyle(), sldContent);
            sldData.setConnectionData(connectionData);
            sldData.setReadOnly(false);
            List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
            sldDataList.add(sldData);
            SelectedFiles selectedFiles = new SelectedFiles();
            selectedFiles.setSldData(sldDataList);
            selectedFiles.setDataSource(false);
            selectedFiles.setConnectionData(connectionData);
            return selectedFiles;
        }
    } else if (node instanceof GeoServerWorkspaceNode) {
        GeoServerWorkspaceNode workspaceNode = (GeoServerWorkspaceNode) node;
        GeoServerConnection connectionData = workspaceNode.getConnection();
        GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(connectionData);
        List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
        if (workspaceNode.isStyle()) {
            Map<String, List<StyleWrapper>> styleMap = getStyleMap(connectionData);
            if ((client != null) && (styleMap != null)) {
                for (StyleWrapper style : styleMap.get(workspaceNode.getWorkspaceName())) {
                    String sldContent = client.getStyle(style);
                    SLDDataInterface sldData = new SLDData(style, sldContent);
                    sldData.setConnectionData(connectionData);
                    sldData.setReadOnly(false);
                    sldDataList.add(sldData);
                }
            }
        }
        SelectedFiles selectedFiles = new SelectedFiles();
        selectedFiles.setSldData(sldDataList);
        selectedFiles.setDataSource(false);
        selectedFiles.setConnectionData(connectionData);
        return selectedFiles;
    } else if (node instanceof GeoServerStyleHeadingNode) {
        GeoServerStyleHeadingNode styleHeadingNode = (GeoServerStyleHeadingNode) node;
        GeoServerConnection connectionData = styleHeadingNode.getConnection();
        GeoServerClientInterface client = GeoServerConnectionManager.getInstance().getConnectionMap().get(connectionData);
        List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
        Map<String, List<StyleWrapper>> styleMap = getStyleMap(connectionData);
        if ((client != null) && (styleMap != null)) {
            for (String workspaceName : styleMap.keySet()) {
                for (StyleWrapper style : styleMap.get(workspaceName)) {
                    String sldContent = client.getStyle(style);
                    SLDDataInterface sldData = new SLDData(style, sldContent);
                    sldData.setConnectionData(connectionData);
                    sldData.setReadOnly(false);
                    sldDataList.add(sldData);
                }
            }
        }
        SelectedFiles selectedFiles = new SelectedFiles();
        selectedFiles.setSldData(sldDataList);
        selectedFiles.setDataSource(false);
        selectedFiles.setConnectionData(connectionData);
        return selectedFiles;
    } else if (node instanceof GeoServerNode) {
        GeoServerNode geoServerNode = (GeoServerNode) node;
        GeoServerConnection connectionData = geoServerNode.getConnection();
        SelectedFiles selectedFiles = new SelectedFiles();
        selectedFiles.setDataSource(false);
        selectedFiles.setConnectionData(connectionData);
        return selectedFiles;
    }
    return null;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) GeoServerNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerNode) ArrayList(java.util.ArrayList) GeoServerConnection(com.sldeditor.common.data.GeoServerConnection) GeoServerStyleNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleNode) GeoServerClientInterface(com.sldeditor.extension.filesystem.geoserver.client.GeoServerClientInterface) GeoServerWorkspaceNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerWorkspaceNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) StyleWrapper(com.sldeditor.common.data.StyleWrapper) GeoServerStyleHeadingNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerStyleHeadingNode) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class VectorReader method createVectorSLDData.

/**
 * Creates the vector sld.
 *
 * @param vectorFile the vector file
 * @return the styled layer descriptor
 */
@Override
public SLDDataInterface createVectorSLDData(File vectorFile) {
    if (vectorFile == null) {
        return null;
    }
    Map<String, Object> map = null;
    try {
        map = DataSourceProperties.encodeFilename(vectorFile.toURI().toURL().toString());
    } catch (MalformedURLException e) {
        ConsoleManager.getInstance().exception(this, e);
        return null;
    }
    StyledLayerDescriptor sld = createSLDData(map, null);
    SLDData sldData = null;
    if (sld != null) {
        File sldFilename = ExternalFilenames.createSLDFilename(vectorFile);
        StyleWrapper styleWrapper = new StyleWrapper(sldFilename.getName());
        String sldContents = sldWriter.encodeSLD(null, sld);
        sldData = new SLDData(styleWrapper, sldContents);
        sldData.setSLDFile(sldFilename);
        sldData.setReadOnly(false);
    }
    return sldData;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) MalformedURLException(java.net.MalformedURLException) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) File(java.io.File)

Example 13 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class VectorReader method createVectorSLDData.

/*
     * (non-Javadoc)
     * 
     * @see com.sldeditor.tool.vector.VectorReaderInterface#createVectorSLDData(com.sldeditor.common.data.DatabaseConnection, java.lang.String)
     */
@Override
public SLDDataInterface createVectorSLDData(DatabaseConnection databaseConnection, String featureClass) {
    if ((databaseConnection == null) || (featureClass == null)) {
        return null;
    }
    Map<String, Object> map = DatabaseConnectionManager.getInstance().getDBConnectionParams(databaseConnection);
    StyledLayerDescriptor sld = createSLDData(map, featureClass);
    SLDData sldData = null;
    if (sld != null) {
        File sldFilename = null;
        StyleWrapper styleWrapper = new StyleWrapper(featureClass);
        String sldContents = sldWriter.encodeSLD(null, sld);
        sldData = new SLDData(styleWrapper, sldContents);
        sldData.setSLDFile(sldFilename);
        sldData.setReadOnly(false);
    }
    return sldData;
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) StyleWrapper(com.sldeditor.common.data.StyleWrapper) File(java.io.File)

Example 14 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class SLDDataTest method testGetLayerName.

/**
 * Test get layer name.
 */
@Test
public void testGetLayerName() {
    String styleName = "style";
    String styleFilename = styleName + ".sld";
    StyleWrapper styleWrapper = new StyleWrapper("workspace", styleFilename);
    SLDData data = new SLDData(styleWrapper, null);
    String actualLayerName = data.getLayerName();
    assertEquals(styleFilename, actualLayerName);
    String actualLayerNameWithOutSuffix = data.getLayerNameWithOutSuffix();
    assertEquals(styleName, actualLayerNameWithOutSuffix);
}
Also used : SLDData(com.sldeditor.common.data.SLDData) StyleWrapper(com.sldeditor.common.data.StyleWrapper) Test(org.junit.Test)

Example 15 with SLDData

use of com.sldeditor.common.data.SLDData in project sldeditor by robward-scisys.

the class SLDDataTest method testUpdateSLDContents.

/**
 * Test update sld contents.
 */
@Test
public void testUpdateSLDContents() {
    String sldContents = "Original sld contents";
    SLDData data = new SLDData(null, sldContents);
    assertEquals(sldContents, data.getSld());
    String updateSldContents = "Updated sld contents";
    data.updateSLDContents(updateSldContents);
    assertEquals(updateSldContents, data.getSld());
}
Also used : SLDData(com.sldeditor.common.data.SLDData) Test(org.junit.Test)

Aggregations

SLDData (com.sldeditor.common.data.SLDData)68 Test (org.junit.Test)54 StyleWrapper (com.sldeditor.common.data.StyleWrapper)35 File (java.io.File)27 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)24 SLDDataInterface (com.sldeditor.common.SLDDataInterface)20 IOException (java.io.IOException)20 URL (java.net.URL)16 ArrayList (java.util.ArrayList)14 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)8 SLDFileHandlerTest (com.sldeditor.test.unit.extension.filesystem.file.sld.SLDFileHandlerTest)8 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)7 FileNotFoundException (java.io.FileNotFoundException)7 URISyntaxException (java.net.URISyntaxException)7 MalformedURLException (java.net.MalformedURLException)6 NamedLayer (org.geotools.styling.NamedLayer)6 Style (org.geotools.styling.Style)6 SLDWriterInterface (com.sldeditor.common.output.SLDWriterInterface)5 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)5 VersionData (com.sldeditor.common.vendoroption.VersionData)4