Skip to content

Commit

Permalink
Merge branch 'dev/features/ComplexElement' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Rillde committed Jun 10, 2023
2 parents e818dc3 + 226cd70 commit c761123
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/main/java/ru/jaxptoobjects/BaseComplexElement.java
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;
}

}
12 changes: 12 additions & 0 deletions src/main/java/ru/jaxptoobjects/ComplexElement.java
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();
}

0 comments on commit c761123

Please sign in to comment.