-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Gerrit van Brakel
authored
Nov 10, 2020
1 parent
a7ae659
commit 8c108e0
Showing
4 changed files
with
207 additions
and
2 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
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,35 @@ | ||
/* | ||
Copyright 2020 WeAreFrank! | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package nl.nn.adapterframework.xml; | ||
|
||
import org.xml.sax.ContentHandler; | ||
|
||
public class XmlTap extends XmlTee { | ||
|
||
public XmlTap() { | ||
super(); | ||
setSecondContentHandler(new XmlWriter()); | ||
} | ||
|
||
public XmlTap(ContentHandler handler) { | ||
super(handler, new XmlWriter()); | ||
} | ||
|
||
public XmlWriter getWriter() { | ||
return (XmlWriter)getSecondContentHandler(); | ||
} | ||
|
||
} |
127 changes: 127 additions & 0 deletions
127
core/src/main/java/nl/nn/adapterframework/xml/XmlTee.java
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,127 @@ | ||
/* | ||
Copyright 2020 WeAreFrank! | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package nl.nn.adapterframework.xml; | ||
|
||
import org.xml.sax.Attributes; | ||
import org.xml.sax.ContentHandler; | ||
import org.xml.sax.SAXException; | ||
import org.xml.sax.ext.LexicalHandler; | ||
|
||
public class XmlTee extends FullXmlFilter { | ||
|
||
private ContentHandler handler=null; | ||
|
||
public XmlTee() { | ||
super(); | ||
} | ||
|
||
public XmlTee(ContentHandler handler, ContentHandler secondHandler) { | ||
super(handler); | ||
this.handler = secondHandler; | ||
} | ||
|
||
public void setSecondContentHandler(ContentHandler handler) { | ||
this.handler = handler; | ||
} | ||
public ContentHandler getSecondContentHandler() { | ||
return handler; | ||
} | ||
|
||
@Override | ||
public void startDocument() throws SAXException { | ||
if (handler!=null) handler.startDocument(); | ||
super.startDocument(); | ||
} | ||
@Override | ||
public void endDocument() throws SAXException { | ||
if (handler!=null) handler.endDocument(); | ||
super.endDocument(); | ||
} | ||
|
||
@Override | ||
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { | ||
if (handler!=null) handler.startElement(uri, localName, qName, atts); | ||
super.startElement(uri, localName, qName, atts); | ||
} | ||
@Override | ||
public void endElement(String uri, String localName, String qName) throws SAXException { | ||
if (handler!=null) handler.endElement(uri, localName, qName); | ||
super.endElement(uri, localName, qName); | ||
} | ||
|
||
@Override | ||
public void characters(char[] ch, int start, int length) throws SAXException { | ||
if (handler!=null) handler.characters(ch, start, length); | ||
super.characters(ch, start, length); | ||
} | ||
|
||
@Override | ||
public void startPrefixMapping(String prefix, String uri) throws SAXException { | ||
if (handler!=null) handler.startPrefixMapping(prefix, uri); | ||
super.startPrefixMapping(prefix, uri); | ||
} | ||
@Override | ||
public void endPrefixMapping(String prefix) throws SAXException { | ||
if (handler!=null) handler.endPrefixMapping(prefix); | ||
super.endPrefixMapping(prefix); | ||
} | ||
|
||
@Override | ||
public void comment(char[] ch, int start, int length) throws SAXException { | ||
if (handler!=null && handler instanceof LexicalHandler) ((LexicalHandler)handler).comment(ch, start, length); | ||
super.comment(ch, start, length); | ||
} | ||
|
||
@Override | ||
public void startCDATA() throws SAXException { | ||
if (handler!=null && handler instanceof LexicalHandler) ((LexicalHandler)handler).startCDATA(); | ||
super.startCDATA(); | ||
} | ||
@Override | ||
public void endCDATA() throws SAXException { | ||
if (handler!=null && handler instanceof LexicalHandler) ((LexicalHandler)handler).endCDATA(); | ||
super.endCDATA(); | ||
} | ||
|
||
@Override | ||
public void startDTD(String name, String publicId, String systemId) throws SAXException { | ||
if (handler!=null && handler instanceof LexicalHandler) ((LexicalHandler)handler).startDTD(name, publicId, systemId); | ||
super.startDTD(name, publicId, systemId); | ||
} | ||
@Override | ||
public void endDTD() throws SAXException { | ||
if (handler!=null && handler instanceof LexicalHandler) ((LexicalHandler)handler).endDTD(); | ||
super.endDTD(); | ||
} | ||
|
||
@Override | ||
public void startEntity(String name) throws SAXException { | ||
if (handler!=null && handler instanceof LexicalHandler) ((LexicalHandler)handler).startEntity(name); | ||
super.startEntity(name); | ||
} | ||
@Override | ||
public void endEntity(String name) throws SAXException { | ||
if (handler!=null && handler instanceof LexicalHandler) ((LexicalHandler)handler).endEntity(name); | ||
super.endEntity(name); | ||
} | ||
|
||
@Override | ||
public void processingInstruction(String target, String data) throws SAXException { | ||
if (handler!=null) handler.processingInstruction(target, data); | ||
super.processingInstruction(target, data); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
core/src/test/java/nl/nn/adapterframework/xml/XmlTapTest.java
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,24 @@ | ||
package nl.nn.adapterframework.xml; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
import nl.nn.adapterframework.testutil.TestFileUtils; | ||
import nl.nn.adapterframework.util.XmlUtils; | ||
|
||
public class XmlTapTest { | ||
|
||
|
||
@Test | ||
public void testBasic() throws Exception { | ||
String input = TestFileUtils.getTestFile("/Xslt/AnyXml/in.xml"); | ||
String expected = input; | ||
XmlWriter xmlWriter = new XmlWriter(); | ||
XmlTap xmlTap = new XmlTap(xmlWriter); | ||
XmlUtils.parseXml(input, xmlTap); | ||
assertEquals(expected,xmlWriter.toString()); | ||
assertEquals(expected,xmlTap.getWriter().toString()); | ||
} | ||
|
||
} |