Revision: 5999
http://sourceforge.net/p/jump-pilot/code/5999
Author: ma15569
Date: 2018-11-30 14:07:27 +0000 (Fri, 30 Nov 2018)
Log Message:
-----------
Added methods to save/load symbology.
Modified Paths:
--------------
core/trunk/src/org/openjump/core/apitools/IOTools.java
Modified: core/trunk/src/org/openjump/core/apitools/IOTools.java
===================================================================
--- core/trunk/src/org/openjump/core/apitools/IOTools.java 2018-11-30
14:02:52 UTC (rev 5998)
+++ core/trunk/src/org/openjump/core/apitools/IOTools.java 2018-11-30
14:07:27 UTC (rev 5999)
@@ -14,25 +14,59 @@
package org.openjump.core.apitools;
+import static
com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn.get;
+import static javax.xml.parsers.DocumentBuilderFactory.newInstance;
+
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
import java.io.OutputStreamWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Vector;
+import java.util.regex.Pattern;
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
import javax.swing.JTable;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import org.apache.commons.lang3.StringUtils;
import org.geotools.dbffile.DbfFieldDef;
import org.geotools.dbffile.DbfFile;
import org.geotools.dbffile.DbfFileWriter;
+import org.openjump.core.ccordsys.srid.SRIDStyle;
+import org.openjump.core.ui.plugin.file.open.JFCWithEnterAction;
+import org.openjump.core.ui.plugin.style.ImportSLDPlugIn;
import org.openjump.core.ui.util.ScreenScale;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jump.I18N;
@@ -50,10 +84,18 @@
import com.vividsolutions.jump.io.WKTReader;
import com.vividsolutions.jump.io.datasource.DataSource;
import com.vividsolutions.jump.io.datasource.DataSourceQuery;
+import com.vividsolutions.jump.util.Blackboard;
import com.vividsolutions.jump.util.java2xml.Java2XML;
+import com.vividsolutions.jump.util.java2xml.XML2Java;
import com.vividsolutions.jump.workbench.JUMPWorkbench;
+import com.vividsolutions.jump.workbench.Logger;
import com.vividsolutions.jump.workbench.model.Layer;
import com.vividsolutions.jump.workbench.model.LayerManager;
+import com.vividsolutions.jump.workbench.plugin.PlugInContext;
+import com.vividsolutions.jump.workbench.ui.GUIUtil;
+import com.vividsolutions.jump.workbench.ui.MultiInputDialog;
+import com.vividsolutions.jump.workbench.ui.WorkbenchFrame;
+import com.vividsolutions.jump.workbench.ui.renderer.style.Style;
import de.latlon.deejump.plugin.style.LayerStyle2SLDPlugIn;
@@ -507,4 +549,634 @@
}
}
+ /**
+ * Method to save Openjump symbology of a layer to a XML file
+ *
+ *
+ * @param style
+ * file to save (ex. file.style.xml)
+ * @param layer
+ * source layer
+ * @throws Exception
+ */
+
+ public static void saveSimbology_Jump(File file, Layer layer)
+ throws Exception {
+ final StringWriter stringWriter = new StringWriter();
+ try {
+
+ new Java2XML().write(layer, "layer", stringWriter);
+ } finally {
+ stringWriter.flush();
+ }
+
+ final DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory
+ .newInstance();
+ final DocumentBuilder documentBuilder = documentBuilderFactory
+ .newDocumentBuilder();
+ final InputSource is = new InputSource(new StringReader(
+ stringWriter.toString()));
+ final Document document = documentBuilder.parse(is);
+ // Remove all other elements than <Styles> from XML
+ removeElements(document);
+
+ document.normalize();
+ //Write the style.xml file
+ final DOMSource source = new DOMSource(document);
+ final FileWriter writer = new FileWriter(new File(
+ file.getAbsolutePath()));
+ final StreamResult result = new StreamResult(writer);
+ final TransformerFactory transformerFactory = TransformerFactory
+ .newInstance();
+ final Transformer transformer = transformerFactory.newTransformer();
+ transformer.transform(source, result);
+
+ //define the folder for possible pictures used as vertex symbols
+ final Pattern ext = Pattern.compile("(?<=.)\\.[^.]+$");
+ final String folder = ext.matcher(file.getAbsolutePath())
+ .replaceAll("");
+
+ //Create a list of pictures
+ final List<String> listPictures = getListOfElements(document);
+
+ if (!listPictures.isEmpty()) {
+ new File(folder).mkdir();
+ //copy pictures into the folder
+ for (final String str : listPictures) {
+ final File inputFile = new File(
+ convertPathToSystemIndependentPath(str));
+ copyFileToFolder(inputFile, new
File(folder).getAbsolutePath());
+ }
+
+ //save a list of original paths of the pictures as txt file
+ try {
+ final OutputStreamWriter wrt = new OutputStreamWriter(
+ new FileOutputStream(new File(folder).getAbsolutePath()
+ .concat(File.separator).concat("picture.txt")),
+ StandardCharsets.UTF_8);
+ String listString = "";
+ for (final String s : listPictures) {
+ listString += s + System.getProperty("line.separator");
+ }
+ wrt.write(listString);
+ wrt.close();
+
+ } catch (final IOException i) {
+ }
+ }
+ }
+
+ /**
+ * Simple method to copy a file to a folder
+ * @param inputFile
+ * @param outputDir
+ * @throws IOException
+ */
+ public static void copyFileToFolder(File inputFile, String outputDir)
+ throws IOException {
+ final File directoryFile = new File(outputDir);
+ if (directoryFile.canRead()) {
+ final File outFile = new File(outputDir.concat(File.separator)
+ .concat(inputFile.getName()));
+ FileChannel inputChannel = null;
+ FileChannel outputChannel = null;
+ try {
+ inputChannel = new FileInputStream(inputFile).getChannel();
+ outputChannel = new FileOutputStream(outFile).getChannel();
+ outputChannel
+ .transferFrom(inputChannel, 0, inputChannel.size());
+ } finally {
+ inputChannel.close();
+ outputChannel.close();
+ }
+ }
+ }
+
+ /**
+ * Converts a system-dependent path into an independent one
+ *
+ * @param oldPath
+ * @return newPath
+ */
+ public static String convertPathToSystemIndependentPath(String oldPath) {
+ final String path = Paths.get(oldPath).toUri().getPath();
+ return path;
+
+ }
+
+ /**
+ * filter all elements to remove all tags except symbology ones
+ * used by Save To JUMP Symbology method
+ */
+ private static void removeElements(Node parent) {
+ final NodeList children = parent.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ final Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ if (child.getNodeName().equals("description")
+ || child.getNodeName().equals("data-source-query")
+ || child.getNodeName().equals(
+ "feature-schema-operation")) {
+
+ parent.removeChild(child);
+ while (child.hasChildNodes()) {
+ child.removeChild(child.getFirstChild());
+ }
+
+ } else {
+ removeElements(child);
+ }
+ final Element eElement = (Element) child;
+ if (eElement.getAttribute("class").contains(
+ "org.openjump.core.ccordsys.srid.SRIDStyle")) {
+
+ parent.removeChild(child);
+ while (child.hasChildNodes()) {
+ child.removeChild(child.getFirstChild());
+ }
+ }
+ }
+ }
+
+ }
+
+ /**
+ * get a list of urls of pictures used as vertex symbols
+ * search into <style> and <vertex-style> elements
+ * used by Save To JUMP Symbology method
+ * @param parent
+ * @return List
+ */
+ private static List<String> getListOfElements(Node parent) {
+ final NodeList children = ((Document) parent).getDocumentElement()
+ .getElementsByTagName("style");
+ final LinkedHashSet<String> uniqueStrings = new
LinkedHashSet<String>();
+ for (int i = 0; i < children.getLength(); i++) {
+ final Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ final Element eElement = (Element) child;
+ if (!eElement.getAttribute("imageURL").isEmpty()) {
+ final String url = eElement.getAttribute("imageURL");
+ uniqueStrings.add(url);
+ }
+ }
+ }
+ final NodeList children1 = ((Document) parent).getDocumentElement()
+ .getElementsByTagName("vertex-style");
+ for (int i = 0; i < children1.getLength(); i++) {
+ final Node child = children1.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ final Element eElement = (Element) child;
+ if (!eElement.getAttribute("imageURL").isEmpty()) {
+ final String url = eElement.getAttribute("imageURL");
+ uniqueStrings.add(url);
+ }
+ }
+ }
+ final List<String> asList = new ArrayList<String>(uniqueStrings);
+ return asList;
+ }
+
+ /**
+ * check if in the XML file there are nodes with attributes as "imageURL"
+ * used by Load JUMP Symbology method
+ * @param file
+ * @return
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ * @throws TransformerException
+ */
+
+ private static boolean imageURLExist(File file)
+ throws ParserConfigurationException, SAXException, IOException,
+ TransformerException {
+
+ final DocumentBuilderFactory dbFactory = DocumentBuilderFactory
+ .newInstance();
+ final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+ final Document doc = dBuilder.parse(file);
+ final LinkedHashSet<String> uniqueStrings = new
LinkedHashSet<String>();
+ final NodeList children = doc.getDocumentElement()
+ .getElementsByTagName("style");
+ final NodeList children1 = doc.getDocumentElement()
+ .getElementsByTagName("vertex-style");
+ for (int i = 0; i < children.getLength(); i++) {
+ final Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ final Element eElement = (Element) child;
+ if (!eElement.getAttribute("imageURL").isEmpty()) {
+ final String url = eElement.getAttribute("imageURL");
+
+ uniqueStrings.add(url);
+
+ }
+ }
+ }
+
+ for (int i = 0; i < children1.getLength(); i++) {
+ final Node child = children1.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ final Element eElement = (Element) child;
+ if (!eElement.getAttribute("imageURL").isEmpty()) {
+ final String url = eElement.getAttribute("imageURL");
+
+ uniqueStrings.add(url);
+
+ }
+ }
+ }
+ if (uniqueStrings.isEmpty()) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
+
+ * This method will recompile the XML file according to location (folder)
of the image symbology files
+ * used by Load JUMP Symbology method
+ * @param xml.
+ * XML file
+ * @param directory.
+ * Folder where the images are stored
+ * @return File
+ * @throws ParserConfigurationException
+ * @throws SAXException
+ * @throws IOException
+ * @throws TransformerException
+ */
+ public static File recompileXMLFile(File file, String directory)
+ throws ParserConfigurationException, SAXException, IOException,
+ TransformerException {
+ final DocumentBuilderFactory dbFactory = DocumentBuilderFactory
+ .newInstance();
+ final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+ final Document doc = dBuilder.parse(file);
+ final NodeList children = doc.getDocumentElement()
+ .getElementsByTagName("style");
+ for (int i = 0; i < children.getLength(); i++) {
+ final Node child = children.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ final Element eElement = (Element) child;
+ if (!eElement.getAttribute("imageURL").isEmpty()) {
+ final String url =
convertPathToSystemIndependentPath(eElement
+ .getAttribute("imageURL"));
+ final String name = new File(url).getName();
+ final String newNamePath = directory.concat(File.separator)
+ .concat(name);
+ eElement.setAttribute("imageURL", newNamePath);
+ }
+ }
+ }
+ final NodeList children1 = doc.getDocumentElement()
+ .getElementsByTagName("vertex-style");
+ for (int i = 0; i < children1.getLength(); i++) {
+ final Node child = children1.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ final Element eElement = (Element) child;
+ if (!eElement.getAttribute("imageURL").isEmpty()) {
+ final String url =
convertPathToSystemIndependentPath(eElement
+ .getAttribute("imageURL"));
+ final String name = new File(url).getName();
+ final String newNamePath = directory.concat(File.separator)
+ .concat(name);
+ eElement.setAttribute("imageURL", newNamePath);
+ }
+ }
+ }
+ final Transformer transformer = TransformerFactory.newInstance()
+ .newTransformer();
+ final DOMSource input = new DOMSource(doc);
+ final File outFile = new File(file.getAbsolutePath());
+ final StreamResult output = new StreamResult(outFile);
+ transformer.transform(input, output);
+ return outFile;
+ }
+
+ /**
+ * Method to load an OpenJUMP symbology file (xml jump) into a layer
+ *
+ * @param style
+ * file to load (ex. file.style.xml)
+ * @param layer
+ * target layer
+ * @throws Exception
+ */
+ public static void loadSimbology_Jump(File file, Layer layer)
+ throws Exception {
+ final WorkbenchFrame workbenchFrame = JUMPWorkbench.getInstance()
+ .getFrame();
+ File recompiled = null;
+ //Check if the xml file contains urls for vertex bitmaps.
+ //if not, there is no need to recompile the file
+ if (!imageURLExist(file)) {
+ recompiled = file;
+ } else {
+ final Pattern ext = Pattern.compile("(?<=.)\\.[^.]+$");
+ final String folder = ext.matcher(file.getAbsolutePath())
+ .replaceAll("");
+ final File fold = new File(folder);
+ //If the folder, with the same name of the xml file, containing
vertex bitmaps, exist
+ //It is automatically loaded to recompile XML file
+ if (fold.exists() && fold.isDirectory()) {
+ recompiled = recompileXMLFile(file, fold.getAbsolutePath());
+ } else {
+ // If the folder is not automatically found
+ // a filechooser is open to select that dolder
+ final JFCWithEnterAction chooser = new JFCWithEnterAction();
+ chooser.setCurrentDirectory(new java.io.File("."));
+ chooser.setDialogTitle("Select folder where vertex images are
located");
+ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+
+ chooser.setAcceptAllFileFilterUsed(false);
+ if (chooser.showOpenDialog(JUMPWorkbench.getInstance()
+ .getFrame()) == JFileChooser.APPROVE_OPTION) {
+ recompiled = recompileXMLFile(file, chooser
+ .getSelectedFile().getAbsolutePath());
+ } else {
+ //Last choice, load any possible symbology from XML file
and
+ //warning to user that some symbols could be not loaded
+ recompiled = file;
+
+ workbenchFrame.getContext().getLayerViewPanel()
+ .getContext()
+ .warnUser("Some styles could not be loaded");
+ }
+ }
+ }
+ final FileReader reader = new FileReader(recompiled);
+
+ try {
+ final Layer sourceLayer = (Layer) new XML2Java(workbenchFrame
+ .getContext().getWorkbench().getPlugInManager()
+ .getClassLoader()).read(reader, Layer.class);
+ final Collection<Style> styleColection = sourceLayer.getStyles();
+ final ArrayList<Style> names = new ArrayList<Style>();
+ for (final Style style2 : styleColection) {
+ names.add(style2);
+ if (style2 instanceof SRIDStyle) {
+ names.remove(style2);
+ }
+ }
+ try {
+ layer.setStyles(names);
+ } catch (final Exception e) {
+ Logger.error(e);
+ final String errorMessage = "Error on loading symbols. Try to
do it manually"; //$NON-NLS-1$
+ JOptionPane.showMessageDialog(
+ workbenchFrame.getActiveInternalFrame(), errorMessage,
+ "Error", JOptionPane.ERROR_MESSAGE);
+ }
+ } finally {
+ reader.close();
+ }
+ }
+
+ /**
+ * Method to load a style file ( SLD - Spatial layer descriptor) into a
+ * layer
+ *
+ * @param style
+ * file to load (ex. file.sld)
+ * @param layer
+ * target layer
+ * @throws Exception
+ */
+
+ public static void loadSimbology_SLD(File file, PlugInContext context)
+ throws SAXException, IOException, ParserConfigurationException {
+ final Blackboard bb = get(JUMPWorkbench.getInstance().getFrame()
+ .getContext());
+ bb.put("ImportSLDPlugin.filename", file.getAbsoluteFile().toString());
+ final DocumentBuilderFactory dbf = newInstance();
+ dbf.setNamespaceAware(true);
+
+ final Document doc = dbf.newDocumentBuilder().parse(file);
+ try {
+ ImportSLDPlugIn.importSLD(doc, context);
+ } catch (final Exception e) {
+ Logger.error(e);
+ }
+
+ }
+
+ /**
+ * Method to save the style of a layer as SLD (Spatial layer
+ * descriptor) file
+ *
+ * @param style
+ * file to save (ex. file.style.sld)
+ * @param layer
+ * source layer
+ * @throws Exception
+ */
+ public static void saveSimbology_SLD(File file, Layer layer)
+ throws Exception {
+
+ final double internalScale = 1d / JUMPWorkbench.getInstance()
+ .getFrame().getContext().getLayerViewPanel().getViewport()
+ .getScale();
+ final double realScale = ScreenScale
+ .getHorizontalMapScale(JUMPWorkbench.getInstance().getFrame()
+ .getContext().getLayerViewPanel().getViewport());
+ final double scaleFactor = internalScale / realScale;
+
+ final File inputXML = File.createTempFile("temptask", ".xml");
+ inputXML.deleteOnExit();
+ final String name = layer.getName();
+ // TODO don't assume has 1 item!!!
+ // Should create this condition in EnableCheckFactory
+ if (layer.getFeatureCollectionWrapper().getFeatures().size() == 0) {
+ throw new Exception(
+
I18N.get("org.openjump.core.ui.plugin.tools.statistics.StatisticOverViewPlugIn.Selected-layer-is-empty"));
+ }
+ final BasicFeature bf = (BasicFeature) layer
+ .getFeatureCollectionWrapper().getFeatures().get(0);
+ final Geometry geo = bf.getGeometry();
+ final String geoType = geo.getGeometryType();
+ final Java2XML java2Xml = new Java2XML();
+ java2Xml.write(layer, "layer", inputXML);
+ final FileInputStream input = new FileInputStream(inputXML);
+ // FileWriter fw = new FileWriter( outputXML );
+ final OutputStreamWriter fw = new OutputStreamWriter(
+ new FileOutputStream(file), Charset.defaultCharset());
+ // "UTF-8");
+ final HashMap<String, String> map = new HashMap<String, String>(9);
+ map.put("wmsLayerName", name);
+ map.put("featureTypeStyle", name);
+ map.put("styleName", name);
+ map.put("styleTitle", name);
+ map.put("geoType", geoType);
+ map.put("geomProperty", I18N
+
.get("deejump.pluging.style.LayerStyle2SLDPlugIn.geomProperty"));
+ map.put("Namespace", "http://www.deegree.org/app");
+ // map.put("NamespacePrefix", prefix + ":");
+ // map.put("NamespacePrefixWithoutColon", prefix);
+ // ATTENTION : note that min and max are swapped in JUMP!!!
+ // It will swap later, in transformContext
+ Double d = layer.getMinScale();
+ d = d != null ? d : new Double(0);
+ map.put("minScale",
+ ""
+ + LayerStyle2SLDPlugIn.toRealWorldScale(scaleFactor,
+ d.doubleValue()));
+ // using Double.MAX_VALUE is creating a large number - too many 0's
+ // make it simple and hardcode a large number
+ final double largeNumber = 99999999999d;
+ d = layer.getMaxScale();
+ d = d != null ? d : new Double(largeNumber);
+ map.put("maxScale",
+ ""
+ + LayerStyle2SLDPlugIn.toRealWorldScale(scaleFactor,
+ d.doubleValue()));
+ fw.write(LayerStyle2SLDPlugIn.transformContext(input, map));
+ fw.close();
+ }
+
+ public static void saveSimbology_SLD2(File file, Layer layer)
+ throws Exception {
+ final String name = layer.getName();
+ final BasicFeature bf = (BasicFeature) layer
+ .getFeatureCollectionWrapper().getFeatures().get(0);
+ final Geometry geo = bf.getGeometry();
+ final String geoType = geo.getGeometryType();
+ final MultiInputDialog dialog = new MultiInputDialog(
+ JUMPWorkbench.getInstance().getFrame(),
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.SLD-Parameters"),
+ true);
+ String geomProperty = "GEOM";
+
+ final FeatureSchema schema = layer.getFeatureCollectionWrapper()
+ .getFeatureSchema();
+ for (int i = 0; i < schema.getAttributeCount(); ++i) {
+ if (schema.getAttributeType(i) == AttributeType.GEOMETRY) {
+ geomProperty = schema.getAttributeName(i);
+ }
+ }
+ dialog.addSeparator();
+
+ dialog.addTextField(
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.geomProperty"),
+ geomProperty,
+ 25,
+ null,
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.Input-the-name-of-the-geometry-property"));
+
+ dialog.addSeparator();
+
+ dialog.addTextField(
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.WMS-Layer-name"),
+ name,
+ 25,
+ null,
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.WMS-Layer-name"));
+ dialog.addTextField(
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.Style-name"),
+ name,
+ 25,
+ null,
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.Style-name"));
+ dialog.addTextField(
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.Style-title"),
+ name,
+ 25,
+ null,
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.Style-title"));
+ dialog.addTextField(
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.Feature-Type-Style"),
+ name,
+ 25,
+ null,
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.Feature-Type-Style"));
+ dialog.addTextField(
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.Namespace"),
+ "http://www.deegree.org/app",
+ 25,
+ null,
+
I18N.get("deejump.pluging.style.LayerStyle2SLDPlugIn.Namespace"));
+ GUIUtil.centreOnWindow(dialog);
+
+ dialog.setVisible(true);
+
+ if (!dialog.wasOKPressed()) {
+ return;
+ }
+
+ // why the field name given when constructing the dialog are used both
+ // for the label and
+ // for the key is beyond me
+ final String wmsLayerName = dialog
+ .getText(I18N
+
.get("deejump.pluging.style.LayerStyle2SLDPlugIn.WMS-Layer-name"));
+ final String styleName = dialog.getText(I18N
+ .get("deejump.pluging.style.LayerStyle2SLDPlugIn.Style-name"));
+ final String styleTitle = dialog.getText(I18N
+
.get("deejump.pluging.style.LayerStyle2SLDPlugIn.Style-title"));
+ final String featureTypeStyle = dialog
+ .getText(I18N
+
.get("deejump.pluging.style.LayerStyle2SLDPlugIn.Feature-Type-Style"));
+ geomProperty = dialog
+ .getText(I18N
+
.get("deejump.pluging.style.LayerStyle2SLDPlugIn.geomProperty"));
+ final String namespace = dialog.getText(I18N
+ .get("deejump.pluging.style.LayerStyle2SLDPlugIn.Namespace"));
+
+ final double internalScale = 1d / JUMPWorkbench.getInstance()
+ .getFrame().getContext().getLayerViewPanel().getViewport()
+ .getScale();
+ final double realScale = ScreenScale
+ .getHorizontalMapScale(JUMPWorkbench.getInstance().getFrame()
+ .getContext().getLayerViewPanel().getViewport());
+ final double scaleFactor = internalScale / realScale;
+
+ final File inputXML = File.createTempFile("temptask", ".xml");
+ inputXML.deleteOnExit();
+
+ // TODO don't assume has 1 item!!!
+ // Should create this condition in EnableCheckFactory
+ if (layer.getFeatureCollectionWrapper().getFeatures().size() == 0) {
+ throw new Exception(
+
I18N.get("org.openjump.core.ui.plugin.tools.statistics.StatisticOverViewPlugIn.Selected-layer-is-empty"));
+ }
+
+ final Java2XML java2Xml = new Java2XML();
+ java2Xml.write(layer, "layer", inputXML);
+ final FileInputStream input = new FileInputStream(inputXML);
+ // FileWriter fw = new FileWriter( outputXML );
+ final OutputStreamWriter fw = new OutputStreamWriter(
+ new FileOutputStream(file), "UTF-8");//
Charset.defaultCharset());
+ // "UTF-8");
+ final HashMap<String, String> map = new HashMap<String, String>(9);
+ map.put("wmsLayerName", wmsLayerName);
+ map.put("featureTypeStyle", featureTypeStyle);
+ map.put("styleName", styleName);
+ map.put("styleTitle", styleTitle);
+ map.put("geoType", geoType);
+ map.put("geomProperty", geomProperty);
+ map.put("Namespace", namespace);
+ // map.put("NamespacePrefix", prefix + ":");
+ // map.put("NamespacePrefixWithoutColon", prefix);
+ // ATTENTION : note that min and max are swapped in JUMP!!!
+ // It will swap later, in transformContext
+ Double d = layer.getMinScale();
+ d = d != null ? d : new Double(0);
+ map.put("minScale",
+ ""
+ + LayerStyle2SLDPlugIn.toRealWorldScale(scaleFactor,
+ d.doubleValue()));
+ // using Double.MAX_VALUE is creating a large number - too many 0's
+ // make it simple and hardcode a large number
+ final double largeNumber = 99999999999d;
+ d = layer.getMaxScale();
+ d = d != null ? d : new Double(largeNumber);
+ map.put("maxScale",
+ ""
+ + LayerStyle2SLDPlugIn.toRealWorldScale(scaleFactor,
+ d.doubleValue()));
+ fw.write(LayerStyle2SLDPlugIn.transformContext(input, map));
+ fw.close();
+ }
+
}
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel