Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Wouters2013-12-10 09:08:16 +0000
committerLaurent Wouters2013-12-10 09:08:16 +0000
commit2abe3399f9a1776bfdaf31b6ac4d48634eb70996 (patch)
tree6b06c417545fdac0f742fda584adf9aeae988b60 /plugins
parentf142facfc5c2c5210882ee015946fa73cae09665 (diff)
downloadorg.eclipse.papyrus-2abe3399f9a1776bfdaf31b6ac4d48634eb70996.tar.gz
org.eclipse.papyrus-2abe3399f9a1776bfdaf31b6ac4d48634eb70996.tar.xz
org.eclipse.papyrus-2abe3399f9a1776bfdaf31b6ac4d48634eb70996.zip
Added a caching mechanism when loading SVG documents
Change-Id: I46b59528ef05969f3f4dba51d7f80152d0edb1cd Signed-off-by: Laurent Wouters <laurent.wouters@cea.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java
index 555f81d48a7..9f1bab11f65 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java
@@ -15,6 +15,8 @@ package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
import java.io.IOException;
import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.dom.util.DOMUtilities;
@@ -53,6 +55,9 @@ public abstract class AbstractShapeProvider extends AbstractProvider implements
/** description of the factory */
protected String description;
+ /** Cache for the loaded SVG document */
+ private Map<String, SVGDocument> cache;
+
/**
* Returns the bundle identifier for this provider
@@ -112,11 +117,31 @@ public abstract class AbstractShapeProvider extends AbstractProvider implements
}
/**
+ * Loads a SVG document from the given location.
+ * This method uses a cache so that any given document is only loaded once.
*
* @param location
+ * The location to load the document from
* @return the Document SVG from its location, can return null if this is not a svg
*/
protected SVGDocument getSVGDocument(String location) {
+ if (cache == null)
+ cache = new HashMap<String, SVGDocument>();
+ if (cache.containsKey(location))
+ return cache.get(location);
+ SVGDocument doc = doGetSVGDocument(location);
+ cache.put(location, doc);
+ return doc;
+ }
+
+ /**
+ * Loads a SVG document from the given location
+ *
+ * @param location
+ * The location to load the document from
+ * @return the Document SVG from its location, can return null if this is not a svg
+ */
+ private SVGDocument doGetSVGDocument(String location) {
int extensionIndex = location.lastIndexOf('.');
if(extensionIndex == 0) {
return null;

Back to the top