X4O: Formatted the SAX3 package to eclipse-160 (code+comment)
This commit is contained in:
parent
2819b36a45
commit
a61ce241e1
26 changed files with 1192 additions and 909 deletions
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3;
|
package org.x4o.sax3;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -38,16 +38,16 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||||
*
|
*
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 May 3, 2013
|
* @version 1.0 May 3, 2013
|
||||||
* @param <TAG> The enum for the XML tag values.
|
* @param <TAG> The enum for the XML tag values.
|
||||||
* @param <TAG_WRITER> The tag writer to output to.
|
* @param <TAG_WRITER> The tag writer to output to.
|
||||||
*/
|
*/
|
||||||
public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter> implements SAX3WriterEnumHammer<TAG>, Closeable {
|
public class SAX3WriterEnum<TAG extends Enum<?>, TAG_WRITER extends ContentWriter> implements SAX3WriterEnumHammer<TAG>, Closeable {
|
||||||
|
|
||||||
private final Attributes EMPTY_ATTRIBUTES = new AttributesImpl();
|
private final Attributes EMPTY_ATTRIBUTES = new AttributesImpl();
|
||||||
private final TAG_WRITER contentWriter;
|
private final TAG_WRITER contentWriter;
|
||||||
private final String tagNamespaceUri;
|
private final String tagNamespaceUri;
|
||||||
private final String tagNamespacePrefix;
|
private final String tagNamespacePrefix;
|
||||||
|
|
||||||
public SAX3WriterEnum(TAG_WRITER contentWriter) {
|
public SAX3WriterEnum(TAG_WRITER contentWriter) {
|
||||||
this(contentWriter, SAX3XMLConstants.NULL_NS_URI, SAX3XMLConstants.NULL_NS_URI);
|
this(contentWriter, SAX3XMLConstants.NULL_NS_URI, SAX3XMLConstants.NULL_NS_URI);
|
||||||
}
|
}
|
||||||
|
|
@ -57,20 +57,20 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
|
||||||
this.tagNamespaceUri = Objects.requireNonNull(tagNamespaceUri, "Can't create wrapper with null tagNamespaceUri");
|
this.tagNamespaceUri = Objects.requireNonNull(tagNamespaceUri, "Can't create wrapper with null tagNamespaceUri");
|
||||||
this.tagNamespacePrefix = Objects.requireNonNull(tagNamespacePrefix, "Can't create wrapper with null tagNamespacePrefix");
|
this.tagNamespacePrefix = Objects.requireNonNull(tagNamespacePrefix, "Can't create wrapper with null tagNamespacePrefix");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
contentWriter.close();
|
contentWriter.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TAG_WRITER getContentWriterWrapped() {
|
public TAG_WRITER getContentWriterWrapped() {
|
||||||
return contentWriter;
|
return contentWriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTagNamespaceUri() {
|
public String getTagNamespaceUri() {
|
||||||
return tagNamespaceUri;
|
return tagNamespaceUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDocument() throws IOException {
|
public void startDocument() throws IOException {
|
||||||
try {
|
try {
|
||||||
contentWriter.startDocument();
|
contentWriter.startDocument();
|
||||||
|
|
@ -79,7 +79,7 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endDocument() throws IOException {
|
public void endDocument() throws IOException {
|
||||||
try {
|
try {
|
||||||
contentWriter.endDocument();
|
contentWriter.endDocument();
|
||||||
|
|
@ -87,30 +87,30 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentCloseable printTag(TAG tag) throws IOException {
|
public ContentCloseable printTag(TAG tag) throws IOException {
|
||||||
return printTag(tag, EMPTY_ATTRIBUTES);
|
return printTag(tag, EMPTY_ATTRIBUTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentCloseable printTag(TAG tag, Attributes atts) throws IOException {
|
public ContentCloseable printTag(TAG tag, Attributes atts) throws IOException {
|
||||||
printTagStart(tag, atts);
|
printTagStart(tag, atts);
|
||||||
return () -> printTagEnd(tag);
|
return () -> printTagEnd(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagStartEnd(TAG tag, Attributes atts) throws IOException {
|
public void printTagStartEnd(TAG tag, Attributes atts) throws IOException {
|
||||||
printTagStart(tag, atts);
|
printTagStart(tag, atts);
|
||||||
printTagEnd(tag);
|
printTagEnd(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagStartEnd(TAG tag) throws IOException {
|
public void printTagStartEnd(TAG tag) throws IOException {
|
||||||
printTagStart(tag);
|
printTagStart(tag);
|
||||||
printTagEnd(tag);
|
printTagEnd(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagStart(TAG tag) throws IOException {
|
public void printTagStart(TAG tag) throws IOException {
|
||||||
printTagStart(tag, EMPTY_ATTRIBUTES);
|
printTagStart(tag, EMPTY_ATTRIBUTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagStart(TAG tag, Attributes atts) throws IOException {
|
public void printTagStart(TAG tag, Attributes atts) throws IOException {
|
||||||
try {
|
try {
|
||||||
contentWriter.startElement(getTagNamespaceUri(), toTagString(tag), "", atts);
|
contentWriter.startElement(getTagNamespaceUri(), toTagString(tag), "", atts);
|
||||||
|
|
@ -118,15 +118,15 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagEnd(TAG tag) throws IOException {
|
public void printTagEnd(TAG tag) throws IOException {
|
||||||
try {
|
try {
|
||||||
contentWriter.endElement(getTagNamespaceUri(),toTagString(tag) , "");
|
contentWriter.endElement(getTagNamespaceUri(), toTagString(tag), "");
|
||||||
} catch (SAXException e) {
|
} catch (SAXException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String toTagString(TAG tag) {
|
private String toTagString(TAG tag) {
|
||||||
String result = tag.name();
|
String result = tag.name();
|
||||||
if (result.startsWith("_")) {
|
if (result.startsWith("_")) {
|
||||||
|
|
@ -134,7 +134,7 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagCharacters(TAG tag, String text) throws IOException {
|
public void printTagCharacters(TAG tag, String text) throws IOException {
|
||||||
printTagStart(tag);
|
printTagStart(tag);
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
|
|
@ -143,7 +143,7 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
|
||||||
printCharacters(text);
|
printCharacters(text);
|
||||||
printTagEnd(tag);
|
printTagEnd(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printCharacters(String text) throws IOException {
|
public void printCharacters(String text) throws IOException {
|
||||||
try {
|
try {
|
||||||
contentWriter.characters(text);
|
contentWriter.characters(text);
|
||||||
|
|
@ -151,7 +151,7 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printComment(String text) throws IOException {
|
public void printComment(String text) throws IOException {
|
||||||
try {
|
try {
|
||||||
contentWriter.comment(text);
|
contentWriter.comment(text);
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3;
|
package org.x4o.sax3;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
@ -34,26 +34,26 @@ import org.xml.sax.Attributes;
|
||||||
* @param <TAG> The enum for the XML tag values.
|
* @param <TAG> The enum for the XML tag values.
|
||||||
*/
|
*/
|
||||||
public interface SAX3WriterEnumHammer<TAG extends Enum<?>> {
|
public interface SAX3WriterEnumHammer<TAG extends Enum<?>> {
|
||||||
|
|
||||||
String getTagNamespaceUri();
|
String getTagNamespaceUri();
|
||||||
|
|
||||||
void startDocument() throws IOException;
|
void startDocument() throws IOException;
|
||||||
|
|
||||||
void endDocument() throws IOException;
|
void endDocument() throws IOException;
|
||||||
|
|
||||||
void printTagStartEnd(TAG tag) throws IOException;
|
void printTagStartEnd(TAG tag) throws IOException;
|
||||||
|
|
||||||
void printTagStartEnd(TAG tag, Attributes atts) throws IOException;
|
void printTagStartEnd(TAG tag, Attributes atts) throws IOException;
|
||||||
|
|
||||||
void printTagStart(TAG tag) throws IOException;
|
void printTagStart(TAG tag) throws IOException;
|
||||||
|
|
||||||
void printTagStart(TAG tag, Attributes atts) throws IOException;
|
void printTagStart(TAG tag, Attributes atts) throws IOException;
|
||||||
|
|
||||||
void printTagEnd(TAG tag) throws IOException;
|
void printTagEnd(TAG tag) throws IOException;
|
||||||
|
|
||||||
void printTagCharacters(TAG tag, String text) throws IOException;
|
void printTagCharacters(TAG tag, String text) throws IOException;
|
||||||
|
|
||||||
void printCharacters(String text) throws IOException;
|
void printCharacters(String text) throws IOException;
|
||||||
|
|
||||||
void printComment(String text) throws IOException;
|
void printComment(String text) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3;
|
package org.x4o.sax3;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
@ -38,16 +38,16 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 Apr 30, 2013
|
* @version 1.0 Apr 30, 2013
|
||||||
*/
|
*/
|
||||||
public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3WriterXml> {
|
public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag, SAX3WriterXml> {
|
||||||
|
|
||||||
public SAX3WriterHtml(Writer out, String encoding) {
|
public SAX3WriterHtml(Writer out, String encoding) {
|
||||||
super(new SAX3WriterXml(out, encoding), "", SAX3XMLConstants.NULL_NS_URI);
|
super(new SAX3WriterXml(out, encoding), "", SAX3XMLConstants.NULL_NS_URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SAX3PropertyConfig getPropertyConfig() {
|
public SAX3PropertyConfig getPropertyConfig() {
|
||||||
return getContentWriterWrapped().getPropertyConfig();
|
return getContentWriterWrapped().getPropertyConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printDocType(DocType doc) throws IOException {
|
public void printDocType(DocType doc) throws IOException {
|
||||||
try {
|
try {
|
||||||
getContentWriterWrapped().startDTD(doc.getName(), doc.getPublicId(), doc.getSystemId());
|
getContentWriterWrapped().startDTD(doc.getName(), doc.getPublicId(), doc.getSystemId());
|
||||||
|
|
@ -55,7 +55,7 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHtmlStart(String language) throws IOException {
|
public void printHtmlStart(String language) throws IOException {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
if (language != null) {
|
if (language != null) {
|
||||||
|
|
@ -63,16 +63,16 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
|
||||||
}
|
}
|
||||||
printTagStart(Tag.html, atts);
|
printTagStart(Tag.html, atts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHtmlEnd() throws IOException {
|
public void printHtmlEnd() throws IOException {
|
||||||
printTagEnd(Tag.html);
|
printTagEnd(Tag.html);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHeadMetaDate() throws IOException {
|
public void printHeadMetaDate() throws IOException {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
printHeadMeta("date", cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH)+1) + "-" + cal.get(Calendar.DAY_OF_MONTH));
|
printHeadMeta("date", cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHeadTitle(String title) throws IOException {
|
public void printHeadTitle(String title) throws IOException {
|
||||||
printTagCharacters(Tag.title, title);
|
printTagCharacters(Tag.title, title);
|
||||||
}
|
}
|
||||||
|
|
@ -84,14 +84,14 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
|
||||||
atts.addAttribute("", "charset", "", "", getPropertyConfig().getPropertyString(SAX3WriterXml.OUTPUT_ENCODING));
|
atts.addAttribute("", "charset", "", "", getPropertyConfig().getPropertyString(SAX3WriterXml.OUTPUT_ENCODING));
|
||||||
printTagStartEnd(Tag.meta, atts);
|
printTagStartEnd(Tag.meta, atts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHeadMeta(String name, String content) throws IOException {
|
public void printHeadMeta(String name, String content) throws IOException {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute("", "name", "", "", name);
|
atts.addAttribute("", "name", "", "", name);
|
||||||
atts.addAttribute("", "content", "", "", content);
|
atts.addAttribute("", "content", "", "", content);
|
||||||
printTagStartEnd(Tag.meta, atts);
|
printTagStartEnd(Tag.meta, atts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHeadLinkCss(String cssUrl) throws IOException {
|
public void printHeadLinkCss(String cssUrl) throws IOException {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute("", "rel", "", "", "stylesheet");
|
atts.addAttribute("", "rel", "", "", "stylesheet");
|
||||||
|
|
@ -100,7 +100,7 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
|
||||||
atts.addAttribute("", "href", "", "", cssUrl);
|
atts.addAttribute("", "href", "", "", cssUrl);
|
||||||
printTagStartEnd(Tag.link, atts);
|
printTagStartEnd(Tag.link, atts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printScriptSrc(String jsUrl) throws IOException {
|
public void printScriptSrc(String jsUrl) throws IOException {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute("", "type", "", "", "text/javascript");
|
atts.addAttribute("", "type", "", "", "text/javascript");
|
||||||
|
|
@ -109,7 +109,7 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
|
||||||
printCharacters(" "); // NOTE: space needed to keep browsers happy
|
printCharacters(" "); // NOTE: space needed to keep browsers happy
|
||||||
printTagEnd(Tag.script);
|
printTagEnd(Tag.script);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printScriptInline(String script) throws IOException {
|
public void printScriptInline(String script) throws IOException {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute("", "type", "", "", "text/javascript");
|
atts.addAttribute("", "type", "", "", "text/javascript");
|
||||||
|
|
@ -117,20 +117,22 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
|
||||||
printComment(script);
|
printComment(script);
|
||||||
printTagEnd(Tag.script);
|
printTagEnd(Tag.script);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printScriptNoDiv() throws IOException {
|
public void printScriptNoDiv() throws IOException {
|
||||||
printScriptNoDiv(null);
|
printScriptNoDiv(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printScriptNoDiv(String text) throws IOException {
|
public void printScriptNoDiv(String text) throws IOException {
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
text = "JavaScript is disabled on your browser.";
|
text = "JavaScript is disabled on your browser.";
|
||||||
}
|
}
|
||||||
printTagStart(Tag.noscript);
|
printTagStart(Tag.noscript);
|
||||||
printTagStart(Tag.div);printCharacters(text);printTagEnd(Tag.div);
|
printTagStart(Tag.div);
|
||||||
|
printCharacters(text);
|
||||||
|
printTagEnd(Tag.div);
|
||||||
printTagEnd(Tag.noscript);
|
printTagEnd(Tag.noscript);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHrefNamed(String name) throws IOException {
|
public void printHrefNamed(String name) throws IOException {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute("", "name", "", "", name);
|
atts.addAttribute("", "name", "", "", name);
|
||||||
|
|
@ -138,7 +140,7 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
|
||||||
printComment(" ");
|
printComment(" ");
|
||||||
printTagEnd(Tag.a);
|
printTagEnd(Tag.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHrefTarget(String href, String target, String text) throws IOException {
|
public void printHrefTarget(String href, String target, String text) throws IOException {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute("", "href", "", "", href);
|
atts.addAttribute("", "href", "", "", href);
|
||||||
|
|
@ -147,28 +149,28 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
|
||||||
printCharacters(text);
|
printCharacters(text);
|
||||||
printTagEnd(Tag.a);
|
printTagEnd(Tag.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHref(String href, String text) throws IOException {
|
public void printHref(String href, String text) throws IOException {
|
||||||
printHref(href, text, text);
|
printHref(href, text, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHref(String href, String text, String title) throws IOException {
|
public void printHref(String href, String text, String title) throws IOException {
|
||||||
printHref(href, text, title, null);
|
printHref(href, text, title, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printHref(String href, String text, String title, String spanClass) throws IOException {
|
public void printHref(String href, String text, String title, String spanClass) throws IOException {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute("", "href", "", "", href);
|
atts.addAttribute("", "href", "", "", href);
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
atts.addAttribute("", "title", "", "", title);
|
atts.addAttribute("", "title", "", "", title);
|
||||||
}
|
}
|
||||||
printTagStart(Tag.a,atts);
|
printTagStart(Tag.a, atts);
|
||||||
if (spanClass != null) {
|
if (spanClass != null) {
|
||||||
atts = new AttributesImpl();
|
atts = new AttributesImpl();
|
||||||
if (spanClass.length() > 0) {
|
if (spanClass.length() > 0) {
|
||||||
atts.addAttribute("", "class", "", "", spanClass);
|
atts.addAttribute("", "class", "", "", spanClass);
|
||||||
}
|
}
|
||||||
printTagStart(Tag.span,atts);
|
printTagStart(Tag.span, atts);
|
||||||
}
|
}
|
||||||
printCharacters(text);
|
printCharacters(text);
|
||||||
if (spanClass != null) {
|
if (spanClass != null) {
|
||||||
|
|
@ -176,11 +178,11 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
|
||||||
}
|
}
|
||||||
printTagEnd(Tag.a);
|
printTagEnd(Tag.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagCharacters(Tag tag, String text, String tagClass) throws IOException {
|
public void printTagCharacters(Tag tag, String text, String tagClass) throws IOException {
|
||||||
printTagCharacters(tag, text, tagClass, null);
|
printTagCharacters(tag, text, tagClass, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagCharacters(Tag tag, String text, String tagClass, String tagId) throws IOException {
|
public void printTagCharacters(Tag tag, String text, String tagClass, String tagId) throws IOException {
|
||||||
printTagStart(tag, tagClass, tagId, null);
|
printTagStart(tag, tagClass, tagId, null);
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
|
|
@ -189,44 +191,44 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
|
||||||
printCharacters(text);
|
printCharacters(text);
|
||||||
printTagEnd(tag);
|
printTagEnd(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentCloseable printTag(Tag tag, String tagClass) throws IOException {
|
public ContentCloseable printTag(Tag tag, String tagClass) throws IOException {
|
||||||
return printTag(tag, tagClass, null, null);
|
return printTag(tag, tagClass, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentCloseable printTag(Tag tag, Enum<?> tagClassEnum) throws IOException {
|
public ContentCloseable printTag(Tag tag, Enum<?> tagClassEnum) throws IOException {
|
||||||
return printTag(tag, tagClassEnum, null);
|
return printTag(tag, tagClassEnum, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentCloseable printTag(Tag tag, Enum<?> tagClassEnum, String tagId) throws IOException {
|
public ContentCloseable printTag(Tag tag, Enum<?> tagClassEnum, String tagId) throws IOException {
|
||||||
return printTag(tag, tagClassEnum, tagId, null);
|
return printTag(tag, tagClassEnum, tagId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentCloseable printTag(Tag tag, Enum<?> tagClassEnum, String tagId, String typeId) throws IOException {
|
public ContentCloseable printTag(Tag tag, Enum<?> tagClassEnum, String tagId, String typeId) throws IOException {
|
||||||
return printTag(tag, tagClassEnum.name(), tagId, typeId);
|
return printTag(tag, tagClassEnum.name(), tagId, typeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContentCloseable printTag(Tag tag, String tagClass, String tagId, String typeId) throws IOException {
|
public ContentCloseable printTag(Tag tag, String tagClass, String tagId, String typeId) throws IOException {
|
||||||
printTagStart(tag, tagClass, tagId, typeId);
|
printTagStart(tag, tagClass, tagId, typeId);
|
||||||
return () -> printTagEnd(tag);
|
return () -> printTagEnd(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagStart(Tag tag, String tagClass) throws IOException {
|
public void printTagStart(Tag tag, String tagClass) throws IOException {
|
||||||
printTagStart(tag, tagClass, null, null);
|
printTagStart(tag, tagClass, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagStart(Tag tag, Enum<?> tagClassEnum) throws IOException {
|
public void printTagStart(Tag tag, Enum<?> tagClassEnum) throws IOException {
|
||||||
printTagStart(tag, tagClassEnum, null);
|
printTagStart(tag, tagClassEnum, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagStart(Tag tag, Enum<?> tagClassEnum, String tagId) throws IOException {
|
public void printTagStart(Tag tag, Enum<?> tagClassEnum, String tagId) throws IOException {
|
||||||
printTagStart(tag, tagClassEnum, tagId, null);
|
printTagStart(tag, tagClassEnum, tagId, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagStart(Tag tag, Enum<?> tagClassEnum, String tagId, String typeId) throws IOException {
|
public void printTagStart(Tag tag, Enum<?> tagClassEnum, String tagId, String typeId) throws IOException {
|
||||||
printTagStart(tag, tagClassEnum.name(), tagId, typeId);
|
printTagStart(tag, tagClassEnum.name(), tagId, typeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printTagStart(Tag tag, String tagClass, String tagId, String typeId) throws IOException {
|
public void printTagStart(Tag tag, String tagClass, String tagId, String typeId) throws IOException {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
if (tagId != null && tagId.length() > 0) {
|
if (tagId != null && tagId.length() > 0) {
|
||||||
|
|
@ -240,80 +242,180 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
|
||||||
}
|
}
|
||||||
printTagStart(tag, atts);
|
printTagStart(tag, atts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Tag {
|
public enum Tag {
|
||||||
|
|
||||||
/* Deprecated TAGS */
|
/* Deprecated TAGS */
|
||||||
frameset,frame,noframes,tt,font,dir,center,strike,
|
frameset,
|
||||||
big,basefont,acronym,applet,iframe,
|
frame,
|
||||||
|
noframes,
|
||||||
|
tt,
|
||||||
|
font,
|
||||||
|
dir,
|
||||||
|
center,
|
||||||
|
strike,
|
||||||
|
big,
|
||||||
|
basefont,
|
||||||
|
acronym,
|
||||||
|
applet,
|
||||||
|
iframe,
|
||||||
|
|
||||||
/* HTML 4 TAGS */
|
/* HTML 4 TAGS */
|
||||||
html,head,title,meta,link,base,body,script,style,
|
html,
|
||||||
|
head,
|
||||||
h1,h2,h3,h4,h5,h6,
|
title,
|
||||||
a,div,span,p,pre,img,hr,br,
|
meta,
|
||||||
b,em,strong,small,noscript,
|
link,
|
||||||
|
base,
|
||||||
ul,li,dl,dt,dd,ol,
|
body,
|
||||||
table,thead,tfoot,tbody,caption,th,tr,td,
|
script,
|
||||||
|
style,
|
||||||
abbr,address,area,bdo,blockquote,
|
|
||||||
cite,code,col,colgroup,del,dfn,i,ins,
|
h1,
|
||||||
kbd,legend,map,menu,object,param,
|
h2,
|
||||||
optgroup,q,s,samp,sub,u,var,
|
h3,
|
||||||
|
h4,
|
||||||
form,fieldset,input,option,
|
h5,
|
||||||
label,button,select,textarea,
|
h6,
|
||||||
|
a,
|
||||||
|
div,
|
||||||
|
span,
|
||||||
|
p,
|
||||||
|
pre,
|
||||||
|
img,
|
||||||
|
hr,
|
||||||
|
br,
|
||||||
|
b,
|
||||||
|
em,
|
||||||
|
strong,
|
||||||
|
small,
|
||||||
|
noscript,
|
||||||
|
|
||||||
|
ul,
|
||||||
|
li,
|
||||||
|
dl,
|
||||||
|
dt,
|
||||||
|
dd,
|
||||||
|
ol,
|
||||||
|
table,
|
||||||
|
thead,
|
||||||
|
tfoot,
|
||||||
|
tbody,
|
||||||
|
caption,
|
||||||
|
th,
|
||||||
|
tr,
|
||||||
|
td,
|
||||||
|
|
||||||
|
abbr,
|
||||||
|
address,
|
||||||
|
area,
|
||||||
|
bdo,
|
||||||
|
blockquote,
|
||||||
|
cite,
|
||||||
|
code,
|
||||||
|
col,
|
||||||
|
colgroup,
|
||||||
|
del,
|
||||||
|
dfn,
|
||||||
|
i,
|
||||||
|
ins,
|
||||||
|
kbd,
|
||||||
|
legend,
|
||||||
|
map,
|
||||||
|
menu,
|
||||||
|
object,
|
||||||
|
param,
|
||||||
|
optgroup,
|
||||||
|
q,
|
||||||
|
s,
|
||||||
|
samp,
|
||||||
|
sub,
|
||||||
|
u,
|
||||||
|
var,
|
||||||
|
|
||||||
|
form,
|
||||||
|
fieldset,
|
||||||
|
input,
|
||||||
|
option,
|
||||||
|
label,
|
||||||
|
button,
|
||||||
|
select,
|
||||||
|
textarea,
|
||||||
|
|
||||||
/* HTML 5 TAGS */
|
/* HTML 5 TAGS */
|
||||||
canvas,audio,video,source,embed,track,
|
canvas,
|
||||||
datalist,keygen,output,
|
audio,
|
||||||
article,aside,bdi,command,details,dialog,summary,
|
video,
|
||||||
figure,figcaption,footer,header,hgroup,mark,meter,
|
source,
|
||||||
nav,progress,ruby,rt,rp,section,time,wbr,
|
embed,
|
||||||
;
|
track,
|
||||||
|
datalist,
|
||||||
|
keygen,
|
||||||
|
output,
|
||||||
|
article,
|
||||||
|
aside,
|
||||||
|
bdi,
|
||||||
|
command,
|
||||||
|
details,
|
||||||
|
dialog,
|
||||||
|
summary,
|
||||||
|
figure,
|
||||||
|
figcaption,
|
||||||
|
footer,
|
||||||
|
header,
|
||||||
|
hgroup,
|
||||||
|
mark,
|
||||||
|
meter,
|
||||||
|
nav,
|
||||||
|
progress,
|
||||||
|
ruby,
|
||||||
|
rt,
|
||||||
|
rp,
|
||||||
|
section,
|
||||||
|
time,
|
||||||
|
wbr,;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String DOCTYPE_NAME = "HTML PUBLIC";
|
private final static String DOCTYPE_NAME = "HTML PUBLIC";
|
||||||
|
|
||||||
public enum DocType {
|
public enum DocType {
|
||||||
/* Order from worst to better. */
|
/* Order from worst to better. */
|
||||||
HTML_5("html","",""),
|
HTML_5("html", "", ""),
|
||||||
|
|
||||||
HTML_4_FRAMESET(DOCTYPE_NAME,"\"-//W3C//DTD HTML 4.01 Frameset//EN\"","http://www.w3.org/TR/html4/frameset.dtd"),
|
HTML_4_FRAMESET(DOCTYPE_NAME, "\"-//W3C//DTD HTML 4.01 Frameset//EN\"", "http://www.w3.org/TR/html4/frameset.dtd"),
|
||||||
HTML_4_TRANSITIONAL(DOCTYPE_NAME,"\"-//W3C//DTD HTML 4.01 Transitional//EN\"","http://www.w3.org/TR/html4/loose.dtd"),
|
HTML_4_TRANSITIONAL(DOCTYPE_NAME, "\"-//W3C//DTD HTML 4.01 Transitional//EN\"", "http://www.w3.org/TR/html4/loose.dtd"),
|
||||||
HTML_4_STRICT(DOCTYPE_NAME,"\"-//W3C//DTD HTML 4.01//EN\"","http://www.w3.org/TR/html4/strict.dtd"),
|
HTML_4_STRICT(DOCTYPE_NAME, "\"-//W3C//DTD HTML 4.01//EN\"", "http://www.w3.org/TR/html4/strict.dtd"),
|
||||||
|
|
||||||
|
XHTML_1_FRAMESET(DOCTYPE_NAME, "\"-//W3C//DTD XHTML 1.0 Frameset//EN\"", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"),
|
||||||
|
XHTML_1_TRANSITIONAL(DOCTYPE_NAME, "\"-//W3C//DTD XHTML 1.0 Transitional//EN\"", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"),
|
||||||
|
XHTML_1_STRICT(DOCTYPE_NAME, "\"-//W3C//DTD XHTML 1.0 Strict//EN\"", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"),
|
||||||
|
|
||||||
|
XHTML_11(DOCTYPE_NAME, "\"-//W3C//DTD XHTML 1.1//EN\"", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"),;
|
||||||
|
|
||||||
XHTML_1_FRAMESET(DOCTYPE_NAME,"\"-//W3C//DTD XHTML 1.0 Frameset//EN\"","http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"),
|
|
||||||
XHTML_1_TRANSITIONAL(DOCTYPE_NAME,"\"-//W3C//DTD XHTML 1.0 Transitional//EN\"","http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"),
|
|
||||||
XHTML_1_STRICT(DOCTYPE_NAME,"\"-//W3C//DTD XHTML 1.0 Strict//EN\"","http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"),
|
|
||||||
|
|
||||||
XHTML_11(DOCTYPE_NAME,"\"-//W3C//DTD XHTML 1.1//EN\"","http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"),
|
|
||||||
;
|
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String publicId;
|
private final String publicId;
|
||||||
private final String systemId;
|
private final String systemId;
|
||||||
|
|
||||||
private DocType(String name, String publicId, String systemId) {
|
private DocType(String name, String publicId, String systemId) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.publicId = publicId;
|
this.publicId = publicId;
|
||||||
this.systemId = systemId;
|
this.systemId = systemId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the name
|
* @return the name
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the publicId
|
* @return the publicId
|
||||||
*/
|
*/
|
||||||
public String getPublicId() {
|
public String getPublicId() {
|
||||||
return publicId;
|
return publicId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the systemId
|
* @return the systemId
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3;
|
package org.x4o.sax3;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
|
|
@ -36,29 +36,32 @@ import org.x4o.sax3.io.SAX3XMLConstants;
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 Apr 17, 2005
|
* @version 1.0 Apr 17, 2005
|
||||||
*/
|
*/
|
||||||
public class SAX3WriterXml extends AbstractContentWriter {
|
public class SAX3WriterXml extends AbstractContentWriter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates XmlWriter which prints to the Writer interface.
|
* Creates XmlWriter which prints to the Writer interface.
|
||||||
* @param out The writer to print the xml to.
|
*
|
||||||
|
* @param out The writer to print the xml to.
|
||||||
*/
|
*/
|
||||||
public SAX3WriterXml(Writer out, String encoding) {
|
public SAX3WriterXml(Writer out, String encoding) {
|
||||||
super(out);
|
super(out);
|
||||||
getPropertyConfig().setProperty(OUTPUT_ENCODING, encoding);
|
getPropertyConfig().setProperty(OUTPUT_ENCODING, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates XmlWriter which prints to the Writer interface.
|
* Creates XmlWriter which prints to the Writer interface.
|
||||||
* @param out The writer to print the xml to.
|
*
|
||||||
|
* @param out The writer to print the xml to.
|
||||||
*/
|
*/
|
||||||
public SAX3WriterXml(Writer out) {
|
public SAX3WriterXml(Writer out) {
|
||||||
this(out,null);
|
this(out, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates XmlWriter which prints to the OutputStream interface.
|
* Creates XmlWriter which prints to the OutputStream interface.
|
||||||
* @param out The OutputStream to write to.
|
*
|
||||||
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
* @param out The OutputStream to write to.
|
||||||
|
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
||||||
*/
|
*/
|
||||||
public SAX3WriterXml(OutputStream out) throws UnsupportedEncodingException {
|
public SAX3WriterXml(OutputStream out) throws UnsupportedEncodingException {
|
||||||
this(new OutputStreamWriter(out, SAX3XMLConstants.XML_DEFAULT_ENCODING), SAX3XMLConstants.XML_DEFAULT_ENCODING);
|
this(new OutputStreamWriter(out, SAX3XMLConstants.XML_DEFAULT_ENCODING), SAX3XMLConstants.XML_DEFAULT_ENCODING);
|
||||||
|
|
@ -66,11 +69,12 @@ public class SAX3WriterXml extends AbstractContentWriter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates XmlWriter which prints to the OutputStream interface.
|
* Creates XmlWriter which prints to the OutputStream interface.
|
||||||
* @param out The OutputStream to write to.
|
*
|
||||||
* @param encoding The OutputStream encoding.
|
* @param out The OutputStream to write to.
|
||||||
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
* @param encoding The OutputStream encoding.
|
||||||
|
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
|
||||||
*/
|
*/
|
||||||
public SAX3WriterXml(OutputStream out,String encoding) throws UnsupportedEncodingException {
|
public SAX3WriterXml(OutputStream out, String encoding) throws UnsupportedEncodingException {
|
||||||
this(new OutputStreamWriter(out, encoding), encoding);
|
this(new OutputStreamWriter(out, encoding), encoding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3;
|
package org.x4o.sax3;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
@ -35,23 +35,23 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 May 3, 2013
|
* @version 1.0 May 3, 2013
|
||||||
*/
|
*/
|
||||||
public class SAX3WriterXsd extends SAX3WriterEnum<SAX3WriterXsd.Tag,SAX3WriterXml> {
|
public class SAX3WriterXsd extends SAX3WriterEnum<SAX3WriterXsd.Tag, SAX3WriterXml> {
|
||||||
|
|
||||||
public SAX3WriterXsd(Writer out, String encoding) {
|
public SAX3WriterXsd(Writer out, String encoding) {
|
||||||
super(new SAX3WriterXml(out, encoding), SAX3XMLConstants.XML_SCHEMA_NS_URI, SAX3XMLConstants.NULL_NS_URI);
|
super(new SAX3WriterXml(out, encoding), SAX3XMLConstants.XML_SCHEMA_NS_URI, SAX3XMLConstants.NULL_NS_URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SAX3PropertyConfig getPropertyConfig() {
|
public SAX3PropertyConfig getPropertyConfig() {
|
||||||
return getContentWriterWrapped().getPropertyConfig();
|
return getContentWriterWrapped().getPropertyConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printXsdImport(String namespace, String schemaLocation) throws IOException {
|
public void printXsdImport(String namespace, String schemaLocation) throws IOException {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute("", "namespace", "", "", namespace);
|
atts.addAttribute("", "namespace", "", "", namespace);
|
||||||
atts.addAttribute("", "schemaLocation", "", "", schemaLocation);
|
atts.addAttribute("", "schemaLocation", "", "", schemaLocation);
|
||||||
printTagStartEnd(Tag._import, atts);
|
printTagStartEnd(Tag._import, atts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printXsdDocumentation(String description) throws IOException {
|
public void printXsdDocumentation(String description) throws IOException {
|
||||||
if (description == null) {
|
if (description == null) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -64,7 +64,7 @@ public class SAX3WriterXsd extends SAX3WriterEnum<SAX3WriterXsd.Tag,SAX3WriterXm
|
||||||
printTagEnd(Tag.documentation);
|
printTagEnd(Tag.documentation);
|
||||||
printTagEnd(Tag.annotation);
|
printTagEnd(Tag.annotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printXsdElementAttribute(String name, String type, String description) throws IOException {
|
public void printXsdElementAttribute(String name, String type, String description) throws IOException {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute("", "name", "", "", name);
|
atts.addAttribute("", "name", "", "", name);
|
||||||
|
|
@ -73,12 +73,37 @@ public class SAX3WriterXsd extends SAX3WriterEnum<SAX3WriterXsd.Tag,SAX3WriterXm
|
||||||
printXsdDocumentation(description);
|
printXsdDocumentation(description);
|
||||||
printTagEnd(Tag.attribute);
|
printTagEnd(Tag.attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Tag {
|
public enum Tag {
|
||||||
all,annotation,any,anyAttribute,appinfo,attribute,attributeGroup,
|
all,
|
||||||
choice,complexContent,complexType,documentation,element,extension,
|
annotation,
|
||||||
field,group,_import,include,key,keyref,list,notation,
|
any,
|
||||||
redefine,restriction,schema,selector,sequence,
|
anyAttribute,
|
||||||
simpleContent,simpleType,unoin,unique
|
appinfo,
|
||||||
|
attribute,
|
||||||
|
attributeGroup,
|
||||||
|
choice,
|
||||||
|
complexContent,
|
||||||
|
complexType,
|
||||||
|
documentation,
|
||||||
|
element,
|
||||||
|
extension,
|
||||||
|
field,
|
||||||
|
group,
|
||||||
|
_import,
|
||||||
|
include,
|
||||||
|
key,
|
||||||
|
keyref,
|
||||||
|
list,
|
||||||
|
notation,
|
||||||
|
redefine,
|
||||||
|
restriction,
|
||||||
|
schema,
|
||||||
|
selector,
|
||||||
|
sequence,
|
||||||
|
simpleContent,
|
||||||
|
simpleType,
|
||||||
|
unoin,
|
||||||
|
unique
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io;
|
package org.x4o.sax3.io;
|
||||||
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
|
|
@ -34,17 +34,19 @@ import org.xml.sax.SAXException;
|
||||||
* @version 1.0 May 3, 2013
|
* @version 1.0 May 3, 2013
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractContentWriter extends AbstractContentWriterLexical implements ContentWriter {
|
public abstract class AbstractContentWriter extends AbstractContentWriterLexical implements ContentWriter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an Lecical content writer for XML.
|
* Creates an Lecical content writer for XML.
|
||||||
* @param out The writer to write to.
|
*
|
||||||
|
* @param out The writer to write to.
|
||||||
*/
|
*/
|
||||||
public AbstractContentWriter(Writer out) {
|
public AbstractContentWriter(Writer out) {
|
||||||
super(out);
|
super(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts and end then element.
|
* Starts and end then element.
|
||||||
|
*
|
||||||
* @see org.x4o.sax3.io.ContentWriter#startElementEnd(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
|
* @see org.x4o.sax3.io.ContentWriter#startElementEnd(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
|
||||||
*/
|
*/
|
||||||
public void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException {
|
public void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io;
|
package org.x4o.sax3.io;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
|
@ -53,19 +53,20 @@ import org.xml.sax.SAXException;
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 May 3, 2013
|
* @version 1.0 May 3, 2013
|
||||||
*/
|
*/
|
||||||
public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
|
|
||||||
private final SAX3PropertyConfig propertyConfig;
|
private final SAX3PropertyConfig propertyConfig;
|
||||||
private final Writer out;
|
private final Writer out;
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
private int indent = 0;
|
private int indent = 0;
|
||||||
private Map<String,String> prefixMapping = null;
|
private Map<String, String> prefixMapping = null;
|
||||||
private List<String> printedMappings = null;
|
private List<String> printedMappings = null;
|
||||||
private StringBuilder startElement = null;
|
private StringBuilder startElement = null;
|
||||||
private boolean printReturn = false;
|
private boolean printReturn = false;
|
||||||
private String lastElement = null;
|
private String lastElement = null;
|
||||||
private Stack<String> elements = null;
|
private Stack<String> elements = null;
|
||||||
|
|
||||||
|
//@formatter:off
|
||||||
private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX + "content/"; // TODO: change to "writer/xml"
|
private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX + "content/"; // TODO: change to "writer/xml"
|
||||||
public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG;
|
public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG;
|
||||||
public final static String OUTPUT_ENCODING = PROPERTY_CONTEXT_PREFIX + "output/encoding";
|
public final static String OUTPUT_ENCODING = PROPERTY_CONTEXT_PREFIX + "output/encoding";
|
||||||
|
|
@ -105,19 +106,21 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
new PropertyConfigItem(ROOT_START_NAMESPACE_ALL, Boolean.class, true)
|
new PropertyConfigItem(ROOT_START_NAMESPACE_ALL, Boolean.class, true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
//@formatter:on
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates XmlWriter which prints to the Writer interface.
|
* Creates XmlWriter which prints to the Writer interface.
|
||||||
* @param out The writer to print the xml to.
|
*
|
||||||
|
* @param out The writer to print the xml to.
|
||||||
*/
|
*/
|
||||||
public AbstractContentWriterHandler(Writer out) {
|
public AbstractContentWriterHandler(Writer out) {
|
||||||
this.out = Objects.requireNonNull(out, "Can't write on null writer.");
|
this.out = Objects.requireNonNull(out, "Can't write on null writer.");
|
||||||
this.prefixMapping = new HashMap<String,String>(15);
|
this.prefixMapping = new HashMap<String, String>(15);
|
||||||
this.printedMappings = new ArrayList<String>(15);
|
this.printedMappings = new ArrayList<String>(15);
|
||||||
this.elements = new Stack<String>();
|
this.elements = new Stack<String>();
|
||||||
this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX);
|
this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SAX3PropertyConfig getPropertyConfig() {
|
public SAX3PropertyConfig getPropertyConfig() {
|
||||||
return propertyConfig;
|
return propertyConfig;
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +129,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ContentHandler#startDocument()
|
* @see org.xml.sax.ContentHandler#startDocument()
|
||||||
*/
|
*/
|
||||||
|
|
@ -140,7 +143,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
prologWriteLicence();
|
prologWriteLicence();
|
||||||
prologWriteUserComment();
|
prologWriteUserComment();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prologWriteLicence() throws SAXException {
|
private void prologWriteLicence() throws SAXException {
|
||||||
if (!propertyConfig.getPropertyBoolean(PROLOG_LICENCE_ENABLE)) {
|
if (!propertyConfig.getPropertyBoolean(PROLOG_LICENCE_ENABLE)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -177,7 +180,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
}
|
}
|
||||||
comment(licenceText);
|
comment(licenceText);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readLicenceStream(InputStream inputStream, String encoding) throws IOException {
|
private String readLicenceStream(InputStream inputStream, String encoding) throws IOException {
|
||||||
if (encoding == null) {
|
if (encoding == null) {
|
||||||
encoding = SAX3XMLConstants.XML_DEFAULT_ENCODING;
|
encoding = SAX3XMLConstants.XML_DEFAULT_ENCODING;
|
||||||
|
|
@ -203,7 +206,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
br.close();
|
br.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prologWriteUserComment() throws SAXException {
|
private void prologWriteUserComment() throws SAXException {
|
||||||
if (!propertyConfig.getPropertyBoolean(PROLOG_USER_COMMENT_ENABLE)) {
|
if (!propertyConfig.getPropertyBoolean(PROLOG_USER_COMMENT_ENABLE)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -220,7 +223,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
userComment = userComment.replaceAll("\n", chEnter + chTab);
|
userComment = userComment.replaceAll("\n", chEnter + chTab);
|
||||||
comment(chEnter + chTab + userComment + chEnter);
|
comment(chEnter + chTab + userComment + chEnter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ContentHandler#endDocument()
|
* @see org.xml.sax.ContentHandler#endDocument()
|
||||||
*/
|
*/
|
||||||
|
|
@ -230,19 +233,19 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
throw new SAXException("Invalid xml still have " + elements.size() + " elements open.");
|
throw new SAXException("Invalid xml still have " + elements.size() + " elements open.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param uri The xml namespace uri.
|
* @param uri The xml namespace uri.
|
||||||
* @param localName The local name of the xml tag.
|
* @param localName The local name of the xml tag.
|
||||||
* @param name The (full) name of the xml tag.
|
* @param name The (full) name of the xml tag.
|
||||||
* @param atts The attributes of the xml tag.
|
* @param atts The attributes of the xml tag.
|
||||||
* @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
|
* @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
|
||||||
*/
|
*/
|
||||||
public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException {
|
public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException {
|
||||||
if (localName == null) {
|
if (localName == null) {
|
||||||
throw new SAXException("LocalName may not be null.");
|
throw new SAXException("LocalName may not be null.");
|
||||||
}
|
}
|
||||||
if (SAX3XMLConstants.isNameString(localName)==false) {
|
if (SAX3XMLConstants.isNameString(localName) == false) {
|
||||||
throw new SAXException("LocalName of element is not valid in xml; '" + localName + "'");
|
throw new SAXException("LocalName of element is not valid in xml; '" + localName + "'");
|
||||||
}
|
}
|
||||||
for (int i = 0; i < atts.getLength(); i++) {
|
for (int i = 0; i < atts.getLength(); i++) {
|
||||||
|
|
@ -272,8 +275,8 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB));
|
startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB));
|
||||||
}
|
}
|
||||||
startElement.append(SAX3XMLConstants.TAG_OPEN);
|
startElement.append(SAX3XMLConstants.TAG_OPEN);
|
||||||
|
|
||||||
startElementTag(uri,localName);
|
startElementTag(uri, localName);
|
||||||
startElementNamespace(uri);
|
startElementNamespace(uri);
|
||||||
startElementNamespaceAll();
|
startElementNamespaceAll();
|
||||||
startElementAttributes(atts);
|
startElementAttributes(atts);
|
||||||
|
|
@ -282,7 +285,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
lastElement = localName;
|
lastElement = localName;
|
||||||
elements.push(localName);
|
elements.push(localName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startElementTag(String uri, String localName) throws SAXException {
|
public void startElementTag(String uri, String localName) throws SAXException {
|
||||||
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
|
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
|
||||||
startElement.append(localName);
|
startElement.append(localName);
|
||||||
|
|
@ -298,7 +301,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
startElement.append(localName);
|
startElement.append(localName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startElementNamespace(String uri) throws SAXException {
|
public void startElementNamespace(String uri) throws SAXException {
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -314,7 +317,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
throw new SAXException("preFixUri: " + uri + " is not started.");
|
throw new SAXException("preFixUri: " + uri + " is not started.");
|
||||||
}
|
}
|
||||||
printedMappings.add(uri);
|
printedMappings.add(uri);
|
||||||
|
|
||||||
startElement.append(' ');
|
startElement.append(' ');
|
||||||
startElement.append(SAX3XMLConstants.XMLNS_ATTRIBUTE);
|
startElement.append(SAX3XMLConstants.XMLNS_ATTRIBUTE);
|
||||||
if ("".equals(prefix) == false) {
|
if ("".equals(prefix) == false) {
|
||||||
|
|
@ -325,7 +328,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
startElement.append(uri);
|
startElement.append(uri);
|
||||||
startElement.append('"');
|
startElement.append('"');
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startElementNamespaceAll() throws SAXException {
|
public void startElementNamespaceAll() throws SAXException {
|
||||||
if (!propertyConfig.getPropertyBoolean(ROOT_START_NAMESPACE_ALL)) {
|
if (!propertyConfig.getPropertyBoolean(ROOT_START_NAMESPACE_ALL)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -360,14 +363,14 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
|
startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printElementAttributeNewLineSpace() {
|
private void printElementAttributeNewLineSpace() {
|
||||||
startElement.append(SAX3XMLConstants.CHAR_NEWLINE);
|
startElement.append(SAX3XMLConstants.CHAR_NEWLINE);
|
||||||
for (int ii = 0; ii < indent+1; ii++) {
|
for (int ii = 0; ii < indent + 1; ii++) {
|
||||||
startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB));
|
startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startElementAttributes(Attributes atts) throws SAXException {
|
private void startElementAttributes(Attributes atts) throws SAXException {
|
||||||
int prevChars = 0;
|
int prevChars = 0;
|
||||||
for (int i = 0; i < atts.getLength(); i++) {
|
for (int i = 0; i < atts.getLength(); i++) {
|
||||||
|
|
@ -378,7 +381,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
attributeValue = propertyConfig.getPropertyString(OUTPUT_CHAR_NULL);
|
attributeValue = propertyConfig.getPropertyString(OUTPUT_CHAR_NULL);
|
||||||
}
|
}
|
||||||
String attributeValueSafe = SAX3XMLConstants.escapeAttributeValue(attributeValue);
|
String attributeValueSafe = SAX3XMLConstants.escapeAttributeValue(attributeValue);
|
||||||
|
|
||||||
if (propertyConfig.getPropertyBoolean(OUTPUT_LINE_PER_ATTRIBUTE)) {
|
if (propertyConfig.getPropertyBoolean(OUTPUT_LINE_PER_ATTRIBUTE)) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
printElementAttributeNewLineSpace();
|
printElementAttributeNewLineSpace();
|
||||||
|
|
@ -396,11 +399,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
startElement.append("=\"");
|
startElement.append("=\"");
|
||||||
startElement.append(attributeValueSafe);
|
startElement.append(attributeValueSafe);
|
||||||
startElement.append('"');
|
startElement.append('"');
|
||||||
|
|
||||||
if (propertyConfig.getPropertyBoolean(OUTPUT_LINE_PER_ATTRIBUTE)) {
|
if (propertyConfig.getPropertyBoolean(OUTPUT_LINE_PER_ATTRIBUTE)) {
|
||||||
printElementAttributeNewLineSpace();
|
printElementAttributeNewLineSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
int breakLines = propertyConfig.getPropertyInteger(OUTPUT_LINE_BREAK_WIDTH);
|
int breakLines = propertyConfig.getPropertyInteger(OUTPUT_LINE_BREAK_WIDTH);
|
||||||
if (breakLines > 0) {
|
if (breakLines > 0) {
|
||||||
if (prevChars == 0 && startElement.length() > breakLines) {
|
if (prevChars == 0 && startElement.length() > breakLines) {
|
||||||
|
|
@ -414,11 +417,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param uri The xml namespace uri.
|
* @param uri The xml namespace uri.
|
||||||
* @param localName The local name of the xml tag.
|
* @param localName The local name of the xml tag.
|
||||||
* @param name The (full) name of the xml tag.
|
* @param name The (full) name of the xml tag.
|
||||||
* @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
|
* @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void endElement(String uri, String localName, String name) throws SAXException {
|
public void endElement(String uri, String localName, String name) throws SAXException {
|
||||||
|
|
@ -426,16 +429,16 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
throw new SAXException("Unexpected end tag: " + localName + " should be: " + elements.peek());
|
throw new SAXException("Unexpected end tag: " + localName + " should be: " + elements.peek());
|
||||||
}
|
}
|
||||||
elements.pop();
|
elements.pop();
|
||||||
|
|
||||||
if (startElement != null) {
|
if (startElement != null) {
|
||||||
String tag = startElement.toString();
|
String tag = startElement.toString();
|
||||||
write(tag.substring(0,tag.length() - 1));// rm normal close
|
write(tag.substring(0, tag.length() - 1));// rm normal close
|
||||||
write(SAX3XMLConstants.TAG_CLOSE_EMPTY);
|
write(SAX3XMLConstants.TAG_CLOSE_EMPTY);
|
||||||
startElement = null;
|
startElement = null;
|
||||||
indent--;
|
indent--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
indent--;
|
indent--;
|
||||||
if (printReturn || !localName.equals(lastElement)) {
|
if (printReturn || !localName.equals(lastElement)) {
|
||||||
write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
|
write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
|
||||||
|
|
@ -446,7 +449,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
if (localName == null) {
|
if (localName == null) {
|
||||||
localName = "null";
|
localName = "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
write(SAX3XMLConstants.TAG_OPEN_END);
|
write(SAX3XMLConstants.TAG_OPEN_END);
|
||||||
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
|
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
|
||||||
write(localName);
|
write(localName);
|
||||||
|
|
@ -466,25 +469,26 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
ignorableWhitespace(SAX3XMLConstants.CHAR_NEWLINE);
|
ignorableWhitespace(SAX3XMLConstants.CHAR_NEWLINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the prefix mapping of an xml namespace uri.
|
* Starts the prefix mapping of an xml namespace uri.
|
||||||
* @param prefix The xml prefix of this xml namespace uri.
|
*
|
||||||
* @param uri The xml namespace uri to add the prefix for.
|
* @param prefix The xml prefix of this xml namespace uri.
|
||||||
|
* @param uri The xml namespace uri to add the prefix for.
|
||||||
* @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
|
* @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void startPrefixMapping(String prefix, String uri) throws SAXException {
|
public void startPrefixMapping(String prefix, String uri) throws SAXException {
|
||||||
prefixMapping.put(uri, prefix);
|
prefixMapping.put(uri, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param prefix The xml prefix of this xml namespace uri to be ended.
|
* @param prefix The xml prefix of this xml namespace uri to be ended.
|
||||||
* @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
|
* @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void endPrefixMapping(String prefix) throws SAXException {
|
public void endPrefixMapping(String prefix) throws SAXException {
|
||||||
Set<Map.Entry<String,String>> s = prefixMapping.entrySet();
|
Set<Map.Entry<String, String>> s = prefixMapping.entrySet();
|
||||||
String uri = null;
|
String uri = null;
|
||||||
for (Map.Entry<String,String> e : s) {
|
for (Map.Entry<String, String> e : s) {
|
||||||
if (e.getValue() == null) {
|
if (e.getValue() == null) {
|
||||||
continue; // way ?
|
continue; // way ?
|
||||||
}
|
}
|
||||||
|
|
@ -501,8 +505,8 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
/**
|
/**
|
||||||
* Prints xml characters and uses characters(java.lang.String) method.
|
* Prints xml characters and uses characters(java.lang.String) method.
|
||||||
*
|
*
|
||||||
* @param ch Character buffer.
|
* @param ch Character buffer.
|
||||||
* @param start The start index of the chars in the ch buffer.
|
* @param start The start index of the chars in the ch buffer.
|
||||||
* @param length The length index of the chars in the ch buffer.
|
* @param length The length index of the chars in the ch buffer.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
|
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
|
||||||
|
|
@ -510,9 +514,10 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||||
characters(new String(ch, start, length));
|
characters(new String(ch, start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escape and prints xml characters.
|
* Escape and prints xml characters.
|
||||||
|
*
|
||||||
* @param text The text to write.
|
* @param text The text to write.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
* @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String)
|
* @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String)
|
||||||
|
|
@ -523,11 +528,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
}
|
}
|
||||||
charactersRaw(SAX3XMLConstants.escapeCharacters(text));
|
charactersRaw(SAX3XMLConstants.escapeCharacters(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void characters(char c) throws SAXException {
|
public void characters(char c) throws SAXException {
|
||||||
characters(new char[]{c}, 0, 1);
|
characters(new char[] { c }, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// move or remove ?
|
// move or remove ?
|
||||||
protected void charactersRaw(String text) throws SAXException {
|
protected void charactersRaw(String text) throws SAXException {
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
|
|
@ -537,12 +542,12 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
checkPrintedReturn(text);
|
checkPrintedReturn(text);
|
||||||
write(text);
|
write(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml ignorable whitespace.
|
* Prints xml ignorable whitespace.
|
||||||
*
|
*
|
||||||
* @param ch Character buffer.
|
* @param ch Character buffer.
|
||||||
* @param start The start index of the chars in the ch buffer.
|
* @param start The start index of the chars in the ch buffer.
|
||||||
* @param length The length index of the chars in the ch buffer.
|
* @param length The length index of the chars in the ch buffer.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
|
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
|
||||||
|
|
@ -550,11 +555,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
|
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
|
||||||
ignorableWhitespace(new String(ch, start, length));
|
ignorableWhitespace(new String(ch, start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml ignorable whitespace.
|
* Prints xml ignorable whitespace.
|
||||||
*
|
*
|
||||||
* @param text The text to print.
|
* @param text The text to print.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
* @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String)
|
* @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
|
@ -565,23 +570,23 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
autoCloseStartElement();
|
autoCloseStartElement();
|
||||||
write(text); // TODO: check chars
|
write(text); // TODO: check chars
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml ignorable whitespace character.
|
* Prints xml ignorable whitespace character.
|
||||||
*
|
*
|
||||||
* @param c The character to print.
|
* @param c The character to print.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
*/
|
*/
|
||||||
public void ignorableWhitespace(char c) throws SAXException {
|
public void ignorableWhitespace(char c) throws SAXException {
|
||||||
ignorableWhitespace(new char[]{c}, 0, 1);
|
ignorableWhitespace(new char[] { c }, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml instructions.
|
* Prints xml instructions.
|
||||||
*
|
*
|
||||||
* @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
|
* @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
|
||||||
* @param target The target.
|
* @param target The target.
|
||||||
* @param data The data.
|
* @param data The data.
|
||||||
*/
|
*/
|
||||||
public void processingInstruction(String target, String data) throws SAXException {
|
public void processingInstruction(String target, String data) throws SAXException {
|
||||||
String targetLow = target.toLowerCase();
|
String targetLow = target.toLowerCase();
|
||||||
|
|
@ -605,7 +610,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
writeFlush();
|
writeFlush();
|
||||||
printReturn = true;
|
printReturn = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Not implemented.
|
* Not implemented.
|
||||||
*
|
*
|
||||||
|
|
@ -614,7 +619,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
*/
|
*/
|
||||||
public void setDocumentLocator(Locator locator) {
|
public void setDocumentLocator(Locator locator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Not implemented.
|
* Not implemented.
|
||||||
*
|
*
|
||||||
|
|
@ -624,12 +629,12 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
public void skippedEntity(String name) throws SAXException {
|
public void skippedEntity(String name) throws SAXException {
|
||||||
// is for validating parser support, so not needed in xml writing.
|
// is for validating parser support, so not needed in xml writing.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml comment.
|
* Prints xml comment.
|
||||||
*
|
*
|
||||||
* @param ch Character buffer.
|
* @param ch Character buffer.
|
||||||
* @param start The start index of the chars in the ch buffer.
|
* @param start The start index of the chars in the ch buffer.
|
||||||
* @param length The length index of the chars in the ch buffer.
|
* @param length The length index of the chars in the ch buffer.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
|
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
|
||||||
|
|
@ -637,7 +642,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
public void comment(char[] ch, int start, int length) throws SAXException {
|
public void comment(char[] ch, int start, int length) throws SAXException {
|
||||||
comment(new String(ch, start, length));
|
comment(new String(ch, start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml comment.
|
* Prints xml comment.
|
||||||
*
|
*
|
||||||
|
|
@ -667,15 +672,15 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
|
write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
|
||||||
writeIndent();
|
writeIndent();
|
||||||
write(SAX3XMLConstants.COMMENT_START);
|
write(SAX3XMLConstants.COMMENT_START);
|
||||||
write(SAX3XMLConstants.escapeCharactersComment(text,getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB), indent));
|
write(SAX3XMLConstants.escapeCharactersComment(text, getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB), indent));
|
||||||
write(SAX3XMLConstants.COMMENT_END);
|
write(SAX3XMLConstants.COMMENT_END);
|
||||||
printReturn = true;
|
printReturn = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the value contains any new lines and sets the printReturn field.
|
* Checks if the value contains any new lines and sets the printReturn field.
|
||||||
*
|
*
|
||||||
* @param value The value to check.
|
* @param value The value to check.
|
||||||
*/
|
*/
|
||||||
private void checkPrintedReturn(String value) {
|
private void checkPrintedReturn(String value) {
|
||||||
if (value.indexOf(SAX3XMLConstants.CHAR_NEWLINE) > 0) {
|
if (value.indexOf(SAX3XMLConstants.CHAR_NEWLINE) > 0) {
|
||||||
|
|
@ -684,10 +689,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
printReturn = false;
|
printReturn = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto close the start element if working in printing event.
|
* Auto close the start element if working in printing event.
|
||||||
* @throws SAXException When prints gives exception.
|
*
|
||||||
|
* @throws SAXException When prints gives exception.
|
||||||
*/
|
*/
|
||||||
protected void autoCloseStartElement() throws SAXException {
|
protected void autoCloseStartElement() throws SAXException {
|
||||||
if (startElement == null) {
|
if (startElement == null) {
|
||||||
|
|
@ -696,17 +702,18 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
write(startElement.toString());
|
write(startElement.toString());
|
||||||
startElement = null;
|
startElement = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indent the output writer with tabs by indent count.
|
* Indent the output writer with tabs by indent count.
|
||||||
* @throws SAXException When prints gives exception.
|
*
|
||||||
|
* @throws SAXException When prints gives exception.
|
||||||
*/
|
*/
|
||||||
private void writeIndent() throws SAXException {
|
private void writeIndent() throws SAXException {
|
||||||
for (int i = 0; i < indent; i++) {
|
for (int i = 0; i < indent; i++) {
|
||||||
write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB));
|
write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeFlush() throws SAXException {
|
protected void writeFlush() throws SAXException {
|
||||||
try {
|
try {
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
@ -714,7 +721,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
throw new SAXException(e);
|
throw new SAXException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void write(String text) throws SAXException {
|
private void write(String text) throws SAXException {
|
||||||
try {
|
try {
|
||||||
out.write(text);
|
out.write(text);
|
||||||
|
|
@ -722,7 +729,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
|
||||||
throw new SAXException(e);
|
throw new SAXException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void write(char c) throws SAXException {
|
private void write(char c) throws SAXException {
|
||||||
try {
|
try {
|
||||||
out.write(c);
|
out.write(c);
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io;
|
package org.x4o.sax3.io;
|
||||||
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
|
|
@ -33,18 +33,19 @@ import org.xml.sax.ext.LexicalHandler;
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 May 3, 2013
|
* @version 1.0 May 3, 2013
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractContentWriterLexical extends AbstractContentWriterHandler implements LexicalHandler {
|
public abstract class AbstractContentWriterLexical extends AbstractContentWriterHandler implements LexicalHandler {
|
||||||
|
|
||||||
protected boolean printCDATA = false;
|
protected boolean printCDATA = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates XmlWriter which prints to the Writer interface.
|
* Creates XmlWriter which prints to the Writer interface.
|
||||||
* @param out The writer to print the xml to.
|
*
|
||||||
|
* @param out The writer to print the xml to.
|
||||||
*/
|
*/
|
||||||
public AbstractContentWriterLexical(Writer out) {
|
public AbstractContentWriterLexical(Writer out) {
|
||||||
super(out);
|
super(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#startCDATA()
|
* @see org.xml.sax.ext.LexicalHandler#startCDATA()
|
||||||
*/
|
*/
|
||||||
|
|
@ -53,7 +54,7 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter
|
||||||
charactersRaw(SAX3XMLConstants.CDATA_START);
|
charactersRaw(SAX3XMLConstants.CDATA_START);
|
||||||
printCDATA = true;
|
printCDATA = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#endCDATA()
|
* @see org.xml.sax.ext.LexicalHandler#endCDATA()
|
||||||
*/
|
*/
|
||||||
|
|
@ -61,7 +62,7 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter
|
||||||
charactersRaw(SAX3XMLConstants.CDATA_END);
|
charactersRaw(SAX3XMLConstants.CDATA_END);
|
||||||
printCDATA = false;
|
printCDATA = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String)
|
* @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
|
@ -80,26 +81,26 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter
|
||||||
}
|
}
|
||||||
charactersRaw(SAX3XMLConstants.TAG_CLOSE);
|
charactersRaw(SAX3XMLConstants.TAG_CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#endDTD()
|
* @see org.xml.sax.ext.LexicalHandler#endDTD()
|
||||||
*/
|
*/
|
||||||
public void endDTD() throws SAXException {
|
public void endDTD() throws SAXException {
|
||||||
writeFlush();
|
writeFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
|
* @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void startEntity(String arg0) throws SAXException {
|
public void startEntity(String arg0) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
|
* @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void endEntity(String arg0) throws SAXException {
|
public void endEntity(String arg0) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(char[], int, int)
|
* @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(char[], int, int)
|
||||||
*/
|
*/
|
||||||
|
|
@ -107,7 +108,7 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter
|
||||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||||
characters(new String(ch, start, length));
|
characters(new String(ch, start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(java.lang.String)
|
* @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -37,14 +37,14 @@ import java.util.Set;
|
||||||
* @param <K> The key class.
|
* @param <K> The key class.
|
||||||
* @param <V> The value class.
|
* @param <V> The value class.
|
||||||
*/
|
*/
|
||||||
public class AttributeMap<K,V> implements Map<K,V> {
|
public class AttributeMap<K, V> implements Map<K, V> {
|
||||||
|
|
||||||
/** stores the SAX attributes set */
|
/** stores the SAX attributes set */
|
||||||
private Attributes attributes = null;
|
private Attributes attributes = null;
|
||||||
|
|
||||||
/** stores the namespace uri for this attributes */
|
/** stores the namespace uri for this attributes */
|
||||||
private String uri = null;
|
private String uri = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constuctes an new AttributeMap.
|
* Constuctes an new AttributeMap.
|
||||||
*
|
*
|
||||||
|
|
@ -53,27 +53,27 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
public AttributeMap(Attributes attributes) {
|
public AttributeMap(Attributes attributes) {
|
||||||
setAttributes(attributes);
|
setAttributes(attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructes an new AttributesMap.
|
* Constructes an new AttributesMap.
|
||||||
*
|
*
|
||||||
* @param attributes The data backed of this map.
|
* @param attributes The data backed of this map.
|
||||||
* @param uri The namespace of these attributes.
|
* @param uri The namespace of these attributes.
|
||||||
*/
|
*/
|
||||||
public AttributeMap(Attributes attributes, String uri) {
|
public AttributeMap(Attributes attributes, String uri) {
|
||||||
setAttributes(attributes);
|
setAttributes(attributes);
|
||||||
setNameSpace(uri);
|
setNameSpace(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the data backend of this map.
|
* Sets the data backend of this map.
|
||||||
*
|
*
|
||||||
* @param attributes The Attributes to be used as data backend.
|
* @param attributes The Attributes to be used as data backend.
|
||||||
*/
|
*/
|
||||||
public void setAttributes(Attributes attributes) {
|
public void setAttributes(Attributes attributes) {
|
||||||
this.attributes = attributes;
|
this.attributes = attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the data backend of this map.
|
* Return the data backend of this map.
|
||||||
*
|
*
|
||||||
|
|
@ -82,16 +82,16 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
public Attributes getAttributes() {
|
public Attributes getAttributes() {
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the namespace uri, when set to null it is disabled(default).
|
* Sets the namespace uri, when set to null it is disabled(default).
|
||||||
*
|
*
|
||||||
* @param uri The namespace uri for when parsing when an certain namespace is required.
|
* @param uri The namespace uri for when parsing when an certain namespace is required.
|
||||||
*/
|
*/
|
||||||
public void setNameSpace(String uri) {
|
public void setNameSpace(String uri) {
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the namespace used for these attributes.
|
* Returns the namespace used for these attributes.
|
||||||
*
|
*
|
||||||
|
|
@ -100,13 +100,13 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
public String getNameSpace() {
|
public String getNameSpace() {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------- inner util functions.
|
// --------------- inner util functions.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the local of full name by index.
|
* Gets the local of full name by index.
|
||||||
*
|
*
|
||||||
* @param index The index of the attribute.
|
* @param index The index of the attribute.
|
||||||
* @return The name of the attribute.
|
* @return The name of the attribute.
|
||||||
*/
|
*/
|
||||||
private String getName(int index) {
|
private String getName(int index) {
|
||||||
|
|
@ -115,7 +115,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
}
|
}
|
||||||
return attributes.getQName(index);
|
return attributes.getQName(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of the attributes. uses the uri if not null.
|
* Gets the value of the attributes. uses the uri if not null.
|
||||||
*
|
*
|
||||||
|
|
@ -131,9 +131,10 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
}
|
}
|
||||||
return attributes.getValue(name);
|
return attributes.getValue(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the attribute value.
|
* Gets the attribute value.
|
||||||
|
*
|
||||||
* @param key The name of the attribute.
|
* @param key The name of the attribute.
|
||||||
* @return The value of the attribute.
|
* @return The value of the attribute.
|
||||||
*/
|
*/
|
||||||
|
|
@ -143,9 +144,9 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
}
|
}
|
||||||
return getValue(key.toString());
|
return getValue(key.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------ MAP intreface
|
// ------------------------------ MAP intreface
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the size of the map.
|
* Returns the size of the map.
|
||||||
*
|
*
|
||||||
|
|
@ -154,7 +155,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
public int size() {
|
public int size() {
|
||||||
return attributes.getLength();
|
return attributes.getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if there are attributes in this map.
|
* Checks if there are attributes in this map.
|
||||||
*
|
*
|
||||||
|
|
@ -166,11 +167,11 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if there is an attributes with an certain key.
|
* Checks if there is an attributes with an certain key.
|
||||||
*
|
*
|
||||||
* @param key The name of an attribute.
|
* @param key The name of an attribute.
|
||||||
* @return True if the attributes excist.
|
* @return True if the attributes excist.
|
||||||
*/
|
*/
|
||||||
public boolean containsKey(Object key) {
|
public boolean containsKey(Object key) {
|
||||||
|
|
@ -179,11 +180,11 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if there is an attributes with an value.
|
* Checks if there is an attributes with an value.
|
||||||
*
|
*
|
||||||
* @param value The value to check.
|
* @param value The value to check.
|
||||||
* @return True if an attributes has this value.
|
* @return True if an attributes has this value.
|
||||||
*/
|
*/
|
||||||
public boolean containsValue(Object value) {
|
public boolean containsValue(Object value) {
|
||||||
|
|
@ -194,56 +195,56 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns The value of an attribute.
|
* Returns The value of an attribute.
|
||||||
*
|
*
|
||||||
* @param key The name of the attribute.
|
* @param key The name of the attribute.
|
||||||
* @return The value of the attribute.
|
* @return The value of the attribute.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public V get(Object key) {
|
public V get(Object key) {
|
||||||
return (V)getValue(key);
|
return (V) getValue(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function not implements. because we can't add to the attributes.
|
* Function not implements. because we can't add to the attributes.
|
||||||
*
|
*
|
||||||
* @param key ignored.
|
* @param key ignored.
|
||||||
* @param value ignored.
|
* @param value ignored.
|
||||||
* @return always null
|
* @return always null
|
||||||
*/
|
*/
|
||||||
public V put(K key, V value) {
|
public V put(K key, V value) {
|
||||||
return null; // we can't add.
|
return null; // we can't add.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function not implements. because we can't remove to the attributes.
|
* Function not implements. because we can't remove to the attributes.
|
||||||
*
|
*
|
||||||
* @param key ignored.
|
* @param key ignored.
|
||||||
* @return always null
|
* @return always null
|
||||||
*/
|
*/
|
||||||
public V remove(Object key) {
|
public V remove(Object key) {
|
||||||
return null ;// we can't remove
|
return null;// we can't remove
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function not implements. because we can't add to the attributes.
|
* Function not implements. because we can't add to the attributes.
|
||||||
*
|
*
|
||||||
* @param t ignored.
|
* @param t ignored.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void putAll(Map t) {
|
public void putAll(Map t) {
|
||||||
// we can't add.
|
// we can't add.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function not implements. because we can't clear the attributes.
|
* Function not implements. because we can't clear the attributes.
|
||||||
*/
|
*/
|
||||||
public void clear() {
|
public void clear() {
|
||||||
// we can't clear
|
// we can't clear
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new Set whith the names of the attributes.
|
* Returns a new Set whith the names of the attributes.
|
||||||
*
|
*
|
||||||
|
|
@ -253,11 +254,11 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
public Set<K> keySet() {
|
public Set<K> keySet() {
|
||||||
HashSet<K> result = new HashSet<K>();
|
HashSet<K> result = new HashSet<K>();
|
||||||
for (int i = 0; i < size(); i++) {
|
for (int i = 0; i < size(); i++) {
|
||||||
result.add((K)getName(i));
|
result.add((K) getName(i));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an Collection of the values in the attributes list.
|
* Returns an Collection of the values in the attributes list.
|
||||||
*
|
*
|
||||||
|
|
@ -267,14 +268,13 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
public Collection<V> values() {
|
public Collection<V> values() {
|
||||||
ArrayList<V> result = new ArrayList<V>();
|
ArrayList<V> result = new ArrayList<V>();
|
||||||
for (int i = 0; i < size(); i++) {
|
for (int i = 0; i < size(); i++) {
|
||||||
result.add((V)attributes.getValue(i));
|
result.add((V) attributes.getValue(i));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an Set made of Map.Entry. note: This Map.Entry is not refenced by
|
* Returns an Set made of Map.Entry. note: This Map.Entry is not refenced by the attribute list. so changes to not reflect to this map object.
|
||||||
* the attribute list. so changes to not reflect to this map object.
|
|
||||||
*
|
*
|
||||||
* @see java.util.Map#entrySet()
|
* @see java.util.Map#entrySet()
|
||||||
* @return An entry set.
|
* @return An entry set.
|
||||||
|
|
@ -289,17 +289,17 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares the SAX attribute list.
|
* Compares the SAX attribute list.
|
||||||
*
|
*
|
||||||
* @param o The Object to compare with.
|
* @param o The Object to compare with.
|
||||||
* @return True if the object are equal.
|
* @return True if the object are equal.
|
||||||
*/
|
*/
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
return attributes.equals(o); // compare to attributes
|
return attributes.equals(o); // compare to attributes
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the hashCode of the attribute list.
|
* returns the hashCode of the attribute list.
|
||||||
*
|
*
|
||||||
|
|
@ -308,33 +308,35 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return attributes.hashCode();
|
return attributes.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An innerclass used by entrySet().
|
* An innerclass used by entrySet().
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
class AttributeMapEntry implements Map.Entry {
|
class AttributeMapEntry implements Map.Entry {
|
||||||
|
|
||||||
private Object key = null;
|
private Object key = null;
|
||||||
private Object value = null;
|
private Object value = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates AttributeMapEntry with key object.
|
* Creates AttributeMapEntry with key object.
|
||||||
* @param key The key.
|
*
|
||||||
|
* @param key The key.
|
||||||
*/
|
*/
|
||||||
protected AttributeMapEntry(Object key) {
|
protected AttributeMapEntry(Object key) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the key.
|
* @return Returns the key.
|
||||||
*/
|
*/
|
||||||
public Object getKey() {
|
public Object getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value of this Map.Entry.
|
* Sets the value of this Map.Entry.
|
||||||
|
*
|
||||||
* @param value The value to set.
|
* @param value The value to set.
|
||||||
* @return The old value.
|
* @return The old value.
|
||||||
*/
|
*/
|
||||||
|
|
@ -343,14 +345,14 @@ public class AttributeMap<K,V> implements Map<K,V> {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The value of this Map.Entry.
|
* @return The value of this Map.Entry.
|
||||||
*/
|
*/
|
||||||
public Object getValue() {
|
public Object getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param o Check if o is equal.
|
* @param o Check if o is equal.
|
||||||
* @return True if key and value of Map.Entry are equal.
|
* @return True if key and value of Map.Entry are equal.
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,11 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io;
|
package org.x4o.sax3.io;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functional closable callback for indenting api flow.
|
* Functional closable callback for indenting api flow.
|
||||||
*
|
*
|
||||||
|
|
@ -34,9 +33,9 @@ import java.io.IOException;
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ContentCloseable extends Closeable {
|
public interface ContentCloseable extends Closeable {
|
||||||
|
|
||||||
void closeContent() throws IOException;
|
void closeContent() throws IOException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void close() throws IOException {
|
default void close() throws IOException {
|
||||||
closeContent(); // wrap for stack trace users
|
closeContent(); // wrap for stack trace users
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io;
|
package org.x4o.sax3.io;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -30,7 +30,6 @@ import org.xml.sax.ContentHandler;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.ext.LexicalHandler;
|
import org.xml.sax.ext.LexicalHandler;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ContentWriter is ContentHandler for writing sax events.
|
* ContentWriter is ContentHandler for writing sax events.
|
||||||
*
|
*
|
||||||
|
|
@ -38,12 +37,12 @@ import org.xml.sax.ext.LexicalHandler;
|
||||||
* @version 1.0 Apr 30, 2013
|
* @version 1.0 Apr 30, 2013
|
||||||
*/
|
*/
|
||||||
public interface ContentWriter extends ContentHandler, LexicalHandler, Closeable {
|
public interface ContentWriter extends ContentHandler, LexicalHandler, Closeable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap startDocument and endDocument in a body closable code block.
|
* Wrap startDocument and endDocument in a body closable code block.
|
||||||
*
|
*
|
||||||
* @return An closable resource block reference.
|
* @return An closable resource block reference.
|
||||||
* @throws SAXException When IOException is thrown.
|
* @throws SAXException When IOException is thrown.
|
||||||
*/
|
*/
|
||||||
default ContentCloseable startDocumentClosure() throws SAXException {
|
default ContentCloseable startDocumentClosure() throws SAXException {
|
||||||
startDocument();
|
startDocument();
|
||||||
|
|
@ -55,49 +54,55 @@ public interface ContentWriter extends ContentHandler, LexicalHandler, Closeable
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts and ends an element in one call.
|
* Starts and ends an element in one call.
|
||||||
* @param uri The uri of the element.
|
*
|
||||||
* @param localName The localName of the element.
|
* @param uri The uri of the element.
|
||||||
* @param name The name of the element.
|
* @param localName The localName of the element.
|
||||||
* @param atts The attributes of the element.
|
* @param name The name of the element.
|
||||||
* @throws SAXException When IOException is thrown.
|
* @param atts The attributes of the element.
|
||||||
|
* @throws SAXException When IOException is thrown.
|
||||||
*/
|
*/
|
||||||
void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException;
|
void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a String as xml comment.
|
* Writes a String as xml comment.
|
||||||
* @param text The text to have embedded as comment in xml.
|
*
|
||||||
* @throws SAXException On error.
|
* @param text The text to have embedded as comment in xml.
|
||||||
|
* @throws SAXException On error.
|
||||||
*/
|
*/
|
||||||
void comment(String text) throws SAXException;
|
void comment(String text) throws SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a whitespace String to the body.
|
* Writes a whitespace String to the body.
|
||||||
* @param text The String of whitespace to write.
|
*
|
||||||
* @throws SAXException On error.
|
* @param text The String of whitespace to write.
|
||||||
|
* @throws SAXException On error.
|
||||||
*/
|
*/
|
||||||
void ignorableWhitespace(String text) throws SAXException;
|
void ignorableWhitespace(String text) throws SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a whitespace character to the body.
|
* Writes a whitespace character to the body.
|
||||||
* @param c The character to write.
|
*
|
||||||
|
* @param c The character to write.
|
||||||
* @throws SAXException On error;
|
* @throws SAXException On error;
|
||||||
*/
|
*/
|
||||||
void ignorableWhitespace(char c) throws SAXException;
|
void ignorableWhitespace(char c) throws SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a String in the body.
|
* Writes a String in the body.
|
||||||
* @param text The text to write.
|
*
|
||||||
* @throws SAXException On error.
|
* @param text The text to write.
|
||||||
|
* @throws SAXException On error.
|
||||||
*/
|
*/
|
||||||
void characters(String text) throws SAXException;
|
void characters(String text) throws SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a single character in the body body.
|
* Writes a single character in the body body.
|
||||||
* @param c The character to write.
|
*
|
||||||
* @throws SAXException On error.
|
* @param c The character to write.
|
||||||
|
* @throws SAXException On error.
|
||||||
*/
|
*/
|
||||||
void characters(char c) throws SAXException;
|
void characters(char c) throws SAXException;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,12 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io;
|
package org.x4o.sax3.io;
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.Locator;
|
import org.xml.sax.Locator;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ContentWriterAdapter is base ContentHandler for writing SAX3 events.
|
* ContentWriterAdapter is base ContentHandler for writing SAX3 events.
|
||||||
*
|
*
|
||||||
|
|
@ -34,80 +33,80 @@ import org.xml.sax.SAXException;
|
||||||
* @version 1.0 Dec 27, 2024
|
* @version 1.0 Dec 27, 2024
|
||||||
*/
|
*/
|
||||||
abstract public class ContentWriterAdapter implements ContentWriter {
|
abstract public class ContentWriterAdapter implements ContentWriter {
|
||||||
|
|
||||||
public void comment(char[] ch, int start, int length) throws SAXException {
|
public void comment(char[] ch, int start, int length) throws SAXException {
|
||||||
comment(new String(ch, start, length));
|
comment(new String(ch, start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
|
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
|
||||||
ignorableWhitespace(new String(ch, start, length));
|
ignorableWhitespace(new String(ch, start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ignorableWhitespace(char c) throws SAXException {
|
public void ignorableWhitespace(char c) throws SAXException {
|
||||||
ignorableWhitespace(new char[]{c}, 0, 1);
|
ignorableWhitespace(new char[] { c }, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException {
|
public void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException {
|
||||||
startElement(uri, localName, name, atts);
|
startElement(uri, localName, name, atts);
|
||||||
endElement(uri, localName, name);
|
endElement(uri, localName, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void characters(char c) throws SAXException {
|
public void characters(char c) throws SAXException {
|
||||||
characters(new char[]{c}, 0, 1);
|
characters(new char[] { c }, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||||
characters(new String(ch, start, length));
|
characters(new String(ch, start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endCDATA() throws SAXException {
|
public void endCDATA() throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endDTD() throws SAXException {
|
public void endDTD() throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endEntity(String arg0) throws SAXException {
|
public void endEntity(String arg0) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startCDATA() throws SAXException {
|
public void startCDATA() throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startDTD(String arg0, String arg1, String arg2) throws SAXException {
|
public void startDTD(String arg0, String arg1, String arg2) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startEntity(String arg0) throws SAXException {
|
public void startEntity(String arg0) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endPrefixMapping(String arg0) throws SAXException {
|
public void endPrefixMapping(String arg0) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processingInstruction(String arg0, String arg1) throws SAXException {
|
public void processingInstruction(String arg0, String arg1) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDocumentLocator(Locator arg0) {
|
public void setDocumentLocator(Locator arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void skippedEntity(String arg0) throws SAXException {
|
public void skippedEntity(String arg0) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startPrefixMapping(String arg0, String arg1) throws SAXException {
|
public void startPrefixMapping(String arg0, String arg1) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void comment(String text) throws SAXException {
|
public void comment(String text) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ignorableWhitespace(String text) throws SAXException {
|
public void ignorableWhitespace(String text) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io;
|
package org.x4o.sax3.io;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -37,12 +37,12 @@ import java.util.function.Supplier;
|
||||||
* @version 1.0 May 1, 2013
|
* @version 1.0 May 1, 2013
|
||||||
*/
|
*/
|
||||||
public final class SAX3PropertyConfig implements Cloneable {
|
public final class SAX3PropertyConfig implements Cloneable {
|
||||||
|
|
||||||
public final static String X4O_PROPERTIES_PREFIX = "http://x4o.org/properties/";
|
public final static String X4O_PROPERTIES_PREFIX = "http://x4o.org/properties/";
|
||||||
private final Map<String,PropertyConfigItem> items;
|
private final Map<String, PropertyConfigItem> items;
|
||||||
private final boolean readOnly;
|
private final boolean readOnly;
|
||||||
private final String keyPrefix;
|
private final String keyPrefix;
|
||||||
|
|
||||||
public SAX3PropertyConfig(String keyPrefix, PropertyConfigItem... items) {
|
public SAX3PropertyConfig(String keyPrefix, PropertyConfigItem... items) {
|
||||||
this(false, null, keyPrefix, items);
|
this(false, null, keyPrefix, items);
|
||||||
}
|
}
|
||||||
|
|
@ -50,14 +50,14 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
public SAX3PropertyConfig(SAX3PropertyConfig parentPropertyConfig, String keyPrefix, PropertyConfigItem... items) {
|
public SAX3PropertyConfig(SAX3PropertyConfig parentPropertyConfig, String keyPrefix, PropertyConfigItem... items) {
|
||||||
this(false, parentPropertyConfig, keyPrefix, items);
|
this(false, parentPropertyConfig, keyPrefix, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SAX3PropertyConfig(boolean readOnly, SAX3PropertyConfig parentPropertyConfig, String keyPrefix, PropertyConfigItem... itemConfig) {
|
public SAX3PropertyConfig(boolean readOnly, SAX3PropertyConfig parentPropertyConfig, String keyPrefix, PropertyConfigItem... itemConfig) {
|
||||||
if (keyPrefix == null) {
|
if (keyPrefix == null) {
|
||||||
throw new NullPointerException("Can't create PropertyConfig with null keyPrefix.");
|
throw new NullPointerException("Can't create PropertyConfig with null keyPrefix.");
|
||||||
}
|
}
|
||||||
this.readOnly = readOnly;
|
this.readOnly = readOnly;
|
||||||
this.keyPrefix = appendSlashIfMissing(keyPrefix);
|
this.keyPrefix = appendSlashIfMissing(keyPrefix);
|
||||||
Map<String,PropertyConfigItem> fillItems = new HashMap<String,PropertyConfigItem>(itemConfig.length);
|
Map<String, PropertyConfigItem> fillItems = new HashMap<String, PropertyConfigItem>(itemConfig.length);
|
||||||
fillPropertyConfigItems(fillItems, itemConfig);
|
fillPropertyConfigItems(fillItems, itemConfig);
|
||||||
copyParentPropertyConfig(fillItems, parentPropertyConfig);
|
copyParentPropertyConfig(fillItems, parentPropertyConfig);
|
||||||
if (fillItems.isEmpty()) {
|
if (fillItems.isEmpty()) {
|
||||||
|
|
@ -71,22 +71,22 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
}
|
}
|
||||||
items = Collections.unmodifiableMap(fillItems);
|
items = Collections.unmodifiableMap(fillItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String appendSlashIfMissing(String keyPrefix) {
|
private final String appendSlashIfMissing(String keyPrefix) {
|
||||||
if (keyPrefix.endsWith("/") == false) {
|
if (keyPrefix.endsWith("/") == false) {
|
||||||
keyPrefix += "/";
|
keyPrefix += "/";
|
||||||
}
|
}
|
||||||
return keyPrefix;
|
return keyPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void fillPropertyConfigItems(Map<String,PropertyConfigItem> fillItems, PropertyConfigItem... itemConfig) {
|
private final void fillPropertyConfigItems(Map<String, PropertyConfigItem> fillItems, PropertyConfigItem... itemConfig) {
|
||||||
for (int i = 0; i < itemConfig.length; i++) {
|
for (int i = 0; i < itemConfig.length; i++) {
|
||||||
PropertyConfigItem item = itemConfig[i];
|
PropertyConfigItem item = itemConfig[i];
|
||||||
fillItems.put(item.getValueKey(),item);
|
fillItems.put(item.getValueKey(), item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void copyParentPropertyConfig(Map<String,PropertyConfigItem> fillItems, SAX3PropertyConfig parentPropertyConfig) {
|
private final void copyParentPropertyConfig(Map<String, PropertyConfigItem> fillItems, SAX3PropertyConfig parentPropertyConfig) {
|
||||||
if (parentPropertyConfig == null) {
|
if (parentPropertyConfig == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -94,26 +94,26 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
fillItems.put(key, parentPropertyConfig.getPropertyConfigItem(key));
|
fillItems.put(key, parentPropertyConfig.getPropertyConfigItem(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class PropertyConfigItem implements Cloneable {
|
public static final class PropertyConfigItem implements Cloneable {
|
||||||
private final boolean valueRequired;
|
private final boolean valueRequired;
|
||||||
private final String valueKey;
|
private final String valueKey;
|
||||||
private final Class<?> valueType;
|
private final Class<?> valueType;
|
||||||
private final Object valueDefault;
|
private final Object valueDefault;
|
||||||
private Object value = null;
|
private Object value = null;
|
||||||
|
|
||||||
public PropertyConfigItem(boolean valueRequired, String valueKey, Class<?> valueType) {
|
public PropertyConfigItem(boolean valueRequired, String valueKey, Class<?> valueType) {
|
||||||
this(valueRequired, valueKey, valueType, null);
|
this(valueRequired, valueKey, valueType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PropertyConfigItem(String valueKey, Class<?> valueType) {
|
public PropertyConfigItem(String valueKey, Class<?> valueType) {
|
||||||
this(false, valueKey, valueType, null);
|
this(false, valueKey, valueType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PropertyConfigItem(String valueKey, Class<?> valueType, Object valueDefault) {
|
public PropertyConfigItem(String valueKey, Class<?> valueType, Object valueDefault) {
|
||||||
this(false, valueKey, valueType, valueDefault); // with default then value can not be required.
|
this(false, valueKey, valueType, valueDefault); // with default then value can not be required.
|
||||||
}
|
}
|
||||||
|
|
||||||
private PropertyConfigItem(boolean valueRequired, String valueKey, Class<?> valueType, Object valueDefault) {
|
private PropertyConfigItem(boolean valueRequired, String valueKey, Class<?> valueType, Object valueDefault) {
|
||||||
if (valueKey == null) {
|
if (valueKey == null) {
|
||||||
throw new NullPointerException("Can't create PropertyConfigItem with null valueKey.");
|
throw new NullPointerException("Can't create PropertyConfigItem with null valueKey.");
|
||||||
|
|
@ -126,51 +126,52 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
this.valueType = valueType;
|
this.valueType = valueType;
|
||||||
this.valueDefault = valueDefault;
|
this.valueDefault = valueDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the value key.
|
* @return the value key.
|
||||||
*/
|
*/
|
||||||
public String getValueKey() {
|
public String getValueKey() {
|
||||||
return valueKey;
|
return valueKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the valueType.
|
* @return the valueType.
|
||||||
*/
|
*/
|
||||||
public Class<?> getValueType() {
|
public Class<?> getValueType() {
|
||||||
return valueType;
|
return valueType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the value default.
|
* @return the value default.
|
||||||
*/
|
*/
|
||||||
public Object getValueDefault() {
|
public Object getValueDefault() {
|
||||||
return valueDefault;
|
return valueDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the valueRequired.
|
* @return the valueRequired.
|
||||||
*/
|
*/
|
||||||
public boolean isValueRequired() {
|
public boolean isValueRequired() {
|
||||||
return valueRequired;
|
return valueRequired;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the value.
|
* @return the value.
|
||||||
*/
|
*/
|
||||||
public Object getValue() {
|
public Object getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param value the value to set.
|
* @param value the value to set.
|
||||||
*/
|
*/
|
||||||
public void setValue(Object value) {
|
public void setValue(Object value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clones all the fields into the new PropertyConfigItem.
|
* Clones all the fields into the new PropertyConfigItem.
|
||||||
|
*
|
||||||
* @see java.lang.Object#clone()
|
* @see java.lang.Object#clone()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -180,7 +181,7 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final PropertyConfigItem getPropertyConfigItem(String key) {
|
private final PropertyConfigItem getPropertyConfigItem(String key) {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
throw new NullPointerException("Can't search with null key.");
|
throw new NullPointerException("Can't search with null key.");
|
||||||
|
|
@ -191,23 +192,23 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getKeyPrefix() {
|
public final String getKeyPrefix() {
|
||||||
return keyPrefix;
|
return keyPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isPropertyRequired(String key) {
|
public final boolean isPropertyRequired(String key) {
|
||||||
return getPropertyKeysRequired().contains(key);
|
return getPropertyKeysRequired().contains(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final List<String> getPropertyKeysRequired() {
|
public final List<String> getPropertyKeysRequired() {
|
||||||
return findPropertyKeysRequired(false);
|
return findPropertyKeysRequired(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final List<String> getPropertyKeysRequiredValues() {
|
public final List<String> getPropertyKeysRequiredValues() {
|
||||||
return findPropertyKeysRequired(true);
|
return findPropertyKeysRequired(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final List<String> findPropertyKeysRequired(boolean checkValue) {
|
private final List<String> findPropertyKeysRequired(boolean checkValue) {
|
||||||
List<String> result = new ArrayList<String>(10);
|
List<String> result = new ArrayList<String>(10);
|
||||||
for (String key : getPropertyKeys()) {
|
for (String key : getPropertyKeys()) {
|
||||||
|
|
@ -223,26 +224,26 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final List<String> getPropertyKeys() {
|
public final List<String> getPropertyKeys() {
|
||||||
List<String> result = new ArrayList<String>(items.keySet());
|
List<String> result = new ArrayList<String>(items.keySet());
|
||||||
Collections.sort(result);
|
Collections.sort(result);
|
||||||
return Collections.unmodifiableList(result);
|
return Collections.unmodifiableList(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setProperty(String key,Object value) {
|
public final void setProperty(String key, Object value) {
|
||||||
if (readOnly) {
|
if (readOnly) {
|
||||||
throw new IllegalStateException("This property is readonly for key:" + key);
|
throw new IllegalStateException("This property is readonly for key:" + key);
|
||||||
}
|
}
|
||||||
PropertyConfigItem item = getPropertyConfigItem(key);
|
PropertyConfigItem item = getPropertyConfigItem(key);
|
||||||
item.setValue(value);
|
item.setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Object getPropertyDefault(String key) {
|
public final Object getPropertyDefault(String key) {
|
||||||
PropertyConfigItem item = getPropertyConfigItem(key);
|
PropertyConfigItem item = getPropertyConfigItem(key);
|
||||||
return item.getValueDefault();
|
return item.getValueDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Object getProperty(String key) {
|
public final Object getProperty(String key) {
|
||||||
PropertyConfigItem item = getPropertyConfigItem(key);
|
PropertyConfigItem item = getPropertyConfigItem(key);
|
||||||
Object value = item.getValue();
|
Object value = item.getValue();
|
||||||
|
|
@ -251,12 +252,12 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Class<?> getPropertyType(String key) {
|
public final Class<?> getPropertyType(String key) {
|
||||||
PropertyConfigItem item = getPropertyConfigItem(key);
|
PropertyConfigItem item = getPropertyConfigItem(key);
|
||||||
return item.getValueType();
|
return item.getValueType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Class<?> getPropertyType(String key, Supplier<Class<?>> defaultValue) {
|
public final Class<?> getPropertyType(String key, Supplier<Class<?>> defaultValue) {
|
||||||
Class<?> result = getPropertyType(key);
|
Class<?> result = getPropertyType(key);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|
@ -264,18 +265,18 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
}
|
}
|
||||||
return defaultValue.get();
|
return defaultValue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final File getPropertyFile(String key) {
|
public final File getPropertyFile(String key) {
|
||||||
Object value = getProperty(key);
|
Object value = getProperty(key);
|
||||||
if (value instanceof File) {
|
if (value instanceof File) {
|
||||||
return (File)value;
|
return (File) value;
|
||||||
}
|
}
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final File getPropertyFile(String key, Supplier<File> defaultValue) {
|
public final File getPropertyFile(String key, Supplier<File> defaultValue) {
|
||||||
File result = getPropertyFile(key);
|
File result = getPropertyFile(key);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|
@ -283,18 +284,18 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
}
|
}
|
||||||
return defaultValue.get();
|
return defaultValue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Boolean getPropertyBoolean(String key) {
|
public final Boolean getPropertyBoolean(String key) {
|
||||||
Object value = getProperty(key);
|
Object value = getProperty(key);
|
||||||
if (value instanceof Boolean) {
|
if (value instanceof Boolean) {
|
||||||
return (Boolean)value;
|
return (Boolean) value;
|
||||||
}
|
}
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Boolean getPropertyBoolean(String key, Supplier<Boolean> defaultValue) {
|
public final Boolean getPropertyBoolean(String key, Supplier<Boolean> defaultValue) {
|
||||||
Boolean result = getPropertyBoolean(key);
|
Boolean result = getPropertyBoolean(key);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|
@ -302,18 +303,18 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
}
|
}
|
||||||
return defaultValue.get();
|
return defaultValue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Integer getPropertyInteger(String key) {
|
public final Integer getPropertyInteger(String key) {
|
||||||
Object value = getProperty(key);
|
Object value = getProperty(key);
|
||||||
if (value instanceof Integer) {
|
if (value instanceof Integer) {
|
||||||
return (Integer)value;
|
return (Integer) value;
|
||||||
}
|
}
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Integer getPropertyInteger(String key, Supplier<Integer> defaultValue) {
|
public final Integer getPropertyInteger(String key, Supplier<Integer> defaultValue) {
|
||||||
Integer result = getPropertyInteger(key);
|
Integer result = getPropertyInteger(key);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|
@ -321,19 +322,19 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
}
|
}
|
||||||
return defaultValue.get();
|
return defaultValue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final List<String> getPropertyList(String key) {
|
public final List<String> getPropertyList(String key) {
|
||||||
Object value = getProperty(key);
|
Object value = getProperty(key);
|
||||||
if (value instanceof List) {
|
if (value instanceof List) {
|
||||||
return (List<String>)value;
|
return (List<String>) value;
|
||||||
}
|
}
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final List<String> getPropertyList(String key, Supplier<List<String>> defaultValue) {
|
public final List<String> getPropertyList(String key, Supplier<List<String>> defaultValue) {
|
||||||
List<String> result = getPropertyList(key);
|
List<String> result = getPropertyList(key);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|
@ -341,39 +342,39 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
}
|
}
|
||||||
return defaultValue.get();
|
return defaultValue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final Map<String,String> getPropertyMap(String key) {
|
public final Map<String, String> getPropertyMap(String key) {
|
||||||
Object value = getProperty(key);
|
Object value = getProperty(key);
|
||||||
if (value instanceof Map) {
|
if (value instanceof Map) {
|
||||||
return (Map<String,String>)value;
|
return (Map<String, String>) value;
|
||||||
}
|
}
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Map<String,String> getPropertyMap(String key, Supplier<Map<String,String>> defaultValue) {
|
public final Map<String, String> getPropertyMap(String key, Supplier<Map<String, String>> defaultValue) {
|
||||||
Map<String,String> result = getPropertyMap(key);
|
Map<String, String> result = getPropertyMap(key);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return defaultValue.get();
|
return defaultValue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getPropertyString(String key) {
|
public final String getPropertyString(String key) {
|
||||||
Object value = getProperty(key);
|
Object value = getProperty(key);
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
return (String)value;
|
return (String) value;
|
||||||
}
|
}
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getPropertyString(String key,String defaultValue) {
|
public final String getPropertyString(String key, String defaultValue) {
|
||||||
String propertyValue = getPropertyString(key);
|
String propertyValue = getPropertyString(key);
|
||||||
if (propertyValue == null) {
|
if (propertyValue == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
|
@ -381,15 +382,15 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
return propertyValue;
|
return propertyValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String getPropertyString(String key,Supplier<String> defaultValue) {
|
public final String getPropertyString(String key, Supplier<String> defaultValue) {
|
||||||
String result = getPropertyString(key);
|
String result = getPropertyString(key);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return defaultValue.get();
|
return defaultValue.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void copyParentProperties(SAX3PropertyConfig config) {
|
public final void copyParentProperties(SAX3PropertyConfig config) {
|
||||||
for (String key : getPropertyKeys()) {
|
for (String key : getPropertyKeys()) {
|
||||||
Object value = config.getProperty(key);
|
Object value = config.getProperty(key);
|
||||||
|
|
@ -399,9 +400,9 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
setProperty(key, value);
|
setProperty(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final void setPropertyParsedValue(String key,String value) {
|
public final void setPropertyParsedValue(String key, String value) {
|
||||||
Class<?> valueType = getPropertyType(key);
|
Class<?> valueType = getPropertyType(key);
|
||||||
if (String.class.equals(valueType)) {
|
if (String.class.equals(valueType)) {
|
||||||
setProperty(key, value);
|
setProperty(key, value);
|
||||||
|
|
@ -429,7 +430,7 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
}
|
}
|
||||||
if (List.class.equals(valueType)) {
|
if (List.class.equals(valueType)) {
|
||||||
String[] listValues = value.split(",");
|
String[] listValues = value.split(",");
|
||||||
List<String> result = (List<String>)getProperty(key);
|
List<String> result = (List<String>) getProperty(key);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = new ArrayList<String>(10);
|
result = new ArrayList<String>(10);
|
||||||
setProperty(key, result);
|
setProperty(key, result);
|
||||||
|
|
@ -441,9 +442,9 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
}
|
}
|
||||||
if (Map.class.equals(valueType)) {
|
if (Map.class.equals(valueType)) {
|
||||||
String[] listValues = value.split(",");
|
String[] listValues = value.split(",");
|
||||||
Map<String,String> result = (Map<String,String>)getProperty(key);
|
Map<String, String> result = (Map<String, String>) getProperty(key);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = new HashMap<String,String>(10);
|
result = new HashMap<String, String>(10);
|
||||||
setProperty(key, result);
|
setProperty(key, result);
|
||||||
}
|
}
|
||||||
if (listValues.length != 2) {
|
if (listValues.length != 2) {
|
||||||
|
|
@ -455,9 +456,10 @@ public final class SAX3PropertyConfig implements Cloneable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clones all the properties into the new PropertyConfig.
|
* Clones all the properties into the new PropertyConfig.
|
||||||
|
*
|
||||||
* @see java.lang.Object#clone()
|
* @see java.lang.Object#clone()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -31,139 +31,140 @@ import java.util.PrimitiveIterator;
|
||||||
* @version 1.0 Mrt 31, 2012
|
* @version 1.0 Mrt 31, 2012
|
||||||
*/
|
*/
|
||||||
public final class SAX3XMLConstants {
|
public final class SAX3XMLConstants {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lowcase xml.
|
* Lowcase xml.
|
||||||
*/
|
*/
|
||||||
public static final String XML = javax.xml.XMLConstants.XML_NS_PREFIX; // "xml"
|
public static final String XML = javax.xml.XMLConstants.XML_NS_PREFIX; // "xml"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML Default encoding is utf-8.
|
* XML Default encoding is utf-8.
|
||||||
*/
|
*/
|
||||||
public static final String XML_DEFAULT_ENCODING = "UTF-8";
|
public static final String XML_DEFAULT_ENCODING = "UTF-8";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML Default version is 1.0.
|
* XML Default version is 1.0.
|
||||||
*/
|
*/
|
||||||
public static final String XML_DEFAULT_VERSION = "1.0";
|
public static final String XML_DEFAULT_VERSION = "1.0";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML Namespace prefix attribute.
|
* XML Namespace prefix attribute.
|
||||||
*/
|
*/
|
||||||
public static final String XMLNS_ATTRIBUTE = javax.xml.XMLConstants.XMLNS_ATTRIBUTE; // "xmlns"
|
public static final String XMLNS_ATTRIBUTE = javax.xml.XMLConstants.XMLNS_ATTRIBUTE; // "xmlns"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML Namespace prefix seperator
|
* XML Namespace prefix seperator
|
||||||
*/
|
*/
|
||||||
public static final String XMLNS_ASSIGN = ":";
|
public static final String XMLNS_ASSIGN = ":";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML Schema namespace URI.
|
* XML Schema namespace URI.
|
||||||
*/
|
*/
|
||||||
public static final String XML_SCHEMA_NS_URI = javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; // "http://www.w3.org/2001/XMLSchema"
|
public static final String XML_SCHEMA_NS_URI = javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; // "http://www.w3.org/2001/XMLSchema"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML Schema instance namespace URI.
|
* XML Schema instance namespace URI.
|
||||||
*/
|
*/
|
||||||
public static final String XML_SCHEMA_INSTANCE_NS_URI = javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI; // "http://www.w3.org/2001/XMLSchema-instance"
|
public static final String XML_SCHEMA_INSTANCE_NS_URI = javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI; // "http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Null or empty namespace uri.
|
* Null or empty namespace uri.
|
||||||
|
*
|
||||||
* @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting">Namespaces in XML, 5.2 Namespace Defaulting</a>
|
* @see <a href="http://www.w3.org/TR/REC-xml-names/#defaulting">Namespaces in XML, 5.2 Namespace Defaulting</a>
|
||||||
*/
|
*/
|
||||||
public static final String NULL_NS_URI = javax.xml.XMLConstants.NULL_NS_URI; // ""
|
public static final String NULL_NS_URI = javax.xml.XMLConstants.NULL_NS_URI; // ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Definition of DTD doctype opening tag.
|
* Definition of DTD doctype opening tag.
|
||||||
*/
|
*/
|
||||||
public static final String XML_DOCTYPE_TAG_OPEN = "<!DOCTYPE";
|
public static final String XML_DOCTYPE_TAG_OPEN = "<!DOCTYPE";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens xml element tag.
|
* Opens xml element tag.
|
||||||
*/
|
*/
|
||||||
public static final String TAG_OPEN = "<";
|
public static final String TAG_OPEN = "<";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens end xml element tag.
|
* Opens end xml element tag.
|
||||||
*/
|
*/
|
||||||
public static final String TAG_OPEN_END = "</";
|
public static final String TAG_OPEN_END = "</";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes xml element tag.
|
* Closes xml element tag.
|
||||||
*/
|
*/
|
||||||
public static final String TAG_CLOSE = ">";
|
public static final String TAG_CLOSE = ">";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close empty xml element tag.
|
* Close empty xml element tag.
|
||||||
*/
|
*/
|
||||||
public static final String TAG_CLOSE_EMPTY = "/>";
|
public static final String TAG_CLOSE_EMPTY = "/>";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a comment.
|
* Starts a comment.
|
||||||
*/
|
*/
|
||||||
public static final String COMMENT_START = "<!--";
|
public static final String COMMENT_START = "<!--";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends a comment.
|
* Ends a comment.
|
||||||
*/
|
*/
|
||||||
public static final String COMMENT_END = "-->";
|
public static final String COMMENT_END = "-->";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a processing instruction.
|
* Starts a processing instruction.
|
||||||
*/
|
*/
|
||||||
public static final String PROCESS_START = "<?";
|
public static final String PROCESS_START = "<?";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends a processing instruction.
|
* Ends a processing instruction.
|
||||||
*/
|
*/
|
||||||
public static final String PROCESS_END = "?>";
|
public static final String PROCESS_END = "?>";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a cdata section.
|
* Starts a cdata section.
|
||||||
*/
|
*/
|
||||||
public static final String CDATA_START = "<![CDATA[";
|
public static final String CDATA_START = "<![CDATA[";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends a cdata section.
|
* Ends a cdata section.
|
||||||
*/
|
*/
|
||||||
public static final String CDATA_END = "]]>";
|
public static final String CDATA_END = "]]>";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The regex expression of a cdata start section.
|
* The regex expression of a cdata start section.
|
||||||
*/
|
*/
|
||||||
public static final String CDATA_START_REGEX = "<!\\x"+Integer.toHexString('[')+"CDATA\\x"+Integer.toHexString('[');
|
public static final String CDATA_START_REGEX = "<!\\x" + Integer.toHexString('[') + "CDATA\\x" + Integer.toHexString('[');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The regex expression of a cdata end section.
|
* The regex expression of a cdata end section.
|
||||||
*/
|
*/
|
||||||
public static final String CDATA_END_REGEX = "\\x"+Integer.toHexString(']')+"\\x"+Integer.toHexString(']')+">";
|
public static final String CDATA_END_REGEX = "\\x" + Integer.toHexString(']') + "\\x" + Integer.toHexString(']') + ">";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tab char
|
* Tab char
|
||||||
*/
|
*/
|
||||||
public static final char CHAR_TAB = '\t';
|
public static final char CHAR_TAB = '\t';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Newline char
|
* Newline char
|
||||||
*/
|
*/
|
||||||
public static final char CHAR_NEWLINE = '\n';
|
public static final char CHAR_NEWLINE = '\n';
|
||||||
|
|
||||||
/// Unicode entity reference escape sequence starter
|
/// Unicode entity reference escape sequence starter
|
||||||
public static final int CODE_POINT_ENTIY_REF_ESCAPE = '&';
|
public static final int CODE_POINT_ENTIY_REF_ESCAPE = '&';
|
||||||
|
|
||||||
/// Unicode entity reference by number
|
/// Unicode entity reference by number
|
||||||
public static final int CODE_POINT_ENTIY_REF_NUMBER = '#';
|
public static final int CODE_POINT_ENTIY_REF_NUMBER = '#';
|
||||||
|
|
||||||
/// Unicode entity reference by hex number
|
/// Unicode entity reference by hex number
|
||||||
public static final int CODE_POINT_ENTIY_REF_NUMBER_HEX = 'x';
|
public static final int CODE_POINT_ENTIY_REF_NUMBER_HEX = 'x';
|
||||||
|
|
||||||
/// Unicode entity reference escape sequence terminator
|
/// Unicode entity reference escape sequence terminator
|
||||||
public static final int CODE_POINT_ENTIY_REF_TERMINATOR = ';';
|
public static final int CODE_POINT_ENTIY_REF_TERMINATOR = ';';
|
||||||
|
|
||||||
static public String getDocumentDeclaration(String encoding) {
|
static public String getDocumentDeclaration(String encoding) {
|
||||||
return getDocumentDeclaration(encoding,null);
|
return getDocumentDeclaration(encoding, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String getDocumentDeclaration(String encoding, String version) {
|
static public String getDocumentDeclaration(String encoding, String version) {
|
||||||
if (encoding == null) {
|
if (encoding == null) {
|
||||||
encoding = XML_DEFAULT_ENCODING;
|
encoding = XML_DEFAULT_ENCODING;
|
||||||
|
|
@ -173,65 +174,136 @@ public final class SAX3XMLConstants {
|
||||||
}
|
}
|
||||||
return String.format("<?xml version=\"%s\" encoding=\"%s\"?>", version, encoding);
|
return String.format("<?xml version=\"%s\" encoding=\"%s\"?>", version, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public boolean isChar(int c) {
|
static public boolean isChar(int c) {
|
||||||
// Exclude "compatibility characters", as defined in section 2.3 of [Unicode]
|
// Exclude "compatibility characters", as defined in section 2.3 of [Unicode]
|
||||||
if (c>=0x7F & c<=0x84) { return false; }
|
if (c >= 0x7F & c <= 0x84) {
|
||||||
if (c>=0x86 & c<=0x9F) { return false; }
|
return false;
|
||||||
if (c>=0xFDD0 & c<=0xFDEF) { return false; }
|
}
|
||||||
if ((c>=0x1FFFE & c<=0x1FFFF)||(c>=0x2FFFE & c<=0x2FFFF)|(c>=0x3FFFE & c<=0x3FFFF)) { return false; }
|
if (c >= 0x86 & c <= 0x9F) {
|
||||||
if ((c>=0x4FFFE & c<=0x4FFFF)||(c>=0x5FFFE & c<=0x5FFFF)|(c>=0x6FFFE & c<=0x6FFFF)) { return false; }
|
return false;
|
||||||
if ((c>=0x7FFFE & c<=0x7FFFF)||(c>=0x8FFFE & c<=0x8FFFF)|(c>=0x9FFFE & c<=0x9FFFF)) { return false; }
|
}
|
||||||
if ((c>=0xAFFFE & c<=0xAFFFF)||(c>=0xBFFFE & c<=0xBFFFF)|(c>=0xCFFFE & c<=0xCFFFF)) { return false; }
|
if (c >= 0xFDD0 & c <= 0xFDEF) {
|
||||||
if ((c>=0xDFFFE & c<=0xDFFFF)||(c>=0xEFFFE & c<=0xEFFFF)|(c>=0xFFFFE & c<=0xFFFFF)) { return false; }
|
return false;
|
||||||
if (c>=0x10FFFE & c<=0x10FFFF) { return false; }
|
}
|
||||||
|
if ((c >= 0x1FFFE & c <= 0x1FFFF) || (c >= 0x2FFFE & c <= 0x2FFFF) | (c >= 0x3FFFE & c <= 0x3FFFF)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((c >= 0x4FFFE & c <= 0x4FFFF) || (c >= 0x5FFFE & c <= 0x5FFFF) | (c >= 0x6FFFE & c <= 0x6FFFF)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((c >= 0x7FFFE & c <= 0x7FFFF) || (c >= 0x8FFFE & c <= 0x8FFFF) | (c >= 0x9FFFE & c <= 0x9FFFF)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((c >= 0xAFFFE & c <= 0xAFFFF) || (c >= 0xBFFFE & c <= 0xBFFFF) | (c >= 0xCFFFE & c <= 0xCFFFF)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((c >= 0xDFFFE & c <= 0xDFFFF) || (c >= 0xEFFFE & c <= 0xEFFFF) | (c >= 0xFFFFE & c <= 0xFFFFF)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (c >= 0x10FFFE & c <= 0x10FFFF) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Source;
|
// Source;
|
||||||
// #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
|
// #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
|
||||||
if (c==0x9) { return true; }
|
if (c == 0x9) {
|
||||||
if (c==0xA) { return true; }
|
return true;
|
||||||
if (c==0xD) { return true; }
|
}
|
||||||
if (c>=0x20 & c<=0xD7FF) { return true; }
|
if (c == 0xA) {
|
||||||
if (c>=0xE000 & c<=0xFFFD) { return true; }
|
return true;
|
||||||
if (c>=0x10000 & c<=0x10FFFF) { return true; }
|
}
|
||||||
|
if (c == 0xD) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0x20 & c <= 0xD7FF) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0xE000 & c <= 0xFFFD) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0x10000 & c <= 0x10FFFF) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public boolean isNameStartChar(int c) {
|
static public boolean isNameStartChar(int c) {
|
||||||
// Source;
|
// Source;
|
||||||
// ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
// ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] |
|
||||||
if (c>='a' & c<='z') { return true; }
|
// [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
||||||
if (c>='A' & c<='Z') { return true; }
|
if (c >= 'a' & c <= 'z') {
|
||||||
if (c==':' || c=='_') { return true; }
|
return true;
|
||||||
if (c>=0xC0 & c<=0xD6) { return true; }
|
}
|
||||||
if (c>=0xD8 & c<=0xF6) { return true; }
|
if (c >= 'A' & c <= 'Z') {
|
||||||
if (c>=0xF8 & c<=0x2FF) { return true; }
|
return true;
|
||||||
if (c>=0x370 & c<=0x37D) { return true; }
|
}
|
||||||
if (c>=0x37F & c<=0x1FFF) { return true; }
|
if (c == ':' || c == '_') {
|
||||||
if (c>=0x200C & c<=0x200D) { return true; }
|
return true;
|
||||||
if (c>=0x2070 & c<=0x218F) { return true; }
|
}
|
||||||
if (c>=0x2C00 & c<=0x2FEF) { return true; }
|
if (c >= 0xC0 & c <= 0xD6) {
|
||||||
if (c>=0x3001 & c<=0xD7FF) { return true; }
|
return true;
|
||||||
if (c>=0xF900 & c<=0xFDCF) { return true; }
|
}
|
||||||
if (c>=0xFDF0 & c<=0xFFFD) { return true; }
|
if (c >= 0xD8 & c <= 0xF6) {
|
||||||
if (c>=0x10000 & c<=0xEFFFF) { return true; }
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0xF8 & c <= 0x2FF) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0x370 & c <= 0x37D) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0x37F & c <= 0x1FFF) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0x200C & c <= 0x200D) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0x2070 & c <= 0x218F) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0x2C00 & c <= 0x2FEF) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0x3001 & c <= 0xD7FF) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0xF900 & c <= 0xFDCF) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0xFDF0 & c <= 0xFFFD) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0x10000 & c <= 0xEFFFF) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public boolean isNameChar(int c) {
|
static public boolean isNameChar(int c) {
|
||||||
// Source;
|
// Source;
|
||||||
// NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
|
// NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
|
||||||
if (isNameStartChar(c)) {
|
if (isNameStartChar(c)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (c=='-' || c=='.') { return true; }
|
if (c == '-' || c == '.') {
|
||||||
if (c>='0' & c<='9') { return true; }
|
return true;
|
||||||
if (c==0xB7) { return true; }
|
}
|
||||||
if (c>=0x0300 & c<=0x036F) { return true; }
|
if (c >= '0' & c <= '9') {
|
||||||
if (c>=0x203F & c<=0x2040) { return true; }
|
return true;
|
||||||
|
}
|
||||||
|
if (c == 0xB7) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0x0300 & c <= 0x036F) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (c >= 0x203F & c <= 0x2040) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public boolean isCharString(String value) {
|
static public boolean isCharString(String value) {
|
||||||
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
|
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
|
|
@ -242,7 +314,7 @@ public final class SAX3XMLConstants {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public boolean isNameString(String value) {
|
static public boolean isNameString(String value) {
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
|
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
|
||||||
|
|
@ -260,7 +332,7 @@ public final class SAX3XMLConstants {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static private boolean escapeXMLValueAppend(int codePoint, StringBuilder result) {
|
static private boolean escapeXMLValueAppend(int codePoint, StringBuilder result) {
|
||||||
if (codePoint == '<') {
|
if (codePoint == '<') {
|
||||||
result.append("<");
|
result.append("<");
|
||||||
|
|
@ -284,23 +356,23 @@ public final class SAX3XMLConstants {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String escapeAttributeValue(String value) {
|
static public String escapeAttributeValue(String value) {
|
||||||
// Reference ::= EntityRef | CharRef
|
// Reference ::= EntityRef | CharRef
|
||||||
// AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
|
// AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
|
||||||
StringBuilder result = new StringBuilder(value.length());
|
StringBuilder result = new StringBuilder(value.length());
|
||||||
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
|
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
int c = iterator.nextInt();
|
int c = iterator.nextInt();
|
||||||
// 3.3.3 Attribute-Value Normalization.
|
// 3.3.3 Attribute-Value Normalization.
|
||||||
if (escapeXMLValueAppend(c,result)) {
|
if (escapeXMLValueAppend(c, result)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result.appendCodePoint(c);
|
result.appendCodePoint(c);
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String escapeCharacters(String value) {
|
static public String escapeCharacters(String value) {
|
||||||
StringBuilder result = new StringBuilder(value.length());
|
StringBuilder result = new StringBuilder(value.length());
|
||||||
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
|
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
|
||||||
|
|
@ -323,18 +395,18 @@ public final class SAX3XMLConstants {
|
||||||
result.append(entity);
|
result.append(entity);
|
||||||
continue; // contine to next i char.
|
continue; // contine to next i char.
|
||||||
} else {
|
} else {
|
||||||
//i = iOrg; // continue normal escape.
|
// i = iOrg; // continue normal escape.
|
||||||
PrimitiveIterator.OfInt entityIterator = entity.codePoints().iterator();
|
PrimitiveIterator.OfInt entityIterator = entity.codePoints().iterator();
|
||||||
while (entityIterator.hasNext()) {
|
while (entityIterator.hasNext()) {
|
||||||
int entityCodePoint = entityIterator.nextInt();
|
int entityCodePoint = entityIterator.nextInt();
|
||||||
if (escapeXMLValueAppend(entityCodePoint,result)) {
|
if (escapeXMLValueAppend(entityCodePoint, result)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result.appendCodePoint(entityCodePoint);
|
result.appendCodePoint(entityCodePoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (escapeXMLValueAppend(c,result)) {
|
if (escapeXMLValueAppend(c, result)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result.appendCodePoint(c);
|
result.appendCodePoint(c);
|
||||||
|
|
@ -342,60 +414,110 @@ public final class SAX3XMLConstants {
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make it loaded and xml and html version aware for correctness.
|
// TODO: make it loaded and xml and html version aware for correctness.
|
||||||
static private boolean charEntityAllowed(String entity) {
|
static private boolean charEntityAllowed(String entity) {
|
||||||
|
|
||||||
// Hex code points
|
// Hex code points
|
||||||
if (entity.startsWith("&#")) {
|
if (entity.startsWith("&#")) {
|
||||||
String hex = entity.substring(2,entity.length() - 1);
|
String hex = entity.substring(2, entity.length() - 1);
|
||||||
if (hex.startsWith("x")) {
|
if (hex.startsWith("x")) {
|
||||||
hex = hex.substring(1);
|
hex = hex.substring(1);
|
||||||
}
|
}
|
||||||
int codePoint = Integer.parseInt(hex, 16);
|
int codePoint = Integer.parseInt(hex, 16);
|
||||||
return codePoint > 0; // TODO: check if code point is valid.
|
return codePoint > 0; // TODO: check if code point is valid.
|
||||||
}
|
}
|
||||||
|
|
||||||
// XML
|
// XML
|
||||||
if ("<".equals(entity)) { return true; }
|
if ("<".equals(entity)) {
|
||||||
if (">".equals(entity)) { return true; }
|
return true;
|
||||||
if ("&".equals(entity)) { return true; }
|
}
|
||||||
if (""".equals(entity)) { return true; }
|
if (">".equals(entity)) {
|
||||||
if ("'".equals(entity)) { return true; }
|
return true;
|
||||||
|
}
|
||||||
|
if ("&".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (""".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ("'".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// HTML
|
// HTML
|
||||||
if ("´".equals(entity)) { return true; }
|
if ("´".equals(entity)) {
|
||||||
if ("ℵ".equals(entity)) { return true; }
|
return true;
|
||||||
if ("≈".equals(entity)) { return true; }
|
}
|
||||||
if ("∠".equals(entity)) { return true; }
|
if ("ℵ".equals(entity)) {
|
||||||
if ("∗".equals(entity)) { return true; }
|
return true;
|
||||||
if ("♣".equals(entity)) { return true; }
|
}
|
||||||
if ("♦".equals(entity)) { return true; }
|
if ("≈".equals(entity)) {
|
||||||
if ("♥".equals(entity)) { return true; }
|
return true;
|
||||||
if ("♠".equals(entity)) { return true; }
|
}
|
||||||
|
if ("∠".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ("∗".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ("♣".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ("♦".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ("♥".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ("♠".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// TODO: etc/etc
|
// TODO: etc/etc
|
||||||
if ("ÿ".equals(entity)) { return true; }
|
if ("ÿ".equals(entity)) {
|
||||||
if ("ý".equals(entity)) { return true; }
|
return true;
|
||||||
if ("ù".equals(entity)) { return true; }
|
}
|
||||||
if ("ü".equals(entity)) { return true; }
|
if ("ý".equals(entity)) {
|
||||||
if ("û".equals(entity)) { return true; }
|
return true;
|
||||||
if ("ú".equals(entity)) { return true; }
|
}
|
||||||
|
if ("ù".equals(entity)) {
|
||||||
if ("÷".equals(entity)) { return true; }
|
return true;
|
||||||
if (" ".equals(entity)) { return true; }
|
}
|
||||||
if ("®".equals(entity)) { return true; }
|
if ("ü".equals(entity)) {
|
||||||
if ("™".equals(entity)) { return true; }
|
return true;
|
||||||
if ("©".equals(entity)) { return true; }
|
}
|
||||||
|
if ("û".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ("ú".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("÷".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (" ".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ("®".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ("™".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ("©".equals(entity)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String escapeCharactersCdata(String value,String replaceCdataStart,String replaceCdataEnd) {
|
static public String escapeCharactersCdata(String value, String replaceCdataStart, String replaceCdataEnd) {
|
||||||
value = value.replaceAll(CDATA_START_REGEX, replaceCdataStart);
|
value = value.replaceAll(CDATA_START_REGEX, replaceCdataStart);
|
||||||
value = value.replaceAll(CDATA_END_REGEX, replaceCdataEnd);
|
value = value.replaceAll(CDATA_END_REGEX, replaceCdataEnd);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String escapeCharactersComment(String value,String charTab,int indent) {
|
static public String escapeCharactersComment(String value, String charTab, int indent) {
|
||||||
value = value.replaceAll(COMMENT_START, "");
|
value = value.replaceAll(COMMENT_START, "");
|
||||||
value = value.replaceAll(COMMENT_END, "");
|
value = value.replaceAll(COMMENT_END, "");
|
||||||
StringBuilder result = new StringBuilder(value.length());
|
StringBuilder result = new StringBuilder(value.length());
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io.xdbx;
|
package org.x4o.sax3.io.xdbx;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
|
@ -38,7 +38,8 @@ public abstract class AbstractXDBXWriter extends AbstractXDBXWriterLexical imple
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates writer which prints to the stream interface.
|
* Creates writer which prints to the stream interface.
|
||||||
* @param out The stream to print the xml to.
|
*
|
||||||
|
* @param out The stream to print the xml to.
|
||||||
*/
|
*/
|
||||||
public AbstractXDBXWriter(OutputStream out) {
|
public AbstractXDBXWriter(OutputStream out) {
|
||||||
super(out);
|
super(out);
|
||||||
|
|
@ -46,10 +47,11 @@ public abstract class AbstractXDBXWriter extends AbstractXDBXWriterLexical imple
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts and end then element.
|
* Starts and end then element.
|
||||||
|
*
|
||||||
* @see org.x4o.sax3.io.ContentWriter#startElementEnd(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
|
* @see org.x4o.sax3.io.ContentWriter#startElementEnd(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
|
||||||
*/
|
*/
|
||||||
public void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException {
|
public void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException {
|
||||||
startElement(uri,localName,name, atts);
|
startElement(uri, localName, name, atts);
|
||||||
endElement(uri, localName, name);
|
endElement(uri, localName, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io.xdbx;
|
package org.x4o.sax3.io.xdbx;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
|
@ -56,15 +56,16 @@ import org.xml.sax.SAXException;
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 Dec 19, 2024
|
* @version 1.0 Dec 19, 2024
|
||||||
*/
|
*/
|
||||||
public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
|
|
||||||
private final SAX3PropertyConfig propertyConfig;
|
private final SAX3PropertyConfig propertyConfig;
|
||||||
private final OutputStream out;
|
private final OutputStream out;
|
||||||
private Map<String,String> prefixMapping = null;
|
private Map<String, String> prefixMapping = null;
|
||||||
private List<String> printedMappings = null;
|
private List<String> printedMappings = null;
|
||||||
private Stack<String> elements = null;
|
private Stack<String> elements = null;
|
||||||
private Map<String,Integer> stringIdx = null;
|
private Map<String, Integer> stringIdx = null;
|
||||||
|
|
||||||
|
//@formatter:off
|
||||||
private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX+"writer/xdbx/";
|
private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX+"writer/xdbx/";
|
||||||
public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG;
|
public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG;
|
||||||
public final static String OUTPUT_DECLARATION = PROPERTY_CONTEXT_PREFIX+"output/declaration";
|
public final static String OUTPUT_DECLARATION = PROPERTY_CONTEXT_PREFIX+"output/declaration";
|
||||||
|
|
@ -94,34 +95,36 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
new PropertyConfigItem(ROOT_START_NAMESPACE_ALL, Boolean.class, true)
|
new PropertyConfigItem(ROOT_START_NAMESPACE_ALL, Boolean.class, true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
//@formatter:on
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates writer which prints to the stream interface.
|
* Creates writer which prints to the stream interface.
|
||||||
* @param out The stream to print the xml to.
|
*
|
||||||
|
* @param out The stream to print the xml to.
|
||||||
*/
|
*/
|
||||||
public AbstractXDBXWriterHandler(OutputStream out) {
|
public AbstractXDBXWriterHandler(OutputStream out) {
|
||||||
this.out = Objects.requireNonNull(out, "Can't write on null OutputStream.");
|
this.out = Objects.requireNonNull(out, "Can't write on null OutputStream.");
|
||||||
this.prefixMapping = new HashMap<String,String>(15);
|
this.prefixMapping = new HashMap<String, String>(15);
|
||||||
this.printedMappings = new ArrayList<String>(15);
|
this.printedMappings = new ArrayList<String>(15);
|
||||||
this.elements = new Stack<String>();
|
this.elements = new Stack<String>();
|
||||||
this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX);
|
this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX);
|
||||||
this.stringIdx = new HashMap<>();
|
this.stringIdx = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SAX3PropertyConfig getPropertyConfig() {
|
public SAX3PropertyConfig getPropertyConfig() {
|
||||||
return propertyConfig;
|
return propertyConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean xdbxStringId(String data) {
|
protected boolean xdbxStringId(String data) {
|
||||||
Integer result = stringIdx.get(data);
|
Integer result = stringIdx.get(data);
|
||||||
return result != null;
|
return result != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int xdbxStringStore(String data) {
|
protected int xdbxStringStore(String data) {
|
||||||
Integer result = stringIdx.get(data);
|
Integer result = stringIdx.get(data);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|
@ -131,7 +134,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
stringIdx.put(data, result);
|
stringIdx.put(data, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ContentHandler#startDocument()
|
* @see org.xml.sax.ContentHandler#startDocument()
|
||||||
*/
|
*/
|
||||||
|
|
@ -146,14 +149,14 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
writeLengthValue("1.0");
|
writeLengthValue("1.0");
|
||||||
writeTag(XDBXContentTag.ENCODING);
|
writeTag(XDBXContentTag.ENCODING);
|
||||||
writeLengthValue("utf-8");
|
writeLengthValue("utf-8");
|
||||||
//Standalone in TV(standalone) form where the value of 'standalone' is either 0 or 1.
|
// Standalone in TV(standalone) form where the value of 'standalone' is either 0 or 1.
|
||||||
//write(XDBXContentTag.STANDALONE);
|
// write(XDBXContentTag.STANDALONE);
|
||||||
//write(1);
|
// write(1);
|
||||||
}
|
}
|
||||||
prologWriteLicence();
|
prologWriteLicence();
|
||||||
prologWriteUserComment();
|
prologWriteUserComment();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prologWriteLicence() throws SAXException {
|
private void prologWriteLicence() throws SAXException {
|
||||||
if (!propertyConfig.getPropertyBoolean(PROLOG_LICENCE_ENABLE)) {
|
if (!propertyConfig.getPropertyBoolean(PROLOG_LICENCE_ENABLE)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -168,7 +171,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
}
|
}
|
||||||
licenceInput = cl.getResourceAsStream(licenceResource);
|
licenceInput = cl.getResourceAsStream(licenceResource);
|
||||||
if (licenceInput == null) {
|
if (licenceInput == null) {
|
||||||
throw new NullPointerException("Could not load licence resource from: "+licenceResource);
|
throw new NullPointerException("Could not load licence resource from: " + licenceResource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (licenceInput == null) {
|
if (licenceInput == null) {
|
||||||
|
|
@ -190,7 +193,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
}
|
}
|
||||||
comment(licenceText);
|
comment(licenceText);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String readLicenceStream(InputStream inputStream, String encoding) throws IOException {
|
private String readLicenceStream(InputStream inputStream, String encoding) throws IOException {
|
||||||
if (encoding == null) {
|
if (encoding == null) {
|
||||||
encoding = SAX3XMLConstants.XML_DEFAULT_ENCODING;
|
encoding = SAX3XMLConstants.XML_DEFAULT_ENCODING;
|
||||||
|
|
@ -202,7 +205,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
while (line != null) {
|
while (line != null) {
|
||||||
if (line.length()>0) {
|
if (line.length() > 0) {
|
||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
}
|
}
|
||||||
sb.append(line);
|
sb.append(line);
|
||||||
|
|
@ -216,7 +219,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
br.close();
|
br.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prologWriteUserComment() throws SAXException {
|
private void prologWriteUserComment() throws SAXException {
|
||||||
if (!propertyConfig.getPropertyBoolean(PROLOG_USER_COMMENT_ENABLE)) {
|
if (!propertyConfig.getPropertyBoolean(PROLOG_USER_COMMENT_ENABLE)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -228,12 +231,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
if (userComment.isEmpty()) {
|
if (userComment.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String chEnter = "\n"; //getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE);
|
String chEnter = "\n"; // getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE);
|
||||||
String chTab = "\t"; //getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB);
|
String chTab = "\t"; // getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB);
|
||||||
userComment = userComment.replaceAll("\n", chEnter + chTab);
|
userComment = userComment.replaceAll("\n", chEnter + chTab);
|
||||||
comment(chEnter + chTab + userComment + chEnter);
|
comment(chEnter + chTab + userComment + chEnter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ContentHandler#endDocument()
|
* @see org.xml.sax.ContentHandler#endDocument()
|
||||||
*/
|
*/
|
||||||
|
|
@ -244,12 +247,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
throw new SAXException("Invalid xml still have " + elements.size() + " elements open.");
|
throw new SAXException("Invalid xml still have " + elements.size() + " elements open.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param uri The xml namespace uri.
|
* @param uri The xml namespace uri.
|
||||||
* @param localName The local name of the xml tag.
|
* @param localName The local name of the xml tag.
|
||||||
* @param name The (full) name of the xml tag.
|
* @param name The (full) name of the xml tag.
|
||||||
* @param atts The attributes of the xml tag.
|
* @param atts The attributes of the xml tag.
|
||||||
* @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
|
* @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
|
||||||
*/
|
*/
|
||||||
public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException {
|
public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException {
|
||||||
|
|
@ -279,7 +282,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
startElementTag(uri,localName,name);
|
startElementTag(uri, localName, name);
|
||||||
startElementNamespace(uri);
|
startElementNamespace(uri);
|
||||||
startElementAttributes(atts);
|
startElementAttributes(atts);
|
||||||
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
|
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
|
||||||
|
|
@ -288,10 +291,10 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
elements.push(uri + ":" + name);
|
elements.push(uri + ":" + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startElementTag(String uri, String localName, String name) throws SAXException {
|
public void startElementTag(String uri, String localName, String name) throws SAXException {
|
||||||
boolean localNameIdx = xdbxStringId(localName);
|
boolean localNameIdx = xdbxStringId(localName);
|
||||||
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri==null) {
|
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
|
||||||
if (localNameIdx) {
|
if (localNameIdx) {
|
||||||
writeTag(XDBXContentTag.ELEMENT_I);
|
writeTag(XDBXContentTag.ELEMENT_I);
|
||||||
writeVariableInteger(xdbxStringStore(localName));
|
writeVariableInteger(xdbxStringStore(localName));
|
||||||
|
|
@ -305,7 +308,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
} else {
|
} else {
|
||||||
String prefix = prefixMapping.get(uri);
|
String prefix = prefixMapping.get(uri);
|
||||||
if (prefix == null) {
|
if (prefix == null) {
|
||||||
throw new SAXException("preFixUri: "+uri+" is not started.");
|
throw new SAXException("preFixUri: " + uri + " is not started.");
|
||||||
}
|
}
|
||||||
if (localNameIdx) {
|
if (localNameIdx) {
|
||||||
writeTag(XDBXContentTag.ELEMENT_III);
|
writeTag(XDBXContentTag.ELEMENT_III);
|
||||||
|
|
@ -318,22 +321,22 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
writeVariableInteger(xdbxStringStore(uri));
|
writeVariableInteger(xdbxStringStore(uri));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startElementNamespace(String uri) throws SAXException {
|
public void startElementNamespace(String uri) throws SAXException {
|
||||||
if ((uri != null && SAX3XMLConstants.NULL_NS_URI.equals(uri) == false) && printedMappings.contains(uri) == false) {
|
if ((uri != null && SAX3XMLConstants.NULL_NS_URI.equals(uri) == false) && printedMappings.contains(uri) == false) {
|
||||||
String prefix = prefixMapping.get(uri);
|
String prefix = prefixMapping.get(uri);
|
||||||
if (prefix == null) {
|
if (prefix == null) {
|
||||||
throw new SAXException("preFixUri: "+uri+" is not started.");
|
throw new SAXException("preFixUri: " + uri + " is not started.");
|
||||||
}
|
}
|
||||||
printedMappings.add(uri);
|
printedMappings.add(uri);
|
||||||
|
|
||||||
writeTag(XDBXContentTag.NS_DECL_II);
|
writeTag(XDBXContentTag.NS_DECL_II);
|
||||||
writeVariableInteger(xdbxStringStore(prefix));
|
writeVariableInteger(xdbxStringStore(prefix));
|
||||||
writeVariableInteger(xdbxStringStore(uri));
|
writeVariableInteger(xdbxStringStore(uri));
|
||||||
}
|
}
|
||||||
startElementNamespaceAll(uri);
|
startElementNamespaceAll(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startElementNamespaceAll(String uri) throws SAXException {
|
public void startElementNamespaceAll(String uri) throws SAXException {
|
||||||
if (!propertyConfig.getPropertyBoolean(ROOT_START_NAMESPACE_ALL)) {
|
if (!propertyConfig.getPropertyBoolean(ROOT_START_NAMESPACE_ALL)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -343,17 +346,17 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
if (printedMappings.contains(uri2) == false) {
|
if (printedMappings.contains(uri2) == false) {
|
||||||
prefix = prefixMapping.get(uri2);
|
prefix = prefixMapping.get(uri2);
|
||||||
if (prefix == null) {
|
if (prefix == null) {
|
||||||
throw new SAXException("preFixUri: "+uri+" is not started.");
|
throw new SAXException("preFixUri: " + uri + " is not started.");
|
||||||
}
|
}
|
||||||
printedMappings.add(uri2);
|
printedMappings.add(uri2);
|
||||||
|
|
||||||
writeTag(XDBXContentTag.NS_DECL_II);
|
writeTag(XDBXContentTag.NS_DECL_II);
|
||||||
writeVariableInteger(xdbxStringStore(prefix));
|
writeVariableInteger(xdbxStringStore(prefix));
|
||||||
writeVariableInteger(xdbxStringStore(uri2));
|
writeVariableInteger(xdbxStringStore(uri2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startElementAttributes(Attributes atts) throws SAXException {
|
private void startElementAttributes(Attributes atts) throws SAXException {
|
||||||
for (int i = 0; i < atts.getLength(); i++) {
|
for (int i = 0; i < atts.getLength(); i++) {
|
||||||
String attributeUri = atts.getURI(i);
|
String attributeUri = atts.getURI(i);
|
||||||
|
|
@ -365,8 +368,8 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
String attributeValueSafe = SAX3XMLConstants.escapeAttributeValue(attributeValue);
|
String attributeValueSafe = SAX3XMLConstants.escapeAttributeValue(attributeValue);
|
||||||
boolean attributeValueSimple = attributeValue.equals(attributeValueSafe);
|
boolean attributeValueSimple = attributeValue.equals(attributeValueSafe);
|
||||||
boolean attributeNameIdx = xdbxStringId(attributeName);
|
boolean attributeNameIdx = xdbxStringId(attributeName);
|
||||||
|
|
||||||
if (SAX3XMLConstants.NULL_NS_URI.equals(attributeUri) || attributeUri ==null) {
|
if (SAX3XMLConstants.NULL_NS_URI.equals(attributeUri) || attributeUri == null) {
|
||||||
if (attributeNameIdx) {
|
if (attributeNameIdx) {
|
||||||
writeTag(XDBXContentTag.ATTRIBUTE_I);
|
writeTag(XDBXContentTag.ATTRIBUTE_I);
|
||||||
writeVariableInteger(xdbxStringStore(attributeName));
|
writeVariableInteger(xdbxStringStore(attributeName));
|
||||||
|
|
@ -399,15 +402,15 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
writeLengthValue(attributeValueSafe);
|
writeLengthValue(attributeValueSafe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param uri The xml namespace uri.
|
* @param uri The xml namespace uri.
|
||||||
* @param localName The local name of the xml tag.
|
* @param localName The local name of the xml tag.
|
||||||
* @param name The (full) name of the xml tag.
|
* @param name The (full) name of the xml tag.
|
||||||
* @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
|
* @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void endElement(String uri, String localName, String name) throws SAXException {
|
public void endElement(String uri, String localName, String name) throws SAXException {
|
||||||
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri==null) {
|
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
|
||||||
if (elements.size() > 0 && elements.peek().equals(localName) == false) {
|
if (elements.size() > 0 && elements.peek().equals(localName) == false) {
|
||||||
throw new SAXException("Unexpected end tag: " + localName + " should be: " + elements.peek());
|
throw new SAXException("Unexpected end tag: " + localName + " should be: " + elements.peek());
|
||||||
}
|
}
|
||||||
|
|
@ -420,16 +423,17 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
elements.pop();
|
elements.pop();
|
||||||
writeTag(XDBXContentTag.END_ELEMENT);
|
writeTag(XDBXContentTag.END_ELEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the prefix mapping of an xml namespace uri.
|
* Starts the prefix mapping of an xml namespace uri.
|
||||||
* @param prefix The xml prefix of this xml namespace uri.
|
*
|
||||||
* @param uri The xml namespace uri to add the prefix for.
|
* @param prefix The xml prefix of this xml namespace uri.
|
||||||
|
* @param uri The xml namespace uri to add the prefix for.
|
||||||
* @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
|
* @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void startPrefixMapping(String prefix, String uri) throws SAXException {
|
public void startPrefixMapping(String prefix, String uri) throws SAXException {
|
||||||
prefixMapping.put(uri, prefix);
|
prefixMapping.put(uri, prefix);
|
||||||
|
|
||||||
boolean prefixIdx = xdbxStringId(prefix);
|
boolean prefixIdx = xdbxStringId(prefix);
|
||||||
if (!prefixIdx) {
|
if (!prefixIdx) {
|
||||||
int prefixIdxNum = xdbxStringStore(prefix);
|
int prefixIdxNum = xdbxStringStore(prefix);
|
||||||
|
|
@ -443,15 +447,15 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
writeVariableInteger(uriIdxNum);
|
writeVariableInteger(uriIdxNum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param prefix The xml prefix of this xml namespace uri to be ended.
|
* @param prefix The xml prefix of this xml namespace uri to be ended.
|
||||||
* @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
|
* @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void endPrefixMapping(String prefix) throws SAXException {
|
public void endPrefixMapping(String prefix) throws SAXException {
|
||||||
Set<Map.Entry<String,String>> s = prefixMapping.entrySet();
|
Set<Map.Entry<String, String>> s = prefixMapping.entrySet();
|
||||||
String uri = null;
|
String uri = null;
|
||||||
for (Map.Entry<String,String> e : s) {
|
for (Map.Entry<String, String> e : s) {
|
||||||
if (e.getValue() == null) {
|
if (e.getValue() == null) {
|
||||||
continue; // way ?
|
continue; // way ?
|
||||||
}
|
}
|
||||||
|
|
@ -463,12 +467,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
prefixMapping.remove(uri);
|
prefixMapping.remove(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml characters and uses characters(java.lang.String) method.
|
* Prints xml characters and uses characters(java.lang.String) method.
|
||||||
*
|
*
|
||||||
* @param ch Character buffer.
|
* @param ch Character buffer.
|
||||||
* @param start The start index of the chars in the ch buffer.
|
* @param start The start index of the chars in the ch buffer.
|
||||||
* @param length The length index of the chars in the ch buffer.
|
* @param length The length index of the chars in the ch buffer.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
|
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
|
||||||
|
|
@ -476,9 +480,10 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||||
characters(new String(ch, start, length));
|
characters(new String(ch, start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escape and prints xml characters.
|
* Escape and prints xml characters.
|
||||||
|
*
|
||||||
* @param text The text to write.
|
* @param text The text to write.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
* @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String)
|
* @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String)
|
||||||
|
|
@ -489,11 +494,11 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
}
|
}
|
||||||
charactersRaw(SAX3XMLConstants.escapeCharacters(text));
|
charactersRaw(SAX3XMLConstants.escapeCharacters(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void characters(char c) throws SAXException {
|
public void characters(char c) throws SAXException {
|
||||||
characters(new char[]{c}, 0, 1);
|
characters(new char[] { c }, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// move or remove ?
|
// move or remove ?
|
||||||
protected void charactersRaw(String text) throws SAXException {
|
protected void charactersRaw(String text) throws SAXException {
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
|
|
@ -501,12 +506,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
}
|
}
|
||||||
writeTagLengthValue(XDBXContentTag.TEXT_T, text);
|
writeTagLengthValue(XDBXContentTag.TEXT_T, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml ignorable whitespace.
|
* Prints xml ignorable whitespace.
|
||||||
*
|
*
|
||||||
* @param ch Character buffer.
|
* @param ch Character buffer.
|
||||||
* @param start The start index of the chars in the ch buffer.
|
* @param start The start index of the chars in the ch buffer.
|
||||||
* @param length The length index of the chars in the ch buffer.
|
* @param length The length index of the chars in the ch buffer.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
|
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
|
||||||
|
|
@ -514,11 +519,11 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
|
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
|
||||||
ignorableWhitespace(new String(ch, start, length));
|
ignorableWhitespace(new String(ch, start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml ignorable whitespace.
|
* Prints xml ignorable whitespace.
|
||||||
*
|
*
|
||||||
* @param text The text to print.
|
* @param text The text to print.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
* @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String)
|
* @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
|
@ -528,23 +533,23 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
}
|
}
|
||||||
writeTagLengthValue(XDBXContentTag.TEXT_WHITE_SPACE, text);
|
writeTagLengthValue(XDBXContentTag.TEXT_WHITE_SPACE, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml ignorable whitespace character.
|
* Prints xml ignorable whitespace character.
|
||||||
*
|
*
|
||||||
* @param c The character to print.
|
* @param c The character to print.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
*/
|
*/
|
||||||
public void ignorableWhitespace(char c) throws SAXException {
|
public void ignorableWhitespace(char c) throws SAXException {
|
||||||
ignorableWhitespace(new char[]{c}, 0, 1);
|
ignorableWhitespace(new char[] { c }, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml instructions.
|
* Prints xml instructions.
|
||||||
*
|
*
|
||||||
* @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
|
* @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
|
||||||
* @param target The target.
|
* @param target The target.
|
||||||
* @param data The data.
|
* @param data The data.
|
||||||
*/
|
*/
|
||||||
public void processingInstruction(String target, String data) throws SAXException {
|
public void processingInstruction(String target, String data) throws SAXException {
|
||||||
String targetLow = target.toLowerCase();
|
String targetLow = target.toLowerCase();
|
||||||
|
|
@ -557,20 +562,20 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
if (SAX3XMLConstants.isCharString(data) == false) {
|
if (SAX3XMLConstants.isCharString(data) == false) {
|
||||||
throw new SAXException("Processing instruction data is invalid char; '" + data + "'");
|
throw new SAXException("Processing instruction data is invalid char; '" + data + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
//'I' LengthValue StringID
|
// 'I' LengthValue StringID
|
||||||
int targetIdx = xdbxStringStore(target);
|
int targetIdx = xdbxStringStore(target);
|
||||||
writeTagLengthValue(XDBXContentTag.STRING_ID, target);
|
writeTagLengthValue(XDBXContentTag.STRING_ID, target);
|
||||||
writeVariableInteger(targetIdx);
|
writeVariableInteger(targetIdx);
|
||||||
|
|
||||||
//'P' StringID LengthValue
|
// 'P' StringID LengthValue
|
||||||
writeTag(XDBXContentTag.PROCESSING_INSTRUCTION);
|
writeTag(XDBXContentTag.PROCESSING_INSTRUCTION);
|
||||||
writeVariableInteger(targetIdx);
|
writeVariableInteger(targetIdx);
|
||||||
writeLengthValue(data);
|
writeLengthValue(data);
|
||||||
|
|
||||||
writeFlush();
|
writeFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Not implemented.
|
* Not implemented.
|
||||||
*
|
*
|
||||||
|
|
@ -579,7 +584,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
*/
|
*/
|
||||||
public void setDocumentLocator(Locator locator) {
|
public void setDocumentLocator(Locator locator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Not implemented.
|
* Not implemented.
|
||||||
*
|
*
|
||||||
|
|
@ -589,12 +594,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
public void skippedEntity(String name) throws SAXException {
|
public void skippedEntity(String name) throws SAXException {
|
||||||
// is for validating parser support, so not needed in xml writing.
|
// is for validating parser support, so not needed in xml writing.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml comment.
|
* Prints xml comment.
|
||||||
*
|
*
|
||||||
* @param ch Character buffer.
|
* @param ch Character buffer.
|
||||||
* @param start The start index of the chars in the ch buffer.
|
* @param start The start index of the chars in the ch buffer.
|
||||||
* @param length The length index of the chars in the ch buffer.
|
* @param length The length index of the chars in the ch buffer.
|
||||||
* @throws SAXException When IOException has happend while printing.
|
* @throws SAXException When IOException has happend while printing.
|
||||||
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
|
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
|
||||||
|
|
@ -602,7 +607,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
public void comment(char[] ch, int start, int length) throws SAXException {
|
public void comment(char[] ch, int start, int length) throws SAXException {
|
||||||
comment(new String(ch, start, length));
|
comment(new String(ch, start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints xml comment.
|
* Prints xml comment.
|
||||||
*
|
*
|
||||||
|
|
@ -621,7 +626,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
char textStart = text.charAt(0);
|
char textStart = text.charAt(0);
|
||||||
char textEnd = text.charAt(text.length() - 1);
|
char textEnd = text.charAt(text.length() - 1);
|
||||||
if (textStart != ' ' && textStart != '\t' && textStart != '\n') {
|
if (textStart != ' ' && textStart != '\t' && textStart != '\n') {
|
||||||
text = " "+text;
|
text = " " + text;
|
||||||
}
|
}
|
||||||
if (textEnd != ' ' && textEnd != '\t' && textEnd != '\n') {
|
if (textEnd != ' ' && textEnd != '\t' && textEnd != '\n') {
|
||||||
text = text + " ";
|
text = text + " ";
|
||||||
|
|
@ -629,7 +634,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
}
|
}
|
||||||
writeTagLengthValue(XDBXContentTag.COMMENT, SAX3XMLConstants.escapeCharactersComment(text, "", 0));
|
writeTagLengthValue(XDBXContentTag.COMMENT, SAX3XMLConstants.escapeCharactersComment(text, "", 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeFlush() throws SAXException {
|
protected void writeFlush() throws SAXException {
|
||||||
try {
|
try {
|
||||||
out.flush();
|
out.flush();
|
||||||
|
|
@ -637,7 +642,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
throw new SAXException(e);
|
throw new SAXException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void write(byte[] data) throws SAXException {
|
private void write(byte[] data) throws SAXException {
|
||||||
try {
|
try {
|
||||||
out.write(data);
|
out.write(data);
|
||||||
|
|
@ -645,7 +650,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
throw new SAXException(e);
|
throw new SAXException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void write(int c) throws SAXException {
|
private void write(int c) throws SAXException {
|
||||||
try {
|
try {
|
||||||
out.write(c);
|
out.write(c);
|
||||||
|
|
@ -653,23 +658,23 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
throw new SAXException(e);
|
throw new SAXException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeHeaderFlags(OutputStream out, int flags) throws SAXException {
|
public void writeHeaderFlags(OutputStream out, int flags) throws SAXException {
|
||||||
write(flags >> 24);
|
write(flags >> 24);
|
||||||
write(flags >> 16);
|
write(flags >> 16);
|
||||||
write(flags >> 8);
|
write(flags >> 8);
|
||||||
write(flags >> 0);
|
write(flags >> 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeTag(XDBXContentTag tag) throws SAXException {
|
protected void writeTag(XDBXContentTag tag) throws SAXException {
|
||||||
write(tag.getTagNumber());
|
write(tag.getTagNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeTagLengthValue(XDBXContentTag tag, String data) throws SAXException {
|
protected void writeTagLengthValue(XDBXContentTag tag, String data) throws SAXException {
|
||||||
writeTag(tag);
|
writeTag(tag);
|
||||||
writeLengthValue(data);
|
writeLengthValue(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeVariableInteger(int i) throws SAXException {
|
protected void writeVariableInteger(int i) throws SAXException {
|
||||||
if (i < 128) {
|
if (i < 128) {
|
||||||
write(i);
|
write(i);
|
||||||
|
|
@ -684,12 +689,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
|
||||||
write((i >> 7) & 0b1111111 + 128);
|
write((i >> 7) & 0b1111111 + 128);
|
||||||
write(i & 0b1111111);
|
write(i & 0b1111111);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeLengthValue(byte[] data) throws SAXException {
|
protected void writeLengthValue(byte[] data) throws SAXException {
|
||||||
writeVariableInteger(data.length);
|
writeVariableInteger(data.length);
|
||||||
write(data);
|
write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeLengthValue(String data) throws SAXException {
|
protected void writeLengthValue(String data) throws SAXException {
|
||||||
writeLengthValue(data.getBytes(StandardCharsets.UTF_8));
|
writeLengthValue(data.getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io.xdbx;
|
package org.x4o.sax3.io.xdbx;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
|
@ -35,56 +35,57 @@ import org.xml.sax.ext.LexicalHandler;
|
||||||
* @version 1.0 Dec 20, 2024
|
* @version 1.0 Dec 20, 2024
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandler implements LexicalHandler {
|
public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandler implements LexicalHandler {
|
||||||
|
|
||||||
protected boolean printCDATA = false;
|
protected boolean printCDATA = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates writer which prints to the stream interface.
|
* Creates writer which prints to the stream interface.
|
||||||
* @param out The stream to print the xml to.
|
*
|
||||||
|
* @param out The stream to print the xml to.
|
||||||
*/
|
*/
|
||||||
public AbstractXDBXWriterLexical(OutputStream out) {
|
public AbstractXDBXWriterLexical(OutputStream out) {
|
||||||
super(out);
|
super(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#startCDATA()
|
* @see org.xml.sax.ext.LexicalHandler#startCDATA()
|
||||||
*/
|
*/
|
||||||
public void startCDATA() throws SAXException {
|
public void startCDATA() throws SAXException {
|
||||||
printCDATA = true;
|
printCDATA = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#endCDATA()
|
* @see org.xml.sax.ext.LexicalHandler#endCDATA()
|
||||||
*/
|
*/
|
||||||
public void endCDATA() throws SAXException {
|
public void endCDATA() throws SAXException {
|
||||||
printCDATA = false;
|
printCDATA = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String)
|
* @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void startDTD(String name, String publicId, String systemId) throws SAXException {
|
public void startDTD(String name, String publicId, String systemId) throws SAXException {
|
||||||
// not supported
|
// not supported
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#endDTD()
|
* @see org.xml.sax.ext.LexicalHandler#endDTD()
|
||||||
*/
|
*/
|
||||||
public void endDTD() throws SAXException {
|
public void endDTD() throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
|
* @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void startEntity(String arg0) throws SAXException {
|
public void startEntity(String arg0) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
|
* @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public void endEntity(String arg0) throws SAXException {
|
public void endEntity(String arg0) throws SAXException {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(char[], int, int)
|
* @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(char[], int, int)
|
||||||
*/
|
*/
|
||||||
|
|
@ -92,7 +93,7 @@ public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandle
|
||||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||||
characters(new String(ch, start, length));
|
characters(new String(ch, start, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(java.lang.String)
|
* @see org.x4o.sax3.io.AbstractContentWriterHandler#characters(java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,11 @@ package org.x4o.sax3.io.xdbx;
|
||||||
* @version 1.0 Dec 20, 2024
|
* @version 1.0 Dec 20, 2024
|
||||||
*/
|
*/
|
||||||
public final class XDBXConstants {
|
public final class XDBXConstants {
|
||||||
|
|
||||||
static public final byte[] HEADER_MARKER = new byte[] {(byte) 0xCA, 0x3B};
|
static public final byte[] HEADER_MARKER = new byte[] { (byte) 0xCA, 0x3B };
|
||||||
static public final byte HEADER_LENGHT = 0x05;
|
static public final byte HEADER_LENGHT = 0x05;
|
||||||
static public final byte HEADER_VERSION = 0x01;
|
static public final byte HEADER_VERSION = 0x01;
|
||||||
|
|
||||||
static public final int FLAG_XML_SEQUENCE = 0x1;
|
static public final int FLAG_XML_SEQUENCE = 0x1;
|
||||||
static public final int FLAG_STRING_ID = 0x2;
|
static public final int FLAG_STRING_ID = 0x2;
|
||||||
static public final int FLAG_STRING_ID_IDX = 0x20;
|
static public final int FLAG_STRING_ID_IDX = 0x20;
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ package org.x4o.sax3.io.xdbx;
|
||||||
* @version 1.0 Dec 20, 2024
|
* @version 1.0 Dec 20, 2024
|
||||||
*/
|
*/
|
||||||
public enum XDBXContentTag {
|
public enum XDBXContentTag {
|
||||||
|
|
||||||
DOCUMENT_END('Z'),
|
DOCUMENT_END('Z'),
|
||||||
COMPLETED_DOC('d'),
|
COMPLETED_DOC('d'),
|
||||||
ATOMIC_VALUE('V'),
|
ATOMIC_VALUE('V'),
|
||||||
|
|
@ -54,15 +54,14 @@ public enum XDBXContentTag {
|
||||||
PROCESSING_INSTRUCTION('P'),
|
PROCESSING_INSTRUCTION('P'),
|
||||||
STRING_ID('I'),
|
STRING_ID('I'),
|
||||||
HINT('H'),
|
HINT('H'),
|
||||||
SEQUENCE_SEPERATOR('@'),
|
SEQUENCE_SEPERATOR('@'),;
|
||||||
;
|
|
||||||
|
|
||||||
private final int tagNumber;
|
private final int tagNumber;
|
||||||
|
|
||||||
private XDBXContentTag(char tag) {
|
private XDBXContentTag(char tag) {
|
||||||
tagNumber = tag;
|
tagNumber = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTagNumber() {
|
public int getTagNumber() {
|
||||||
return tagNumber;
|
return tagNumber;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io.xdbx;
|
package org.x4o.sax3.io.xdbx;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
@ -39,7 +39,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 Dec 20, 2024
|
* @version 1.0 Dec 20, 2024
|
||||||
*/
|
*/
|
||||||
public class XDBXReaderXml {
|
public class XDBXReaderXml {
|
||||||
|
|
||||||
private final ContentWriter out;
|
private final ContentWriter out;
|
||||||
private final Map<Integer, String> stringIdx;
|
private final Map<Integer, String> stringIdx;
|
||||||
|
|
@ -48,19 +48,19 @@ public class XDBXReaderXml {
|
||||||
private String docEncoding;
|
private String docEncoding;
|
||||||
private Stack<XDBXElement> elementStack;
|
private Stack<XDBXElement> elementStack;
|
||||||
private boolean failOnUnsupportedTag = true;
|
private boolean failOnUnsupportedTag = true;
|
||||||
|
|
||||||
public XDBXReaderXml(ContentWriter out) {
|
public XDBXReaderXml(ContentWriter out) {
|
||||||
this.out = out;
|
this.out = out;
|
||||||
this.stringIdx = new HashMap<>();
|
this.stringIdx = new HashMap<>();
|
||||||
this.elementStack = new Stack<>();
|
this.elementStack = new Stack<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: replace with proper PropertyConfig support
|
// TODO: replace with proper PropertyConfig support
|
||||||
public XDBXReaderXml withNoFailOnUnsupportedTag() {
|
public XDBXReaderXml withNoFailOnUnsupportedTag() {
|
||||||
failOnUnsupportedTag = false;
|
failOnUnsupportedTag = false;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parse(InputStream in) throws IOException {
|
public void parse(InputStream in) throws IOException {
|
||||||
if (!Arrays.equals(XDBXConstants.HEADER_MARKER, in.readNBytes(2))) {
|
if (!Arrays.equals(XDBXConstants.HEADER_MARKER, in.readNBytes(2))) {
|
||||||
throw new IOException("Wrong magic marker");
|
throw new IOException("Wrong magic marker");
|
||||||
|
|
@ -92,7 +92,7 @@ public class XDBXReaderXml {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseToken(int token, InputStream in) throws IOException, SAXException {
|
private void parseToken(int token, InputStream in) throws IOException, SAXException {
|
||||||
if (XDBXContentTag.STRING_ID.getTagNumber() == token) {
|
if (XDBXContentTag.STRING_ID.getTagNumber() == token) {
|
||||||
String value = readLengthValue(in);
|
String value = readLengthValue(in);
|
||||||
|
|
@ -233,10 +233,10 @@ public class XDBXReaderXml {
|
||||||
return; // NOP is done by caller
|
return; // NOP is done by caller
|
||||||
}
|
}
|
||||||
if (failOnUnsupportedTag) {
|
if (failOnUnsupportedTag) {
|
||||||
throw new SAXException("Unsupported tag: " + (char)token + " 0x" + Integer.toHexString(token).toUpperCase());
|
throw new SAXException("Unsupported tag: " + (char) token + " 0x" + Integer.toHexString(token).toUpperCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void flushDocDeclaration() throws SAXException {
|
protected void flushDocDeclaration() throws SAXException {
|
||||||
if (docMetaFlushed) {
|
if (docMetaFlushed) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -244,7 +244,7 @@ public class XDBXReaderXml {
|
||||||
docMetaFlushed = true;
|
docMetaFlushed = true;
|
||||||
out.declaration(docXmlVersion, docEncoding, "");
|
out.declaration(docXmlVersion, docEncoding, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void flushElement() throws SAXException {
|
protected void flushElement() throws SAXException {
|
||||||
flushDocDeclaration();
|
flushDocDeclaration();
|
||||||
if (elementStack.isEmpty()) {
|
if (elementStack.isEmpty()) {
|
||||||
|
|
@ -257,13 +257,13 @@ public class XDBXReaderXml {
|
||||||
element.started = true;
|
element.started = true;
|
||||||
out.startElement(element.uri, element.localName, element.name, element.atts);
|
out.startElement(element.uri, element.localName, element.name, element.atts);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String readLengthValue(InputStream in) throws IOException {
|
protected String readLengthValue(InputStream in) throws IOException {
|
||||||
int len = readVariableInteger(in);
|
int len = readVariableInteger(in);
|
||||||
String value = new String(in.readNBytes(len));
|
String value = new String(in.readNBytes(len));
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int readVariableInteger(InputStream in) throws IOException {
|
protected int readVariableInteger(InputStream in) throws IOException {
|
||||||
int result = in.read();
|
int result = in.read();
|
||||||
if (result < 128) {
|
if (result < 128) {
|
||||||
|
|
@ -275,7 +275,7 @@ public class XDBXReaderXml {
|
||||||
}
|
}
|
||||||
return result + (in.read() << 14);
|
return result + (in.read() << 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int readHeaderFlags(InputStream in) throws IOException {
|
public int readHeaderFlags(InputStream in) throws IOException {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
result += in.read() << 24;
|
result += in.read() << 24;
|
||||||
|
|
@ -284,7 +284,7 @@ public class XDBXReaderXml {
|
||||||
result += in.read() << 0;
|
result += in.read() << 0;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDocXmlVersion() {
|
public String getDocXmlVersion() {
|
||||||
return docXmlVersion;
|
return docXmlVersion;
|
||||||
}
|
}
|
||||||
|
|
@ -292,17 +292,18 @@ public class XDBXReaderXml {
|
||||||
public String getDocEncoding() {
|
public String getDocEncoding() {
|
||||||
return docEncoding;
|
return docEncoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
class XDBXElement {
|
class XDBXElement {
|
||||||
String uri;
|
String uri;
|
||||||
String localName;
|
String localName;
|
||||||
String name;
|
String name;
|
||||||
final AttributesImpl atts;
|
final AttributesImpl atts;
|
||||||
boolean started = false;
|
boolean started = false;
|
||||||
|
|
||||||
XDBXElement() {
|
XDBXElement() {
|
||||||
atts = new AttributesImpl();
|
atts = new AttributesImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
XDBXElement(String localName) {
|
XDBXElement(String localName) {
|
||||||
this();
|
this();
|
||||||
this.localName = localName;
|
this.localName = localName;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.x4o.sax3.io.xdbx;
|
package org.x4o.sax3.io.xdbx;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
|
@ -30,11 +30,12 @@ import java.io.OutputStream;
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 Dev 20, 2024
|
* @version 1.0 Dev 20, 2024
|
||||||
*/
|
*/
|
||||||
public class XDBXWriterXml extends AbstractXDBXWriter {
|
public class XDBXWriterXml extends AbstractXDBXWriter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates XmlWriter which prints to the OutputStream interface.
|
* Creates XmlWriter which prints to the OutputStream interface.
|
||||||
* @param out The OutputStream to write to.
|
*
|
||||||
|
* @param out The OutputStream to write to.
|
||||||
*/
|
*/
|
||||||
public XDBXWriterXml(OutputStream out) {
|
public XDBXWriterXml(OutputStream out) {
|
||||||
super(out);
|
super(out);
|
||||||
|
|
|
||||||
|
|
@ -47,39 +47,41 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||||
* @version 1.0 S 17, 2012
|
* @version 1.0 S 17, 2012
|
||||||
*/
|
*/
|
||||||
public class SAX3WriterXmlAttributeTest {
|
public class SAX3WriterXmlAttributeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttributeNormal() throws Exception {
|
public void testAttributeNormal() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||||
writer.startDocument();
|
writer.startDocument();
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "attr", "", "", "foobar");
|
atts.addAttribute("", "attr", "", "", "foobar");
|
||||||
writer.startElementEnd("", "test", "", atts);
|
writer.startElementEnd("", "test", "", atts);
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test attr=\"foobar\"/>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test attr=\"foobar\"/>"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttributeEscape() throws Exception {
|
public void testAttributeEscape() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||||
writer.startDocument();
|
writer.startDocument();
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "attr", "", "", "<test/> & 'foobar' is \"quoted\"!");
|
atts.addAttribute("", "attr", "", "", "<test/> & 'foobar' is \"quoted\"!");
|
||||||
writer.startElementEnd("", "test", "", atts);
|
writer.startElementEnd("", "test", "", atts);
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test attr=\"<test/> & 'foobar' is "quoted"!\"/>"), output);
|
Assertions.assertTrue(
|
||||||
|
output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test attr=\"<test/> & 'foobar' is "quoted"!\"/>"),
|
||||||
|
output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttributeWhiteSpace() throws Exception {
|
public void testAttributeWhiteSpace() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -87,57 +89,57 @@ public class SAX3WriterXmlAttributeTest {
|
||||||
writer.startDocument();
|
writer.startDocument();
|
||||||
Assertions.assertThrows(SAXException.class, () -> {
|
Assertions.assertThrows(SAXException.class, () -> {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "", "", "", "junit");
|
atts.addAttribute("", "", "", "", "junit");
|
||||||
writer.startElementEnd("", "test", "", atts);
|
writer.startElementEnd("", "test", "", atts);
|
||||||
});
|
});
|
||||||
Assertions.assertThrows(SAXException.class, () -> {
|
Assertions.assertThrows(SAXException.class, () -> {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", " ", "", "", "junit");
|
atts.addAttribute("", " ", "", "", "junit");
|
||||||
writer.startElementEnd("", "test", "", atts);
|
writer.startElementEnd("", "test", "", atts);
|
||||||
});
|
});
|
||||||
Assertions.assertThrows(SAXException.class, () -> {
|
Assertions.assertThrows(SAXException.class, () -> {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "foo bar", "", "", "junit");
|
atts.addAttribute("", "foo bar", "", "", "junit");
|
||||||
writer.startElementEnd("", "test", "", atts);
|
writer.startElementEnd("", "test", "", atts);
|
||||||
});
|
});
|
||||||
Assertions.assertThrows(SAXException.class, () -> {
|
Assertions.assertThrows(SAXException.class, () -> {
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "foobar", "", "", "junit");
|
atts.addAttribute("", "foobar", "", "", "junit");
|
||||||
writer.startElementEnd("", "test junit", "", atts);
|
writer.startElementEnd("", "test junit", "", atts);
|
||||||
});
|
});
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "abc", "", "", " junit ");
|
atts.addAttribute("", "abc", "", "", " junit ");
|
||||||
writer.startElementEnd("", "root", "", atts);
|
writer.startElementEnd("", "root", "", atts);
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root abc=\" junit \"/>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root abc=\" junit \"/>"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttributeChinees() throws Exception {
|
public void testAttributeChinees() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||||
writer.startDocument();
|
writer.startDocument();
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "仙上主天", "", "", "仙上主天");
|
atts.addAttribute("", "仙上主天", "", "", "仙上主天");
|
||||||
writer.startElementEnd("", "chinees", "", atts);
|
writer.startElementEnd("", "chinees", "", atts);
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<chinees 仙上主天=\"仙上主天\"/>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<chinees 仙上主天=\"仙上主天\"/>"), output);
|
||||||
|
|
||||||
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
|
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
|
||||||
SAXParser saxParser = saxFactory.newSAXParser();
|
SAXParser saxParser = saxFactory.newSAXParser();
|
||||||
XMLReader saxReader = saxParser.getXMLReader();
|
XMLReader saxReader = saxParser.getXMLReader();
|
||||||
saxReader.parse(new InputSource(new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8))));
|
saxReader.parse(new InputSource(new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8))));
|
||||||
Assertions.assertNotNull(saxReader);
|
Assertions.assertNotNull(saxReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttributeBrahmi() throws Exception {
|
public void testAttributeBrahmi() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -145,38 +147,40 @@ public class SAX3WriterXmlAttributeTest {
|
||||||
// Legal by spec, but not in JVM SAX Reader
|
// Legal by spec, but not in JVM SAX Reader
|
||||||
writer.startDocument();
|
writer.startDocument();
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕", "", "", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕");
|
atts.addAttribute("", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕", "", "", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕");
|
||||||
atts.addAttribute ("", "ᒡᒢᑊᒻᒻᓫᔿ", "", "", "ᒡᒢᑊᒻᒻᓫᔿ");
|
atts.addAttribute("", "ᒡᒢᑊᒻᒻᓫᔿ", "", "", "ᒡᒢᑊᒻᒻᓫᔿ");
|
||||||
writer.startElementEnd("", "test", "", atts);
|
writer.startElementEnd("", "test", "", atts);
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test 𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕=\"𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕\" ᒡᒢᑊᒻᒻᓫᔿ=\"ᒡᒢᑊᒻᒻᓫᔿ\"/>"), output);
|
Assertions.assertTrue(output.equals(
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test 𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕=\"𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕\" ᒡᒢᑊᒻᒻᓫᔿ=\"ᒡᒢᑊᒻᒻᓫᔿ\"/>"),
|
||||||
|
output);
|
||||||
|
|
||||||
// TODO: fix SAX impl
|
// TODO: fix SAX impl
|
||||||
Assertions.assertThrows(SAXException.class, () -> {
|
Assertions.assertThrows(SAXException.class, () -> {
|
||||||
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
|
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
|
||||||
SAXParser saxParser = saxFactory.newSAXParser();
|
SAXParser saxParser = saxFactory.newSAXParser();
|
||||||
XMLReader saxReader = saxParser.getXMLReader();
|
XMLReader saxReader = saxParser.getXMLReader();
|
||||||
saxReader.parse(new InputSource(new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8))));
|
saxReader.parse(new InputSource(new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8))));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createLongAttribute(Map<String,Object> para) throws SAXException, IOException {
|
private String createLongAttribute(Map<String, Object> para) throws SAXException, IOException {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||||
for (String key:para.keySet()) {
|
for (String key : para.keySet()) {
|
||||||
Object value = para.get(key);
|
Object value = para.get(key);
|
||||||
writer.getPropertyConfig().setProperty(key, value);
|
writer.getPropertyConfig().setProperty(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
String data = "_FOR_FOO_BAR";
|
String data = "_FOR_FOO_BAR";
|
||||||
String dataValue = "LOOP";
|
String dataValue = "LOOP";
|
||||||
for (int i=0;i<15;i++) {
|
for (int i = 0; i < 15; i++) {
|
||||||
atts.addAttribute("", "attr"+i, "", "", dataValue+=data);
|
atts.addAttribute("", "attr" + i, "", "", dataValue += data);
|
||||||
}
|
}
|
||||||
writer.startDocument();
|
writer.startDocument();
|
||||||
writer.startElement("", "test", "", atts);
|
writer.startElement("", "test", "", atts);
|
||||||
|
|
@ -187,43 +191,43 @@ public class SAX3WriterXmlAttributeTest {
|
||||||
}
|
}
|
||||||
return outputWriter.toString();
|
return outputWriter.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttributeLongNormal() throws Exception {
|
public void testAttributeLongNormal() throws Exception {
|
||||||
Map<String,Object> para = new HashMap<String,Object>();
|
Map<String, Object> para = new HashMap<String, Object>();
|
||||||
String output = createLongAttribute(para);
|
String output = createLongAttribute(para);
|
||||||
int newlines = output.split("\n").length;
|
int newlines = output.split("\n").length;
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(newlines==4, "outputs: "+newlines);
|
Assertions.assertTrue(newlines == 4, "outputs: " + newlines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttributeLongPerLine() throws Exception {
|
public void testAttributeLongPerLine() throws Exception {
|
||||||
Map<String,Object> para = new HashMap<String,Object>();
|
Map<String, Object> para = new HashMap<String, Object>();
|
||||||
para.put(SAX3WriterXml.OUTPUT_LINE_PER_ATTRIBUTE, true);
|
para.put(SAX3WriterXml.OUTPUT_LINE_PER_ATTRIBUTE, true);
|
||||||
String output = createLongAttribute(para);
|
String output = createLongAttribute(para);
|
||||||
int newlines = output.split("\n").length;
|
int newlines = output.split("\n").length;
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(newlines==20, "outputs: "+newlines);
|
Assertions.assertTrue(newlines == 20, "outputs: " + newlines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttributeLongSplit80() throws Exception {
|
public void testAttributeLongSplit80() throws Exception {
|
||||||
Map<String,Object> para = new HashMap<String,Object>();
|
Map<String, Object> para = new HashMap<String, Object>();
|
||||||
para.put(SAX3WriterXml.OUTPUT_LINE_BREAK_WIDTH, 80);
|
para.put(SAX3WriterXml.OUTPUT_LINE_BREAK_WIDTH, 80);
|
||||||
String output = createLongAttribute(para);
|
String output = createLongAttribute(para);
|
||||||
int newlines = output.split("\n").length;
|
int newlines = output.split("\n").length;
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(newlines==16, "outputs: "+newlines);
|
Assertions.assertTrue(newlines == 16, "outputs: " + newlines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttributeLongSplit180() throws Exception {
|
public void testAttributeLongSplit180() throws Exception {
|
||||||
Map<String,Object> para = new HashMap<String,Object>();
|
Map<String, Object> para = new HashMap<String, Object>();
|
||||||
para.put(SAX3WriterXml.OUTPUT_LINE_BREAK_WIDTH, 180);
|
para.put(SAX3WriterXml.OUTPUT_LINE_BREAK_WIDTH, 180);
|
||||||
String output = createLongAttribute(para);
|
String output = createLongAttribute(para);
|
||||||
int newlines = output.split("\n").length;
|
int newlines = output.split("\n").length;
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(newlines==11, "outputs: "+newlines);
|
Assertions.assertTrue(newlines == 11, "outputs: " + newlines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ import org.x4o.sax3.SAX3WriterXml;
|
||||||
* @version 1.0 Sep 17, 2013
|
* @version 1.0 Sep 17, 2013
|
||||||
*/
|
*/
|
||||||
public class SAX3WriterXmlCDataTest {
|
public class SAX3WriterXmlCDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCDATANone() throws Exception {
|
public void testCDATANone() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -46,10 +46,10 @@ public class SAX3WriterXmlCDataTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>foobar"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>foobar"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCDATANoneTagEscape() throws Exception {
|
public void testCDATANoneTagEscape() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -60,10 +60,10 @@ public class SAX3WriterXmlCDataTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>foobar<test/>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>foobar<test/>"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCDATANormal() throws Exception {
|
public void testCDATANormal() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -76,10 +76,10 @@ public class SAX3WriterXmlCDataTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar]]>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar]]>"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCDATAEscapeTag() throws Exception {
|
public void testCDATAEscapeTag() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -92,10 +92,10 @@ public class SAX3WriterXmlCDataTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar<test/>]]>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar<test/>]]>"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCDATAEscapeStart() throws Exception {
|
public void testCDATAEscapeStart() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -108,10 +108,10 @@ public class SAX3WriterXmlCDataTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar]]>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar]]>"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCDATAEscapeEnd() throws Exception {
|
public void testCDATAEscapeEnd() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -124,10 +124,10 @@ public class SAX3WriterXmlCDataTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar]]>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[foobar]]>"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCDATAEscapeEndEskimo() throws Exception {
|
public void testCDATAEscapeEndEskimo() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -140,10 +140,10 @@ public class SAX3WriterXmlCDataTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[ᒡᒢᑊᒻᒻᓫᔿ]]>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[ᒡᒢᑊᒻᒻᓫᔿ]]>"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCDATAEscapeInvalid() throws Exception {
|
public void testCDATAEscapeInvalid() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -156,10 +156,10 @@ public class SAX3WriterXmlCDataTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[tokens like \'\' are <invalid>]]>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[tokens like \'\' are <invalid>]]>"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCDATAEscapeValid() throws Exception {
|
public void testCDATAEscapeValid() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -172,7 +172,7 @@ public class SAX3WriterXmlCDataTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[tokens like \']]>\' are <valid>]]>"));
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><![CDATA[tokens like \']]>\' are <valid>]]>"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||||
* @version 1.0 Aug 26, 2012
|
* @version 1.0 Aug 26, 2012
|
||||||
*/
|
*/
|
||||||
public class SAX3WriterXmlTest {
|
public class SAX3WriterXmlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCharactersNormal() throws Exception {
|
public void testCharactersNormal() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -48,10 +48,10 @@ public class SAX3WriterXmlTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>test is foobar!"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>test is foobar!"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCharactersEscape() throws Exception {
|
public void testCharactersEscape() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -62,10 +62,10 @@ public class SAX3WriterXmlTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test/> & 'foobar' is "quoted"!"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><test/> & 'foobar' is "quoted"!"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCommentNormal() throws Exception {
|
public void testCommentNormal() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -76,10 +76,10 @@ public class SAX3WriterXmlTest {
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!-- foobar -->"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!-- foobar -->"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCommentEscape() throws Exception {
|
public void testCommentEscape() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -89,17 +89,17 @@ public class SAX3WriterXmlTest {
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
}
|
}
|
||||||
// note two space because auto-space is before escaping and places spaces over comment tags.
|
// note two space because auto-space is before escaping and places spaces over comment tags.
|
||||||
// 1) "<!-- foobar -->" - argu
|
// 1) "<!-- foobar -->" - argu
|
||||||
// 2) " <!-- foobar --> " - auto-space (default enabled)
|
// 2) " <!-- foobar --> " - auto-space (default enabled)
|
||||||
// 3) " foobar " - escapes
|
// 3) " foobar " - escapes
|
||||||
// 4) "<!-- foobar -->" - printed
|
// 4) "<!-- foobar -->" - printed
|
||||||
|
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!-- foobar -->"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!-- foobar -->"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testXmlInvalid() throws Exception {
|
public void testXmlInvalid() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -110,13 +110,13 @@ public class SAX3WriterXmlTest {
|
||||||
writer.startElement("", "test", "", atts);
|
writer.startElement("", "test", "", atts);
|
||||||
writer.startElement("", "foobar", "", atts);
|
writer.startElement("", "foobar", "", atts);
|
||||||
writer.endElement("", "test", "");
|
writer.endElement("", "test", "");
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
});
|
});
|
||||||
Assertions.assertTrue(e.getMessage().contains("tag"));
|
Assertions.assertTrue(e.getMessage().contains("tag"));
|
||||||
Assertions.assertTrue(e.getMessage().contains("foobar"));
|
Assertions.assertTrue(e.getMessage().contains("foobar"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testXmlInvalidEnd() throws Exception {
|
public void testXmlInvalidEnd() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -133,7 +133,7 @@ public class SAX3WriterXmlTest {
|
||||||
Assertions.assertTrue(e.getMessage().contains("open"));
|
Assertions.assertTrue(e.getMessage().contains("open"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessingInstruction() throws Exception {
|
public void testProcessingInstruction() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -143,14 +143,14 @@ public class SAX3WriterXmlTest {
|
||||||
writer.processingInstruction("target", "data");
|
writer.processingInstruction("target", "data");
|
||||||
writer.startElement("", "test", "", atts);
|
writer.startElement("", "test", "", atts);
|
||||||
writer.endElement("", "test", "");
|
writer.endElement("", "test", "");
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?target data?>\n<test/>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?target data?>\n<test/>"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessingInstructionInline() throws Exception {
|
public void testProcessingInstructionInline() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -161,14 +161,15 @@ public class SAX3WriterXmlTest {
|
||||||
writer.startElement("", "test", "", atts);
|
writer.startElement("", "test", "", atts);
|
||||||
writer.processingInstruction("target-doc", "data-doc");
|
writer.processingInstruction("target-doc", "data-doc");
|
||||||
writer.endElement("", "test", "");
|
writer.endElement("", "test", "");
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
}
|
}
|
||||||
String output = outputWriter.toString();
|
String output = outputWriter.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length()>0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?target data?>\n<test>\n\t<?target-doc data-doc?>\n</test>\n"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?target data?>\n<test>\n\t<?target-doc data-doc?>\n</test>\n"),
|
||||||
|
output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessingInstructionTargetXmlPrefix() throws Exception {
|
public void testProcessingInstructionTargetXmlPrefix() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -181,7 +182,7 @@ public class SAX3WriterXmlTest {
|
||||||
Assertions.assertTrue(e.getMessage().contains("start with xml"));
|
Assertions.assertTrue(e.getMessage().contains("start with xml"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessingInstructionTargetNoneNameChar() throws Exception {
|
public void testProcessingInstructionTargetNoneNameChar() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
|
|
@ -195,14 +196,14 @@ public class SAX3WriterXmlTest {
|
||||||
Assertions.assertTrue(e.getMessage().contains("4Prefix"));
|
Assertions.assertTrue(e.getMessage().contains("4Prefix"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessingInstructionDataNoneChar() throws Exception {
|
public void testProcessingInstructionDataNoneChar() throws Exception {
|
||||||
StringWriter outputWriter = new StringWriter();
|
StringWriter outputWriter = new StringWriter();
|
||||||
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
|
||||||
SAXException e = Assertions.assertThrows(SAXException.class, () -> {
|
SAXException e = Assertions.assertThrows(SAXException.class, () -> {
|
||||||
writer.startDocument();
|
writer.startDocument();
|
||||||
writer.processingInstruction("target", "isInvalidChar="+0xD800);
|
writer.processingInstruction("target", "isInvalidChar=" + 0xD800);
|
||||||
});
|
});
|
||||||
Assertions.assertTrue(e.getMessage().contains("instruction"));
|
Assertions.assertTrue(e.getMessage().contains("instruction"));
|
||||||
Assertions.assertTrue(e.getMessage().contains("invalid char"));
|
Assertions.assertTrue(e.getMessage().contains("invalid char"));
|
||||||
|
|
|
||||||
|
|
@ -45,61 +45,61 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||||
* @version 1.0 Dec 21, 2024
|
* @version 1.0 Dec 21, 2024
|
||||||
*/
|
*/
|
||||||
public class XDBXReaderXmlTest {
|
public class XDBXReaderXmlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadWrite() throws Exception {
|
public void testReadWrite() throws Exception {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
try (XDBXWriterXml writer = new XDBXWriterXml(baos)) {
|
try (XDBXWriterXml writer = new XDBXWriterXml(baos)) {
|
||||||
writer.startDocument();
|
writer.startDocument();
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "attr", "", "", "foobar");
|
atts.addAttribute("", "attr", "", "", "foobar");
|
||||||
writer.startElementEnd("", "test", "", atts);
|
writer.startElementEnd("", "test", "", atts);
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringWriter outputXmlStr = new StringWriter();
|
StringWriter outputXmlStr = new StringWriter();
|
||||||
SAX3WriterXml outputXml = new SAX3WriterXml(outputXmlStr);
|
SAX3WriterXml outputXml = new SAX3WriterXml(outputXmlStr);
|
||||||
XDBXReaderXml reader = new XDBXReaderXml(outputXml);
|
XDBXReaderXml reader = new XDBXReaderXml(outputXml);
|
||||||
byte[] writeData = baos.toByteArray();
|
byte[] writeData = baos.toByteArray();
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(writeData);
|
ByteArrayInputStream bais = new ByteArrayInputStream(writeData);
|
||||||
reader.parse(bais);
|
reader.parse(bais);
|
||||||
|
|
||||||
String output = outputXmlStr.toString();
|
String output = outputXmlStr.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length() > 0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test attr=\"foobar\"/>"), output);
|
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test attr=\"foobar\"/>"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadWritePom() throws Exception {
|
public void testReadWritePom() throws Exception {
|
||||||
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
|
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
|
||||||
saxFactory.setNamespaceAware(true);
|
saxFactory.setNamespaceAware(true);
|
||||||
SAXParser saxParser = saxFactory.newSAXParser();
|
SAXParser saxParser = saxFactory.newSAXParser();
|
||||||
XMLReader saxReader = saxParser.getXMLReader();
|
XMLReader saxReader = saxParser.getXMLReader();
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
XDBXWriterXml writer = new XDBXWriterXml(baos);
|
XDBXWriterXml writer = new XDBXWriterXml(baos);
|
||||||
|
|
||||||
saxReader.setContentHandler(writer);
|
saxReader.setContentHandler(writer);
|
||||||
saxReader.parse(new InputSource(new FileInputStream(new File("../pom.xml"))));
|
saxReader.parse(new InputSource(new FileInputStream(new File("../pom.xml"))));
|
||||||
|
|
||||||
StringWriter outputXmlStr = new StringWriter();
|
StringWriter outputXmlStr = new StringWriter();
|
||||||
SAX3WriterXml outputXml = new SAX3WriterXml(outputXmlStr);
|
SAX3WriterXml outputXml = new SAX3WriterXml(outputXmlStr);
|
||||||
XDBXReaderXml reader = new XDBXReaderXml(outputXml);
|
XDBXReaderXml reader = new XDBXReaderXml(outputXml);
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
reader.parse(bais);
|
reader.parse(bais);
|
||||||
|
|
||||||
String output = outputXmlStr.toString();
|
String output = outputXmlStr.toString();
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length() > 0);
|
Assertions.assertTrue(output.length() > 0);
|
||||||
Assertions.assertTrue(output.contains("<artifactId>nx01-x4o-driver</artifactId>"), output);
|
Assertions.assertTrue(output.contains("<artifactId>nx01-x4o-driver</artifactId>"), output);
|
||||||
|
|
||||||
long sizePom = new File("../pom.xml").length();
|
long sizePom = new File("../pom.xml").length();
|
||||||
long sizeXDBX = baos.toByteArray().length;
|
long sizeXDBX = baos.toByteArray().length;
|
||||||
|
|
||||||
System.out.println("size-pom.xml:: " + sizePom);
|
System.out.println("size-pom.xml:: " + sizePom);
|
||||||
System.out.println("size-pom.xdbx: " + sizeXDBX);
|
System.out.println("size-pom.xdbx: " + sizeXDBX);
|
||||||
|
|
||||||
Assertions.assertTrue(sizePom > sizeXDBX, "XDBX is not smaller");
|
Assertions.assertTrue(sizePom > sizeXDBX, "XDBX is not smaller");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,104 +38,103 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||||
* @version 1.0 Dec 21, 2024
|
* @version 1.0 Dec 21, 2024
|
||||||
*/
|
*/
|
||||||
public class XDBXWriterXmlTest {
|
public class XDBXWriterXmlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExample1DefaultEncoding() throws Exception {
|
public void testExample1DefaultEncoding() throws Exception {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
try (XDBXWriterXml writer = new XDBXWriterXml(baos)) {
|
try (XDBXWriterXml writer = new XDBXWriterXml(baos)) {
|
||||||
writer.getPropertyConfig().setProperty(XDBXWriterXml.OUTPUT_DECLARATION, false);
|
writer.getPropertyConfig().setProperty(XDBXWriterXml.OUTPUT_DECLARATION, false);
|
||||||
|
|
||||||
writer.startDocument();
|
writer.startDocument();
|
||||||
writer.startElement("", "root", "", new AttributesImpl());
|
writer.startElement("", "root", "", new AttributesImpl());
|
||||||
|
|
||||||
AttributesImpl atts = new AttributesImpl();
|
AttributesImpl atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "mgr", "", "", "NO");
|
atts.addAttribute("", "mgr", "", "", "NO");
|
||||||
writer.startElement("", "name", "", atts);
|
writer.startElement("", "name", "", atts);
|
||||||
writer.characters("Joe");
|
writer.characters("Joe");
|
||||||
writer.endElement("", "name", "");
|
writer.endElement("", "name", "");
|
||||||
|
|
||||||
writer.startElement("", "name", "", new AttributesImpl());
|
writer.startElement("", "name", "", new AttributesImpl());
|
||||||
writer.characters("Susan");
|
writer.characters("Susan");
|
||||||
writer.endElement("", "name", "");
|
writer.endElement("", "name", "");
|
||||||
writer.startElement("", "name", "", new AttributesImpl());
|
writer.startElement("", "name", "", new AttributesImpl());
|
||||||
writer.characters("Bill");
|
writer.characters("Bill");
|
||||||
writer.endElement("", "name", "");
|
writer.endElement("", "name", "");
|
||||||
|
|
||||||
writer.endElement("", "root", "");
|
writer.endElement("", "root", "");
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] output = baos.toByteArray();
|
byte[] output = baos.toByteArray();
|
||||||
int outIdx = 8;
|
int outIdx = 8;
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length > 0);
|
Assertions.assertTrue(output.length > 0);
|
||||||
Assertions.assertEquals((byte)'X', output[outIdx++]);
|
Assertions.assertEquals((byte) 'X', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'r', output[outIdx++]);
|
Assertions.assertEquals((byte) 'r', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'o', output[outIdx++]);
|
Assertions.assertEquals((byte) 'o', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'o', output[outIdx++]);
|
Assertions.assertEquals((byte) 'o', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'t', output[outIdx++]);
|
Assertions.assertEquals((byte) 't', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 1, output[outIdx++]);
|
Assertions.assertEquals((byte) 1, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((byte)'X', output[outIdx++]);
|
Assertions.assertEquals((byte) 'X', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'n', output[outIdx++]);
|
Assertions.assertEquals((byte) 'n', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'a', output[outIdx++]);
|
Assertions.assertEquals((byte) 'a', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'m', output[outIdx++]);
|
Assertions.assertEquals((byte) 'm', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'e', output[outIdx++]);
|
Assertions.assertEquals((byte) 'e', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((byte)'Y', output[outIdx++]);
|
Assertions.assertEquals((byte) 'Y', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'m', output[outIdx++]);
|
Assertions.assertEquals((byte) 'm', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'g', output[outIdx++]);
|
Assertions.assertEquals((byte) 'g', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'r', output[outIdx++]);
|
Assertions.assertEquals((byte) 'r', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'N', output[outIdx++]);
|
Assertions.assertEquals((byte) 'N', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'O', output[outIdx++]);
|
Assertions.assertEquals((byte) 'O', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'T', output[outIdx++]);
|
Assertions.assertEquals((byte) 'T', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'J', output[outIdx++]);
|
Assertions.assertEquals((byte) 'J', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'o', output[outIdx++]);
|
Assertions.assertEquals((byte) 'o', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'e', output[outIdx++]);
|
Assertions.assertEquals((byte) 'e', output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((byte)'z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'z', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'e', output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
Assertions.assertEquals((byte) 'e', output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
//Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
// Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
||||||
//Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
// Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
||||||
Assertions.assertEquals((byte)'T', output[outIdx++]);
|
Assertions.assertEquals((byte) 'T', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 5, output[outIdx++]);
|
Assertions.assertEquals((byte) 5, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'S', output[outIdx++]);
|
Assertions.assertEquals((byte) 'S', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'u', output[outIdx++]);
|
Assertions.assertEquals((byte) 'u', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'s', output[outIdx++]);
|
Assertions.assertEquals((byte) 's', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'a', output[outIdx++]);
|
Assertions.assertEquals((byte) 'a', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'n', output[outIdx++]);
|
Assertions.assertEquals((byte) 'n', output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((byte)'z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'z', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'e', output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
Assertions.assertEquals((byte) 'e', output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
//Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
// Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
||||||
//Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
// Assertions.assertEquals((byte) 0, output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
|
||||||
Assertions.assertEquals((byte)'T', output[outIdx++]);
|
Assertions.assertEquals((byte) 'T', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'B', output[outIdx++]);
|
Assertions.assertEquals((byte) 'B', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'i', output[outIdx++]);
|
Assertions.assertEquals((byte) 'i', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'l', output[outIdx++]);
|
Assertions.assertEquals((byte) 'l', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'l', output[outIdx++]);
|
Assertions.assertEquals((byte) 'l', output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((byte)'z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'z', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'z', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'Z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'Z', output[outIdx++]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExample3StringIds() throws Exception {
|
public void testExample3StringIds() throws Exception {
|
||||||
|
|
@ -143,14 +142,14 @@ public class XDBXWriterXmlTest {
|
||||||
try (XDBXWriterXml writer = new XDBXWriterXml(baos)) {
|
try (XDBXWriterXml writer = new XDBXWriterXml(baos)) {
|
||||||
writer.getPropertyConfig().setProperty(XDBXWriterXml.OUTPUT_DECLARATION, false);
|
writer.getPropertyConfig().setProperty(XDBXWriterXml.OUTPUT_DECLARATION, false);
|
||||||
AttributesImpl atts;
|
AttributesImpl atts;
|
||||||
|
|
||||||
writer.startDocument();
|
writer.startDocument();
|
||||||
writer.startPrefixMapping("foo", "bar");
|
writer.startPrefixMapping("foo", "bar");
|
||||||
writer.startElement("", "root", "", new AttributesImpl());
|
writer.startElement("", "root", "", new AttributesImpl());
|
||||||
|
|
||||||
writer.startElement("", "Person", "", new AttributesImpl());
|
writer.startElement("", "Person", "", new AttributesImpl());
|
||||||
atts = new AttributesImpl();
|
atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "mgr", "", "", "NO");
|
atts.addAttribute("", "mgr", "", "", "NO");
|
||||||
writer.startElement("", "name", "", atts);
|
writer.startElement("", "name", "", atts);
|
||||||
writer.characters("Bill");
|
writer.characters("Bill");
|
||||||
writer.endElement("", "name", "");
|
writer.endElement("", "name", "");
|
||||||
|
|
@ -158,10 +157,10 @@ public class XDBXWriterXmlTest {
|
||||||
writer.characters("35");
|
writer.characters("35");
|
||||||
writer.endElement("bar", "age", "age");
|
writer.endElement("bar", "age", "age");
|
||||||
writer.endElement("", "Person", "");
|
writer.endElement("", "Person", "");
|
||||||
|
|
||||||
writer.startElement("", "Person", "", new AttributesImpl());
|
writer.startElement("", "Person", "", new AttributesImpl());
|
||||||
atts = new AttributesImpl();
|
atts = new AttributesImpl();
|
||||||
atts.addAttribute ("", "mgr", "", "", "NO");
|
atts.addAttribute("", "mgr", "", "", "NO");
|
||||||
writer.startElement("", "name", "", atts);
|
writer.startElement("", "name", "", atts);
|
||||||
writer.characters("Joe");
|
writer.characters("Joe");
|
||||||
writer.endElement("", "name", "");
|
writer.endElement("", "name", "");
|
||||||
|
|
@ -169,134 +168,134 @@ public class XDBXWriterXmlTest {
|
||||||
writer.characters("45");
|
writer.characters("45");
|
||||||
writer.endElement("bar", "age", "age");
|
writer.endElement("bar", "age", "age");
|
||||||
writer.endElement("", "Person", "");
|
writer.endElement("", "Person", "");
|
||||||
|
|
||||||
writer.endElement("", "root", "");
|
writer.endElement("", "root", "");
|
||||||
writer.endDocument();
|
writer.endDocument();
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] output = baos.toByteArray();
|
byte[] output = baos.toByteArray();
|
||||||
int outIdx = 8;
|
int outIdx = 8;
|
||||||
Assertions.assertNotNull(output);
|
Assertions.assertNotNull(output);
|
||||||
Assertions.assertTrue(output.length > 0);
|
Assertions.assertTrue(output.length > 0);
|
||||||
Assertions.assertEquals((byte)'I', output[outIdx++]);
|
Assertions.assertEquals((byte) 'I', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'f', output[outIdx++]);
|
Assertions.assertEquals((byte) 'f', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'o', output[outIdx++]);
|
Assertions.assertEquals((byte) 'o', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'o', output[outIdx++]);
|
Assertions.assertEquals((byte) 'o', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 1, output[outIdx++]);
|
Assertions.assertEquals((byte) 1, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'I', output[outIdx++]);
|
Assertions.assertEquals((byte) 'I', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'b', output[outIdx++]);
|
Assertions.assertEquals((byte) 'b', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'a', output[outIdx++]);
|
Assertions.assertEquals((byte) 'a', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'r', output[outIdx++]);
|
Assertions.assertEquals((byte) 'r', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((char)'X', (char)output[outIdx++]);
|
Assertions.assertEquals((char) 'X', (char) output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'r', output[outIdx++]);
|
Assertions.assertEquals((byte) 'r', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'o', output[outIdx++]);
|
Assertions.assertEquals((byte) 'o', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'o', output[outIdx++]);
|
Assertions.assertEquals((byte) 'o', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'t', output[outIdx++]);
|
Assertions.assertEquals((byte) 't', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
Assertions.assertEquals((char)'m', (char)output[outIdx++]);
|
Assertions.assertEquals((char) 'm', (char) output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 1, output[outIdx++]);
|
Assertions.assertEquals((byte) 1, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((char)'X', (char)output[outIdx++]);
|
Assertions.assertEquals((char) 'X', (char) output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 6, output[outIdx++]);
|
Assertions.assertEquals((byte) 6, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'P', output[outIdx++]);
|
Assertions.assertEquals((byte) 'P', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'e', output[outIdx++]);
|
Assertions.assertEquals((byte) 'e', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'r', output[outIdx++]);
|
Assertions.assertEquals((byte) 'r', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'s', output[outIdx++]);
|
Assertions.assertEquals((byte) 's', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'o', output[outIdx++]);
|
Assertions.assertEquals((byte) 'o', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'n', output[outIdx++]);
|
Assertions.assertEquals((byte) 'n', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((char)'X', (char)output[outIdx++]);
|
Assertions.assertEquals((char) 'X', (char) output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'n', output[outIdx++]);
|
Assertions.assertEquals((byte) 'n', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'a', output[outIdx++]);
|
Assertions.assertEquals((byte) 'a', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'m', output[outIdx++]);
|
Assertions.assertEquals((byte) 'm', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'e', output[outIdx++]);
|
Assertions.assertEquals((byte) 'e', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 5, output[outIdx++]);
|
Assertions.assertEquals((byte) 5, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((char)'Y', (char)output[outIdx++]);
|
Assertions.assertEquals((char) 'Y', (char) output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'m', output[outIdx++]);
|
Assertions.assertEquals((byte) 'm', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'g', output[outIdx++]);
|
Assertions.assertEquals((byte) 'g', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'r', output[outIdx++]);
|
Assertions.assertEquals((byte) 'r', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 6, output[outIdx++]);
|
Assertions.assertEquals((byte) 6, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
Assertions.assertEquals((byte) 0, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'N', output[outIdx++]);
|
Assertions.assertEquals((byte) 'N', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'O', output[outIdx++]);
|
Assertions.assertEquals((byte) 'O', output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((byte)'T', output[outIdx++]);
|
Assertions.assertEquals((byte) 'T', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'B', output[outIdx++]);
|
Assertions.assertEquals((byte) 'B', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'i', output[outIdx++]);
|
Assertions.assertEquals((byte) 'i', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'l', output[outIdx++]);
|
Assertions.assertEquals((byte) 'l', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'l', output[outIdx++]);
|
Assertions.assertEquals((byte) 'l', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'z', output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((char)'X', (char)output[outIdx++]);
|
Assertions.assertEquals((char) 'X', (char) output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'a', output[outIdx++]);
|
Assertions.assertEquals((byte) 'a', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'g', output[outIdx++]);
|
Assertions.assertEquals((byte) 'g', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'e', output[outIdx++]);
|
Assertions.assertEquals((byte) 'e', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 7, output[outIdx++]);
|
Assertions.assertEquals((byte) 7, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 1, output[outIdx++]);
|
Assertions.assertEquals((byte) 1, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 'T', output[outIdx++]);
|
Assertions.assertEquals((byte) 'T', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'3', output[outIdx++]);
|
Assertions.assertEquals((byte) '3', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'5', output[outIdx++]);
|
Assertions.assertEquals((byte) '5', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'z', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'z', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'e', output[outIdx++]);
|
Assertions.assertEquals((byte) 'e', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
Assertions.assertEquals((byte) 4, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'e', output[outIdx++]);
|
Assertions.assertEquals((byte) 'e', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 5, output[outIdx++]);
|
Assertions.assertEquals((byte) 5, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'a', output[outIdx++]);
|
Assertions.assertEquals((byte) 'a', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 6, output[outIdx++]);
|
Assertions.assertEquals((byte) 6, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'N', output[outIdx++]);
|
Assertions.assertEquals((byte) 'N', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'O', output[outIdx++]);
|
Assertions.assertEquals((byte) 'O', output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((byte)'T', output[outIdx++]);
|
Assertions.assertEquals((byte) 'T', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
Assertions.assertEquals((byte) 3, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'J', output[outIdx++]);
|
Assertions.assertEquals((byte) 'J', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'o', output[outIdx++]);
|
Assertions.assertEquals((byte) 'o', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'e', output[outIdx++]);
|
Assertions.assertEquals((byte) 'e', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'z', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'x', output[outIdx++]);
|
Assertions.assertEquals((byte) 'x', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 7, output[outIdx++]);
|
Assertions.assertEquals((byte) 7, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 1, output[outIdx++]);
|
Assertions.assertEquals((byte) 1, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((byte)'T', output[outIdx++]);
|
Assertions.assertEquals((byte) 'T', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
Assertions.assertEquals((byte) 2, output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'4', output[outIdx++]);
|
Assertions.assertEquals((byte) '4', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'5', output[outIdx++]);
|
Assertions.assertEquals((byte) '5', output[outIdx++]);
|
||||||
|
|
||||||
Assertions.assertEquals((byte)'z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'z', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'z', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'z', output[outIdx++]);
|
||||||
Assertions.assertEquals((byte)'Z', output[outIdx++]);
|
Assertions.assertEquals((byte) 'Z', output[outIdx++]);
|
||||||
|
|
||||||
StringWriter outputXmlStr = new StringWriter();
|
StringWriter outputXmlStr = new StringWriter();
|
||||||
SAX3WriterXml outputXml = new SAX3WriterXml(outputXmlStr);
|
SAX3WriterXml outputXml = new SAX3WriterXml(outputXmlStr);
|
||||||
XDBXReaderXml reader = new XDBXReaderXml(outputXml);
|
XDBXReaderXml reader = new XDBXReaderXml(outputXml);
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(output);
|
ByteArrayInputStream bais = new ByteArrayInputStream(output);
|
||||||
reader.parse(bais);
|
reader.parse(bais);
|
||||||
|
|
||||||
String outputStr = outputXmlStr.toString();
|
String outputStr = outputXmlStr.toString();
|
||||||
Assertions.assertTrue(outputStr.contains("<root"));
|
Assertions.assertTrue(outputStr.contains("<root"));
|
||||||
Assertions.assertTrue(outputStr.contains("xmlns:foo=\"bar\""));
|
Assertions.assertTrue(outputStr.contains("xmlns:foo=\"bar\""));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue