diff --git a/scm-webapp/src/main/java/sonia/scm/cache/EhCacheConfigurationReader.java b/scm-webapp/src/main/java/sonia/scm/cache/EhCacheConfigurationReader.java index 66c5380ff3..bac0ced9a5 100644 --- a/scm-webapp/src/main/java/sonia/scm/cache/EhCacheConfigurationReader.java +++ b/scm-webapp/src/main/java/sonia/scm/cache/EhCacheConfigurationReader.java @@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -72,6 +73,7 @@ import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.w3c.dom.Attr; /** * @@ -291,7 +293,13 @@ public class EhCacheConfigurationReader Element rootEl = merged.createElementNS("http://ehcache.org/ehcache.xsd", "ehcache"); - for (Node node : map.values()) + for (Attr attribute : attributeMap.values()) + { + Attr mergedAttr = (Attr) merged.adoptNode(attribute); + rootEl.setAttributeNode(mergedAttr); + } + + for (Node node : nodeMap.values()) { Node mergedNode = merged.adoptNode(node); @@ -351,6 +359,23 @@ public class EhCacheConfigurationReader */ private void readConfiguration(Element rootEl) { + NamedNodeMap attributes = rootEl.getAttributes(); + + for (int i = 0; i < attributes.getLength(); i++) + { + Node node = attributes.item(i); + + if (Node.ATTRIBUTE_NODE == node.getNodeType()) + { + String name = node.getNodeName(); + + if (!name.startsWith("xmlns") && (node instanceof Attr)) + { + attributeMap.put(node.getNodeName(), (Attr) node); + } + } + } + NodeList list = rootEl.getChildNodes(); for (int i = 0; i < list.getLength(); i++) @@ -368,7 +393,7 @@ public class EhCacheConfigurationReader name = nameNode.getNodeValue(); } - map.put(new Id(element, name), node); + nodeMap.put(new Id(element, name), node); } } } @@ -473,5 +498,8 @@ public class EhCacheConfigurationReader private DocumentBuilder builder; /** Field description */ - private Map map = Maps.newLinkedHashMap(); + private Map nodeMap = Maps.newLinkedHashMap(); + + /** Field description */ + private Map attributeMap = Maps.newLinkedHashMap(); } diff --git a/scm-webapp/src/test/java/sonia/scm/cache/EhConfigurationReaderTest.java b/scm-webapp/src/test/java/sonia/scm/cache/EhConfigurationReaderTest.java index 9a87361831..c501d21076 100644 --- a/scm-webapp/src/test/java/sonia/scm/cache/EhConfigurationReaderTest.java +++ b/scm-webapp/src/test/java/sonia/scm/cache/EhConfigurationReaderTest.java @@ -84,6 +84,21 @@ public class EhConfigurationReaderTest } + /** + * Method description + * + */ + @Test + public void testGlobalAttributes() + { + EhConfigurationTestReader reader = + new EhConfigurationTestReader("cache.006.xml"); + Configuration c = createConfiguration(reader); + + assertFalse(c.getUpdateCheck()); + assertEquals("512M", c.getMaxBytesLocalDiskAsString()); + } + /** * Method description * @@ -175,6 +190,21 @@ public class EhConfigurationReaderTest checkDefaultConfiguration(c, 170l, 18900l); } + /** + * Method description + * + */ + @Test + public void testOverrideGlobalAttributes() + { + EhConfigurationTestReader reader = + new EhConfigurationTestReader("cache.006.xml", null, "cache.007.xml"); + Configuration c = createConfiguration(reader); + + assertTrue(c.getUpdateCheck()); + assertEquals("1G", c.getMaxBytesLocalDiskAsString()); + } + /** * Method description * diff --git a/scm-webapp/src/test/resources/sonia/scm/cache/cache.006.xml b/scm-webapp/src/test/resources/sonia/scm/cache/cache.006.xml new file mode 100644 index 0000000000..fab44312be --- /dev/null +++ b/scm-webapp/src/test/resources/sonia/scm/cache/cache.006.xml @@ -0,0 +1,38 @@ + + + + + + + diff --git a/scm-webapp/src/test/resources/sonia/scm/cache/cache.007.xml b/scm-webapp/src/test/resources/sonia/scm/cache/cache.007.xml new file mode 100644 index 0000000000..cc24dd3ca9 --- /dev/null +++ b/scm-webapp/src/test/resources/sonia/scm/cache/cache.007.xml @@ -0,0 +1,38 @@ + + + + + + +