[Schmitzm-commits] r188 - trunk/src/schmitzm/jfree/chart/style

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jul 3 17:17:22 CEST 2009


Author: mojays
Date: 2009-07-03 17:17:21 +0200 (Fri, 03 Jul 2009)
New Revision: 188

Modified:
   trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java
Log:
ChartStyleUtil: read style from URL

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java	2009-07-03 14:57:50 UTC (rev 187)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleUtil.java	2009-07-03 15:17:21 UTC (rev 188)
@@ -12,17 +12,23 @@
 package schmitzm.jfree.chart.style;
 
 import java.awt.Paint;
+import java.io.IOException;
+import java.net.URL;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
 import java.util.List;
 import java.util.Random;
 
+import org.jdom.Document;
 import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.ui.RectangleInsets;
 
 
+import schmitzm.io.IOUtil;
 import schmitzm.jfree.chart.style.ChartStyle.ChartType;
 import schmitzm.lang.LangUtil;
 import schmitzm.swing.SwingUtil;
@@ -34,8 +40,33 @@
  * @version 1.0
  */
 public class ChartStyleUtil {
-  
+  private static final SAXBuilder SAX_BUILDER = new SAXBuilder();
+
   /**
+   * Reads a chart definition from {@link URL}. The URL must refers to
+   * a resource which contains exactly one chart definition as root element.<br>
+   * <b>The filename is taken as chart ID</b>
+   * @param url refers to XML resource
+   */
+  public static ChartStyle readStyleFromXML(URL url) throws IOException, JDOMException {
+    String id = IOUtil.urlToFile(url).getName();
+    return readStyleFromXML(url, id);
+  }
+
+  /**
+   * Reads a chart definition from {@link URL}. The URL must refers to
+   * a resource which contains exactly one chart definition as root element.
+   * @param url refers to XML resource
+   * @param id  the ID for the style (if {@code null} the
+   *            ID is taken from "id" attribute)
+   */
+  public static ChartStyle readStyleFromXML(URL url, String id) throws IOException, JDOMException {
+    Document document = SAX_BUILDER.build(url);
+    
+    return( createStyleFromXML(document.getRootElement(),null) );
+  }
+
+  /**
    * Reads a chart definition from XML element. The chart style ID
    * is taken from "id" attribute.
    * @param element the XML element



More information about the Schmitzm-commits mailing list