diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-16 22:54:55 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2011-09-16 22:54:55 +0000 |
commit | d86305f890dcbb2ac296c0794228f2d2140cdd19 (patch) | |
tree | 2a528c5219322365dd9c07d27ad3e32ae3748744 /sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache | |
parent | 6e4fab25b13f7af6b1b1fa766b111fd529a59490 (diff) |
Cache the css
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1171845 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache')
-rw-r--r-- | sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java index 6370358c9f..3467e5d9d0 100644 --- a/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java +++ b/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java @@ -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(); |