summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-16 22:54:55 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2011-09-16 22:54:55 +0000
commitd86305f890dcbb2ac296c0794228f2d2140cdd19 (patch)
tree2a528c5219322365dd9c07d27ad3e32ae3748744 /sca-java-2.x/trunk
parent6e4fab25b13f7af6b1b1fa766b111fd529a59490 (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')
-rw-r--r--sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/artifacts/Style.java30
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();