]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2892; fix + test
authorChris Bowditch <cbowditch@apache.org>
Mon, 6 Jan 2020 14:44:14 +0000 (14:44 +0000)
committerChris Bowditch <cbowditch@apache.org>
Mon, 6 Jan 2020 14:44:14 +0000 (14:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1872384 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/configuration/DefaultConfiguration.java
fop-core/src/test/java/org/apache/fop/configuration/DefaultConfigurationTest.java [new file with mode: 0644]
fop-core/src/test/resources/org/apache/fop/configuration/sample_config.xml [new file with mode: 0644]

index 22f28a1703c61f5ab7c686447b9cc246cd96ec7f..b50fd8b1717bc2b7df6a182163cf8d7a6a21992a 100644 (file)
@@ -108,7 +108,7 @@ public class DefaultConfiguration implements Configuration {
 
     @Override
     public Configuration getChild(String key) {
-        NodeList nl = element.getElementsByTagName(key);
+        NodeList nl = element.getChildNodes();
         for (int i = 0; i < nl.getLength(); ++i) {
             Node n = nl.item(i);
             if (n.getNodeName().equals(key)) {
@@ -133,13 +133,15 @@ public class DefaultConfiguration implements Configuration {
 
     @Override
     public Configuration[] getChildren(String key) {
-        NodeList nl = element.getElementsByTagName(key);
-        Configuration[] result = new Configuration[nl.getLength()];
+        ArrayList<Configuration> result = new ArrayList<>(1);
+        NodeList nl = element.getChildNodes();
         for (int i = 0; i < nl.getLength(); ++i) {
             Node n = nl.item(i);
-            result[i] = new DefaultConfiguration((Element) n);
+            if (n.getNodeName().equals(key)) {
+                result.add(new DefaultConfiguration((Element) n));
+            }
         }
-        return result;
+        return result.toArray(new Configuration[0]);
     }
 
     @Override
diff --git a/fop-core/src/test/java/org/apache/fop/configuration/DefaultConfigurationTest.java b/fop-core/src/test/java/org/apache/fop/configuration/DefaultConfigurationTest.java
new file mode 100644 (file)
index 0000000..f25df7e
--- /dev/null
@@ -0,0 +1,47 @@
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements.  See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License.  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.apache.fop.configuration;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+public class DefaultConfigurationTest {\r
+\r
+    DefaultConfiguration configuration;\r
+\r
+    @Before\r
+    public void setup() throws Exception {\r
+        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();\r
+        configuration = builder.build(getClass().getResourceAsStream("sample_config.xml"));\r
+    }\r
+\r
+    @Test\r
+    public void testGetChild() {\r
+        Configuration fontsConfig = configuration.getChild("fonts");\r
+        assertEquals("fonts element should be direct child", "fop/fonts",  fontsConfig.getLocation());\r
+    }\r
+\r
+    @Test\r
+    public void testGetChildren() {\r
+        Configuration[] fontsConfig = configuration.getChildren("fonts");\r
+        assertEquals("only direct children should match", 1, fontsConfig.length);\r
+        assertEquals("fonts element should be direct child", "fop/fonts", fontsConfig[0].getLocation());\r
+    }\r
+}\r
diff --git a/fop-core/src/test/resources/org/apache/fop/configuration/sample_config.xml b/fop-core/src/test/resources/org/apache/fop/configuration/sample_config.xml
new file mode 100644 (file)
index 0000000..d3bc3e3
--- /dev/null
@@ -0,0 +1,20 @@
+<fop version="1.0">\r
+\r
+  <renderers>\r
+    <renderer mime="application/pdf">\r
+      <fonts> \r
+        <auto-detect/>\r
+      </fonts>\r
+    </renderer>\r
+  </renderers>\r
+\r
+  <!-- A substitution can map a font family to another. -->\r
+  <fonts>\r
+    <substitutions>  \r
+        <substitution>\r
+            <from font-family='courierNew' font-style='normal' font-weight='400'/>   <to font-family='Courier New'/> \r
+         </substitution> \r
+     </substitutions>\r
+  </fonts>\r
+\r
+</fop>
\ No newline at end of file