diff gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java @ 1070:7096a2e13676

Added functionality to publish the the mbr of the generated layer to the client. gnv-artifacts/trunk@1166 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 07 Jun 2010 14:42:42 +0000
parents 04967dc9c83f
children f953c9a559d8
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java	Mon Jun 07 12:22:00 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/MetaWriter.java	Mon Jun 07 14:42:42 2010 +0000
@@ -5,16 +5,18 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.text.DecimalFormat;
 import java.util.Date;
 
 import javax.xml.xpath.XPathConstants;
 
 import org.apache.log4j.Logger;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
+import com.vividsolutions.jts.geom.Envelope;
+
 import de.intevation.artifactdatabase.XMLUtils;
 import de.intevation.artifacts.ArtifactNamespaceContext;
 import de.intevation.artifacts.CallContext;
@@ -39,6 +41,7 @@
     public static final String META_FILE_NAME = "meta.xml";
 
     public static final String XPATH_META = "/art:meta";
+    public static final String XPATH_MAPSERVER = "art:meta/art:"+NODE_MAPSERVER;
 
     /**
      * Constructor.
@@ -133,7 +136,37 @@
         return true;
     }
 
+    /**
+     * Method to write the <i>meta</i> document down to a file.
+     *
+     * @param path The destination of the file.
+     * @param meta The xml document storing the meta information.
+     */
+    public static boolean insertMbr(Envelope mbr, String srs, Document meta) {
+        Node mapserverNode = (Node) XMLUtils.xpath(
+                meta,
+                XPATH_MAPSERVER,
+                XPathConstants.NODE,
+                ArtifactNamespaceContext.INSTANCE);
+        if (mapserverNode != null){
+            XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
+                    meta,
+                    ArtifactNamespaceContext.NAMESPACE_URI,
+                    ArtifactNamespaceContext.NAMESPACE_PREFIX);
+            Element bboxNode = creator.create("Box");
+            bboxNode.setAttribute("srsName", srs);
+            Element coordinateNode = creator.create("coordinates");
 
+            DecimalFormat formatter = new DecimalFormat("###.############");
+            coordinateNode.setTextContent(formatter.format(mbr.getMinX()).replace(',', '.') +","+ 
+                                          formatter.format(mbr.getMinY()).replace(',', '.')+" "+
+                                          formatter.format(mbr.getMaxX()).replace(',', '.') +","+ 
+                                          formatter.format(mbr.getMaxY()).replace(',', '.'));
+            mapserverNode.appendChild(bboxNode);
+            bboxNode.appendChild(coordinateNode);
+        }
+        return true;
+    }
     /**
      * Method to write the <i>meta</i> document down to a file.
      *

http://dive4elements.wald.intevation.org