@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)) {
@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
--- /dev/null
+/*\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