Skip to content

Commit

Permalink
feat(#277): the problem in cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Dec 4, 2024
1 parent caf4e28 commit 8fcd3eb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/com/jcabi/xml/XMLDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import net.sf.saxon.trans.SymbolicName;
import net.sf.saxon.xpath.XPathFactoryImpl;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -126,7 +127,7 @@ public final class XMLDocument implements XML {
*/
public XMLDocument(final String text) {
this(
new DomParser(XMLDocument.configuredDFactory(), text).document(),
new DomParser(FACTORY, text).document(),
new XPathContext(),
false
);
Expand All @@ -152,7 +153,7 @@ public XMLDocument(final String text) {
*/
public XMLDocument(final byte[] data) {
this(
new DomParser(XMLDocument.configuredDFactory(), data).document(),
new DomParser(FACTORY, data).document(),
new XPathContext(),
false
);
Expand Down Expand Up @@ -202,8 +203,8 @@ public XMLDocument(final Source source) {
* @throws FileNotFoundException In case of I/O problems
*/
public XMLDocument(final File file) throws FileNotFoundException {
this(new TextResource(file).toString());
// this(new DomParser(XMLDocument.configuredDFactory(), file).document());
// this(new TextResource(file).toString());
this(new DomParser(FACTORY, file).document());
}

/**
Expand Down Expand Up @@ -322,7 +323,8 @@ public Node node() {
final Node casted = this.cache;
final Node answer;
if (casted instanceof Document) {
answer = casted.cloneNode(true);
answer = casted;
// answer = casted.cloneNode(true);
} else {
answer = XMLDocument.createImportedNode(casted);
}
Expand Down Expand Up @@ -478,7 +480,7 @@ public Collection<SAXParseException> validate(final Schema schema) {
* @return A cloned node imported in a dedicated document.
*/
private static Node createImportedNode(final Node node) {
final DocumentBuilderFactory factory = XMLDocument.configuredDFactory();
final DocumentBuilderFactory factory = FACTORY;
final DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
Expand Down Expand Up @@ -599,6 +601,8 @@ private static Node transform(final Source source) {
return result.getNode();
}

private static final DocumentBuilderFactory FACTORY = XMLDocument.configuredDFactory();

/**
* Create new {@link DocumentBuilderFactory} and configure it.
* @return Configured factory
Expand Down

0 comments on commit 8fcd3eb

Please sign in to comment.