tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1171845 - /tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java
Date Fri, 16 Sep 2011 22:54:55 GMT
Author: rfeng
Date: Fri Sep 16 22:54:55 2011
New Revision: 1171845

URL: http://svn.apache.org/viewvc?rev=1171845&view=rev
Log:
Cache the css

Modified:
    tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java

Modified: tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java?rev=1171845&r1=1171844&r2=1171845&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java
Fri Sep 16 22:54:55 2011
@@ -32,7 +32,7 @@ import org.w3c.dom.Element;
  * CSS style element
  */
 public class Style {
-    private String css = "rect.composite {" + "          fill: #E5E5E5;"
+    private static final String DEFAULT_CSS = "rect.composite {" + "          fill: #E5E5E5;"
         + "          stroke: #919191;"
         + "          alignment-baseline: middle;"
         + "      }\n"
@@ -68,27 +68,33 @@ public class Style {
         + "        alignment-baseline: middle;"
         + "      }\n";
 
-    public Element addElement(Document document, String svgNs, String css) {
+    private static volatile String css;
+
+    public Element addElement(Document document, String svgNs, String styleSheet) {
 
         Element style = document.createElementNS(svgNs, "style");
         style.setAttributeNS(null, "type", "text/css");
 
-        if (css != null) {
-            this.css = css;
-        }
-        try {
-            this.css = readCSS();
-        } catch (IOException e) {
-            // Ignore
+        if (styleSheet == null) {
+            try {
+                if (css == null) {
+                    css = readCSS();
+                }
+            } catch (IOException e) {
+                // Ignore
+                css = DEFAULT_CSS;
+            }
+            styleSheet = css;
         }
-        CDATASection cdata = document.createCDATASection(this.css);
+
+        CDATASection cdata = document.createCDATASection(styleSheet);
         style.appendChild(cdata);
 
         return style;
     }
 
-    private String readCSS() throws IOException {
-        InputStream is = getClass().getResourceAsStream("composite-diagram.css");
+    private static String readCSS() throws IOException {
+        InputStream is = Style.class.getResourceAsStream("composite-diagram.css");
         InputStreamReader reader = new InputStreamReader(is, "UTF-8");
 
         StringWriter sw = new StringWriter();



Mime
View raw message