-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev/features/ComplexElement' into develop
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ru.jaxptoobjects; | ||
|
||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public abstract class BaseComplexElement extends BaseElement implements ComplexElement { | ||
|
||
private List<Node> elements; | ||
private List<String> namesChildren; | ||
|
||
|
||
public BaseComplexElement(Node node) { | ||
super(node); | ||
elements = new ArrayList(); | ||
namesChildren = new ArrayList(); | ||
NodeList elements = node.getChildNodes(); | ||
for (int i = 0; i < elements.getLength(); i++) { | ||
if (elements.item(i).getNodeType() == Node.ELEMENT_NODE) { | ||
this.elements.add(elements.item(i)); | ||
namesChildren.add(elements.item(i).getNodeName()); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Node getElement(String elementName) { | ||
for (Node element: elements) { | ||
if (element.getNodeName().equals(elementName)) { | ||
return element; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public List<Node> getElementList(String elementName) { | ||
List<Node> elements = new ArrayList(); | ||
for (Node element: this.elements) { | ||
if (element.getNodeName().equals(elementName)) { | ||
elements.add(element); | ||
} | ||
} | ||
return elements; | ||
} | ||
|
||
@Override | ||
public boolean hasElement(String elementName) { | ||
return getElement(elementName) != null; | ||
} | ||
|
||
@Override | ||
public List<String> getNamesChildren() { | ||
return namesChildren; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ru.jaxptoobjects; | ||
|
||
import org.w3c.dom.Node; | ||
|
||
import java.util.List; | ||
|
||
public interface ComplexElement extends Element { | ||
public Node getElement(String elementName); | ||
public List<Node> getElementList(String elementName); | ||
public boolean hasElement(String elementName); | ||
public List<String> getNamesChildren(); | ||
} |