use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class BatchUpdateFontUtils method containsFonts.
/**
* Contains font details.
*
* @param sldData the sld data
* @return the scale sld data
*/
public static List<BatchUpdateFontData> containsFonts(SLDDataInterface sldData) {
List<BatchUpdateFontData> dataList = null;
if (sldData != null) {
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
if (sld != null) {
List<StyledLayer> styledLayerList = sld.layers();
if (sld != null) {
for (StyledLayer styledLayer : styledLayerList) {
if (styledLayer instanceof NamedLayerImpl) {
NamedLayerImpl namedLayerImpl = (NamedLayerImpl) styledLayer;
for (Style style : namedLayerImpl.styles()) {
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
for (Rule rule : fts.rules()) {
for (Symbolizer symbolizer : rule.symbolizers()) {
if (symbolizer instanceof TextSymbolizer) {
TextSymbolizer textSymbol = (TextSymbolizer) symbolizer;
Font font = textSymbol.getFont();
if (font != null) {
if (dataList == null) {
dataList = new ArrayList<BatchUpdateFontData>();
}
BatchUpdateFontData fontSLDData = new BatchUpdateFontData(sld, sldData);
fontSLDData.setNamedLayer(namedLayerImpl.getName());
fontSLDData.setFeatureTypeStyle(fts.getName());
fontSLDData.setStyle(style.getName());
fontSLDData.setRule(rule);
fontSLDData.setSymbolizer(textSymbol);
fontSLDData.setFont(font);
dataList.add(fontSLDData);
}
}
}
}
}
}
}
}
}
}
}
return dataList;
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class LegendTool method saveAllLegendToFolder.
/**
* Save all legend to folder.
*
* @param destinationFolder the destination folder
*/
private void saveAllLegendToFolder(File destinationFolder) {
if (!destinationFolder.exists()) {
destinationFolder.mkdirs();
}
logger.info(Localisation.getString(LegendTool.class, "LegendTool.saveAllLayerLegends"));
for (SLDDataInterface sldData : sldDataList) {
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
if (sld != null) {
String heading = null;
String filename = null;
String layerName = sldData.getLayerNameWithOutSuffix();
List<String> filenameList = new ArrayList<String>();
LegendManager.getInstance().saveLegendImage(sld, destinationFolder, layerName, heading, filename, filenameList);
}
}
}
use of org.geotools.styling.StyledLayerDescriptor in project sldeditor by robward-scisys.
the class ExportHTML method save.
/**
* Save all html to folder.
*
* @param destinationFolder the destination folder
* @param filename the filename
* @param sldDataList the sld data list
* @param backgroundColour the background colour
*/
public static void save(File destinationFolder, String filename, List<SLDDataInterface> sldDataList, Color backgroundColour) {
if (!destinationFolder.exists()) {
destinationFolder.mkdirs();
}
InputStream inputStream = ExportHTML.class.getResourceAsStream(HTML_TEMPLATE);
if (inputStream == null) {
ConsoleManager.getInstance().error(ExportHTML.class, "Failed to find html template");
} else {
String htmlTemplate = null;
BufferedReader reader = null;
File file = null;
try {
file = stream2file(inputStream);
reader = new BufferedReader(new FileReader(file));
String line = null;
StringBuilder stringBuilder = new StringBuilder();
String ls = System.getProperty("line.separator");
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append(ls);
}
htmlTemplate = stringBuilder.toString();
} catch (Exception e) {
ConsoleManager.getInstance().exception(ExportHTML.class, e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
ConsoleManager.getInstance().exception(ExportHTML.class, e);
}
}
}
StringBuilder sb = new StringBuilder();
sb.append(" <tr>\n");
sb.append(" <th>Layer Name</th>\n");
sb.append(" <th>Legend</th>\n");
sb.append(" </tr>\n");
for (SLDDataInterface sldData : sldDataList) {
StyleWrapper styleWrapper = sldData.getStyle();
String layerName = styleWrapper.getStyle();
sb.append(" <tr>\n");
sb.append(String.format(" <td>%s</td>\n", layerName));
StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);
if (sld != null) {
String showHeading = null;
String showFilename = null;
List<String> legendFileNameList = new ArrayList<String>();
boolean result = LegendManager.getInstance().saveLegendImage(sld, destinationFolder, layerName, showHeading, showFilename, legendFileNameList);
if (result) {
String legendFilename = legendFileNameList.get(0);
sb.append(String.format(" <td><img src=\"%s\" alt=\"%s\" ></td>\n", legendFilename, layerName));
}
}
sb.append(" </tr>\n");
}
if (htmlTemplate != null) {
htmlTemplate = htmlTemplate.replace(TEMPLATE_INSERT_CODE, sb.toString());
PrintWriter out;
try {
File f = new File(destinationFolder, filename);
out = new PrintWriter(f);
out.println(htmlTemplate);
out.close();
} catch (FileNotFoundException e) {
ConsoleManager.getInstance().exception(ExportHTML.class, e);
}
}
if (file != null) {
file.delete();
}
}
}
use of org.geotools.styling.StyledLayerDescriptor 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;
}
use of org.geotools.styling.StyledLayerDescriptor 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;
}
Aggregations