1. Project Clover database mar. janv. 20 2026 12:32:22 CET
  2. Package org.devacfr.maven.skins.reflow

File Xpp3Utils.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
22% of files have more coverage

Code metrics

12
21
4
1
113
52
10
0,48
5,25
4
2,5

Classes

Class Line # Actions
Xpp3Utils 34 21 0% 10 4
0.891891989,2%
 

Contributing tests

This file is covered by 30 tests. .

Source view

1    /*
2    * Copyright 2012-2025 Christophe Friederich
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16    package org.devacfr.maven.skins.reflow;
17   
18    import static java.util.Objects.requireNonNull;
19   
20    import com.google.common.collect.Lists;
21    import java.util.Collections;
22    import java.util.List;
23    import java.util.stream.Collectors;
24    import javax.annotation.Nonnull;
25    import javax.annotation.Nullable;
26    import org.codehaus.plexus.util.xml.Xpp3Dom;
27   
28    /**
29    * Utility class to manipulate {@link Xpp3Dom} model.
30    *
31    * @author Christophe Friederich
32    * @since 2.0
33    */
 
34    public final class Xpp3Utils {
35   
 
36  0 toggle private Xpp3Utils() {
37  0 throw new UnsupportedOperationException();
38    }
39   
40    /**
41    * Retrieves the child node. Tests both default name and with namespace.
42    *
43    * @param parentNode
44    * the parent node
45    * @param name
46    * the child name of node to get
47    * @param namespace
48    * the namespace (can be empty or {@code null}).
49    * @return Returns Returns {@link Xpp3Dom} representing the child of {@code parentNode} if exists, otherwise returns
50    * {@code null}.
51    */
 
52  1094 toggle @Nullable public static Xpp3Dom getFirstChild(@Nullable final Xpp3Dom parentNode,
53    @Nonnull final String name,
54    @Nonnull final String namespace) {
55  1094 if (parentNode == null) {
56  49 return null;
57    }
58  1045 requireNonNull(namespace);
59  1045 final Xpp3Dom child = parentNode.getChild(requireNonNull(name));
60  1045 if (child != null) {
61  459 return child;
62    }
63   
64  586 return parentNode.getChild(namespace + name);
65    }
66   
67    /**
68    * Gets the list of all children name for the {@code parentNode}.
69    *
70    * @param parentNode
71    * the parent node to use (can be {@code null}.
72    * @return Returns a list of {@link String} representing the name of all children, which may be empty but never
73    * {@code null}.
74    * @since 1.3
75    */
 
76  2 toggle @Nonnull
77    public static List<String> getChildren(@Nullable final Xpp3Dom parentNode) {
78  2 return getChildrenNodes(parentNode, null).stream().map(Xpp3Dom::getName).collect(Collectors.toList());
79    }
80   
81    /**
82    * Gets children list filtered by name of {@code parentNode}.
83    *
84    * @param parentNode
85    * the parent node to use.
86    * @param name
87    * the name of element to filter
88    * @return Returns a list of {@link Xpp3Dom} representing all children element filtered by {@code name} of
89    * {@code parentNode}.
90    */
 
91  53 toggle @Nonnull
92    public static List<Xpp3Dom> getChildrenNodes(@Nullable final Xpp3Dom parentNode, final String name) {
93  53 if (parentNode == null) {
94  2 return Collections.emptyList();
95    }
96  51 final Xpp3Dom[] children = parentNode.getChildren();
97  51 if (children == null) {
98  0 return Collections.emptyList();
99    }
100  51 final List<Xpp3Dom> list = Lists.newArrayListWithCapacity(children.length);
101  51 for (final Xpp3Dom child : children) {
102  66 if (name != null) {
103  56 if (name.equals(child.getName())) {
104  46 list.add(child);
105    }
106    } else {
107  10 list.add(child);
108    }
109    }
110   
111  51 return list;
112    }
113    }