use of com.sldeditor.common.output.SLDWriterInterface in project sldeditor by robward-scisys.
the class YSLDToolTest method getSLDDataFile.
/**
* Gets the SLD/YSLD file.
*
* @param testfile the testfile
* @return the SLD data file
*/
private static SLDData getSLDDataFile(String testfile) {
SLDData sldData = null;
InputStream inputStream = YSLDToolTest.class.getResourceAsStream(testfile);
if (inputStream == null) {
Assert.assertNotNull("Failed to find test file : " + testfile, inputStream);
} else {
File f = null;
try {
String fileExtension = ExternalFilenames.getFileExtension(testfile);
f = stream2file(inputStream, ExternalFilenames.addFileExtensionSeparator(fileExtension));
String sldContents = readFile(f.getAbsolutePath());
if (fileExtension.compareTo("ysld") == 0) {
StyledLayerDescriptor sld = Ysld.parse(sldContents);
// Convert YSLD to SLD string
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
sldContents = sldWriter.encodeSLD(null, sld);
}
sldData = new SLDData(new StyleWrapper(f.getName()), sldContents);
sldData.setSLDFile(f);
SelectedSymbol.getInstance().setSld(SLDUtils.createSLDFromString(sldData));
} catch (IOException e1) {
e1.printStackTrace();
}
}
return sldData;
}
use of com.sldeditor.common.output.SLDWriterInterface in project sldeditor by robward-scisys.
the class YSLDTool method exportToSLD.
/**
* Export to SLD.
*/
private void exportToSLD() {
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD);
for (SLDDataInterface sldData : sldDataList) {
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
String layerName = sldData.getLayerNameWithOutSuffix();
if (sld != null) {
String sldString = sldWriter.encodeSLD(sldData.getResourceLocator(), sld);
String destinationFolder = sldData.getSLDFile().getParent();
File fileToSave = GenerateFilename.findUniqueName(destinationFolder, layerName, SLDEditorFile.getSLDFileExtension());
String sldFilename = fileToSave.getName();
if (fileToSave.exists()) {
ConsoleManager.getInstance().error(this, Localisation.getField(YSLDTool.class, "YSLDTool.destinationAlreadyExists") + " " + sldFilename);
} else {
ConsoleManager.getInstance().information(this, Localisation.getField(YSLDTool.class, "YSLDTool.exportToSLDMsg") + " " + sldFilename);
BufferedWriter out;
try {
out = new BufferedWriter(new FileWriter(fileToSave));
out.write(sldString);
out.close();
} catch (IOException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
}
}
}
use of com.sldeditor.common.output.SLDWriterInterface in project sldeditor by robward-scisys.
the class SLDTextArea method outputText.
/**
* Output text.
*/
private void outputText() {
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(outputFormat);
String encodedSLD = sldWriter.encodeSLD(resourceLocator, displayedSld);
sldSourceTextArea.setText(encodedSLD);
}
use of com.sldeditor.common.output.SLDWriterInterface in project sldeditor by robward-scisys.
the class SLDWriterFactoryTest method testCreateSLDWriter.
/**
* Test method for {@link com.sldeditor.common.output.impl.SLDWriterFactory#createWriter(java.lang.String)}.
*/
@Test
public void testCreateSLDWriter() {
SLDWriterInterface writer = SLDWriterFactory.createWriter(null);
assertNotNull(writer);
}
use of com.sldeditor.common.output.SLDWriterInterface in project sldeditor by robward-scisys.
the class GeoServerClientTest method testInitialiseWithValidConnection.
/**
* Only works if a default GeoServer instance is running
*
* <p>Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#initialise(com.sldeditor.extension.filesystem.geoserver.GeoServerReadProgressInterface, com.sldeditor.common.data.GeoServerConnection)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#retrieveData()}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#connect()}. Test
* method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getStyle(com.sldeditor.common.data.StyleWrapper)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getStyle(com.sldeditor.common.data.StyleWrapper)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#uploadSLD(com.sldeditor.common.data.StyleWrapper, java.lang.String)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#getWorkspaceList()}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#refreshWorkspace(java.lang.String)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#deleteStyle(com.sldeditor.common.data.StyleWrapper)}.
* Test method for
* {@link com.sldeditor.extension.filesystem.geoserver.client.GeoServerClient#disconnect()}.
*/
@Ignore
@Test
public void testInitialiseWithValidConnection() {
GeoServerClient client = new GeoServerClient();
TestProgressClass progress = new TestProgressClass();
client.initialise(progress, testConnection);
assertTrue(client.connect());
assertEquals(testConnection, client.getConnection());
List<String> actualWorkspaceList = client.getWorkspaceList();
assertTrue(actualWorkspaceList.size() > 0);
client.retrieveData();
int count = 0;
while (!progress.hasFinished() && count < 50) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
count++;
}
assertTrue(progress.hasFinished());
// CHECKSTYLE:OFF
int actualNoOfStyles = progress.styleTotal;
// CHECKSTYLE:ON
// Retrieve style
StyleWrapper styleWrapper = new StyleWrapper(client.getDefaultWorkspaceName(), "point");
String sldContents = client.getStyle(styleWrapper);
assertTrue(sldContents != null);
SLDData sldData = new SLDData(styleWrapper, sldContents);
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
assertEquals("default_point", sld.layers().get(0).getName());
// Upload as new style
String timeString = "" + System.currentTimeMillis();
String styleName = "New_Test_style_" + timeString;
styleWrapper.setStyle(styleName);
assertTrue(client.uploadSLD(styleWrapper, sldContents));
List<StyleWrapper> stylesToDeleteList = new ArrayList<StyleWrapper>();
stylesToDeleteList.add(styleWrapper.clone());
// Replace the existing style
StyledLayer styledLayer = sld.layers().get(0);
styledLayer.setName("test point sld");
SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(null);
String updatedSLDBody = sldWriter.encodeSLD(null, sld);
assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
// Change the workspace name - invalid
styleWrapper.setWorkspace("Test workspace");
assertFalse(client.uploadSLD(styleWrapper, updatedSLDBody));
// Change the workspace name - valid
String expectedWorkspace = "Test_workspace_" + timeString;
styleWrapper.setWorkspace(expectedWorkspace);
assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
stylesToDeleteList.add(styleWrapper.clone());
actualWorkspaceList = client.getWorkspaceList();
assertTrue(actualWorkspaceList.contains(expectedWorkspace));
// Update the contents
styledLayer.setName("updated test point sld");
updatedSLDBody = sldWriter.encodeSLD(null, sld);
assertTrue(client.uploadSLD(styleWrapper, updatedSLDBody));
// Check refresh workspace works
client.refreshWorkspace(client.getDefaultWorkspaceName());
count = 0;
while (!progress.hasFinished() && count < 50) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
count++;
}
assertTrue(progress.hasFinished());
assertEquals(actualNoOfStyles + 1, progress.styleTotal);
//
for (StyleWrapper styleToDelete : stylesToDeleteList) {
System.out.println("Deleting style : " + styleToDelete.getWorkspace() + "/" + styleToDelete.getStyle());
assertTrue(client.deleteStyle(styleToDelete));
}
assertFalse(client.deleteStyle(null));
assertFalse(client.deleteStyle(new StyleWrapper()));
StyleWrapper tmpStyle = styleWrapper.clone();
tmpStyle.setStyle("invalid");
assertFalse(client.deleteStyle(tmpStyle));
tmpStyle = styleWrapper.clone();
tmpStyle.setWorkspace("invalid");
assertFalse(client.deleteStyle(tmpStyle));
System.out.println("Deleting workspace : " + expectedWorkspace);
assertTrue(client.deleteWorkspace(expectedWorkspace));
client.disconnect();
assertFalse(client.isConnected());
}
Aggregations