X4O: Formatted the SAX3 package to eclipse-160 (code+comment)

This commit is contained in:
Willem Cazander 2025-11-07 21:35:41 +01:00
parent 2819b36a45
commit a61ce241e1
26 changed files with 1192 additions and 909 deletions

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3;
package org.x4o.sax3;
import java.io.Closeable;
import java.io.IOException;
@ -38,10 +38,10 @@ import org.xml.sax.helpers.AttributesImpl;
*
* @author Willem Cazander
* @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.
*/
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 TAG_WRITER contentWriter;
@ -121,7 +121,7 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
public void printTagEnd(TAG tag) throws IOException {
try {
contentWriter.endElement(getTagNamespaceUri(),toTagString(tag) , "");
contentWriter.endElement(getTagNamespaceUri(), toTagString(tag), "");
} catch (SAXException e) {
throw new IOException(e);
}

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3;
package org.x4o.sax3;
import java.io.IOException;

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3;
package org.x4o.sax3;
import java.io.IOException;
import java.io.Writer;
@ -38,7 +38,7 @@ import org.xml.sax.helpers.AttributesImpl;
* @author Willem Cazander
* @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) {
super(new SAX3WriterXml(out, encoding), "", SAX3XMLConstants.NULL_NS_URI);
@ -70,7 +70,7 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
public void printHeadMetaDate() throws IOException {
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 {
@ -127,7 +127,9 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
text = "JavaScript is disabled on your browser.";
}
printTagStart(Tag.noscript);
printTagStart(Tag.div);printCharacters(text);printTagEnd(Tag.div);
printTagStart(Tag.div);
printCharacters(text);
printTagEnd(Tag.div);
printTagEnd(Tag.noscript);
}
@ -162,13 +164,13 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
if (title != null) {
atts.addAttribute("", "title", "", "", title);
}
printTagStart(Tag.a,atts);
printTagStart(Tag.a, atts);
if (spanClass != null) {
atts = new AttributesImpl();
if (spanClass.length() > 0) {
atts.addAttribute("", "class", "", "", spanClass);
}
printTagStart(Tag.span,atts);
printTagStart(Tag.span, atts);
}
printCharacters(text);
if (spanClass != null) {
@ -244,51 +246,151 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
public enum Tag {
/* Deprecated TAGS */
frameset,frame,noframes,tt,font,dir,center,strike,
big,basefont,acronym,applet,iframe,
frameset,
frame,
noframes,
tt,
font,
dir,
center,
strike,
big,
basefont,
acronym,
applet,
iframe,
/* HTML 4 TAGS */
html,head,title,meta,link,base,body,script,style,
html,
head,
title,
meta,
link,
base,
body,
script,
style,
h1,h2,h3,h4,h5,h6,
a,div,span,p,pre,img,hr,br,
b,em,strong,small,noscript,
h1,
h2,
h3,
h4,
h5,
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,
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,
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,
form,
fieldset,
input,
option,
label,
button,
select,
textarea,
/* HTML 5 TAGS */
canvas,audio,video,source,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,
;
canvas,
audio,
video,
source,
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";
public enum DocType {
/* 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_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_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_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_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_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 publicId;

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3;
package org.x4o.sax3;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
@ -40,7 +40,8 @@ public class SAX3WriterXml extends AbstractContentWriter {
/**
* 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) {
super(out);
@ -49,16 +50,18 @@ public class SAX3WriterXml extends AbstractContentWriter {
/**
* 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) {
this(out,null);
this(out, null);
}
/**
* 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 {
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.
* @param out The OutputStream to write to.
* @param encoding The OutputStream encoding.
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
*
* @param out The OutputStream to write to.
* @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);
}
}

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3;
package org.x4o.sax3;
import java.io.IOException;
import java.io.Writer;
@ -35,7 +35,7 @@ import org.xml.sax.helpers.AttributesImpl;
* @author Willem Cazander
* @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) {
super(new SAX3WriterXml(out, encoding), SAX3XMLConstants.XML_SCHEMA_NS_URI, SAX3XMLConstants.NULL_NS_URI);
@ -75,10 +75,35 @@ public class SAX3WriterXsd extends SAX3WriterEnum<SAX3WriterXsd.Tag,SAX3WriterXm
}
public enum Tag {
all,annotation,any,anyAttribute,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
all,
annotation,
any,
anyAttribute,
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
}
}

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3.io;
package org.x4o.sax3.io;
import java.io.Writer;
@ -37,7 +37,8 @@ public abstract class AbstractContentWriter extends AbstractContentWriterLexical
/**
* 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) {
super(out);
@ -45,6 +46,7 @@ public abstract class AbstractContentWriter extends AbstractContentWriterLexical
/**
* 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)
*/
public void startElementEnd(String uri, String localName, String name, Attributes atts) throws SAXException {

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3.io;
package org.x4o.sax3.io;
import java.io.BufferedReader;
import java.io.Closeable;
@ -59,13 +59,14 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
private final Writer out;
private boolean started = false;
private int indent = 0;
private Map<String,String> prefixMapping = null;
private Map<String, String> prefixMapping = null;
private List<String> printedMappings = null;
private StringBuilder startElement = null;
private boolean printReturn = false;
private String lastElement = 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"
public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG;
public final static String OUTPUT_ENCODING = PROPERTY_CONTEXT_PREFIX + "output/encoding";
@ -105,14 +106,16 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
new PropertyConfigItem(ROOT_START_NAMESPACE_ALL, Boolean.class, true)
);
}
//@formatter:on
/**
* 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) {
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.elements = new Stack<String>();
this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX);
@ -232,17 +235,17 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
/**
* @param uri The xml namespace uri.
* @param localName The local name of the xml tag.
* @param name The (full) name of the xml tag.
* @param atts The attributes of the xml tag.
* @param uri The xml namespace uri.
* @param localName The local name of the xml tag.
* @param name The (full) name 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)
*/
public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException {
if (localName == 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 + "'");
}
for (int i = 0; i < atts.getLength(); i++) {
@ -273,7 +276,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
startElement.append(SAX3XMLConstants.TAG_OPEN);
startElementTag(uri,localName);
startElementTag(uri, localName);
startElementNamespace(uri);
startElementNamespaceAll();
startElementAttributes(atts);
@ -363,7 +366,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
private void printElementAttributeNewLineSpace() {
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));
}
}
@ -416,9 +419,9 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
/**
* @param uri The xml namespace uri.
* @param localName The local name of the xml tag.
* @param name The (full) name of the xml tag.
* @param uri The xml namespace uri.
* @param localName The local 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)
*/
public void endElement(String uri, String localName, String name) throws SAXException {
@ -429,7 +432,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
if (startElement != null) {
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);
startElement = null;
indent--;
@ -469,8 +472,9 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
/**
* 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)
*/
public void startPrefixMapping(String prefix, String uri) throws SAXException {
@ -478,13 +482,13 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
/**
* @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)
*/
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;
for (Map.Entry<String,String> e : s) {
for (Map.Entry<String, String> e : s) {
if (e.getValue() == null) {
continue; // way ?
}
@ -501,8 +505,8 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
/**
* Prints xml characters and uses characters(java.lang.String) method.
*
* @param ch Character buffer.
* @param start The start index of the chars in the ch buffer.
* @param ch Character 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.
* @throws SAXException When IOException has happend while printing.
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
@ -513,6 +517,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
/**
* Escape and prints xml characters.
*
* @param text The text to write.
* @throws SAXException When IOException has happend while printing.
* @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String)
@ -525,7 +530,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
public void characters(char c) throws SAXException {
characters(new char[]{c}, 0, 1);
characters(new char[] { c }, 0, 1);
}
// move or remove ?
@ -541,8 +546,8 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
/**
* Prints xml ignorable whitespace.
*
* @param ch Character buffer.
* @param start The start index of the chars in the ch buffer.
* @param ch Character 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.
* @throws SAXException When IOException has happend while printing.
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
@ -554,7 +559,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
/**
* Prints xml ignorable whitespace.
*
* @param text The text to print.
* @param text The text to print.
* @throws SAXException When IOException has happend while printing.
* @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String)
*/
@ -569,11 +574,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
/**
* 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.
*/
public void ignorableWhitespace(char c) throws SAXException {
ignorableWhitespace(new char[]{c}, 0, 1);
ignorableWhitespace(new char[] { c }, 0, 1);
}
/**
@ -581,7 +586,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
*
* @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
* @param target The target.
* @param data The data.
* @param data The data.
*/
public void processingInstruction(String target, String data) throws SAXException {
String targetLow = target.toLowerCase();
@ -628,8 +633,8 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
/**
* Prints xml comment.
*
* @param ch Character buffer.
* @param start The start index of the chars in the ch buffer.
* @param ch Character 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.
* @throws SAXException When IOException has happend while printing.
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
@ -667,7 +672,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
writeIndent();
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);
printReturn = true;
}
@ -675,7 +680,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
/**
* 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) {
if (value.indexOf(SAX3XMLConstants.CHAR_NEWLINE) > 0) {
@ -687,7 +692,8 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
/**
* 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 {
if (startElement == null) {
@ -699,7 +705,8 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
/**
* 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 {
for (int i = 0; i < indent; i++) {

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3.io;
package org.x4o.sax3.io;
import java.io.Writer;
@ -39,7 +39,8 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter
/**
* 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) {
super(out);

View file

@ -37,7 +37,7 @@ import java.util.Set;
* @param <K> The key 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 */
private Attributes attributes = null;
@ -57,8 +57,8 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* Constructes an new AttributesMap.
*
* @param attributes The data backed of this map.
* @param uri The namespace of these attributes.
* @param attributes The data backed of this map.
* @param uri The namespace of these attributes.
*/
public AttributeMap(Attributes attributes, String uri) {
setAttributes(attributes);
@ -68,7 +68,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* 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) {
this.attributes = attributes;
@ -86,7 +86,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* 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) {
this.uri = uri;
@ -106,7 +106,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* 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.
*/
private String getName(int index) {
@ -134,6 +134,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* Gets the attribute value.
*
* @param key The name of the attribute.
* @return The value of the attribute.
*/
@ -170,7 +171,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* 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.
*/
public boolean containsKey(Object key) {
@ -183,7 +184,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* 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.
*/
public boolean containsValue(Object value) {
@ -198,19 +199,19 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* 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.
*/
@SuppressWarnings("unchecked")
public V get(Object key) {
return (V)getValue(key);
return (V) getValue(key);
}
/**
* Function not implements. because we can't add to the attributes.
*
* @param key ignored.
* @param value ignored.
* @param key ignored.
* @param value ignored.
* @return always null
*/
public V put(K key, V value) {
@ -220,17 +221,17 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* Function not implements. because we can't remove to the attributes.
*
* @param key ignored.
* @param key ignored.
* @return always null
*/
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.
*
* @param t ignored.
* @param t ignored.
*/
@SuppressWarnings("rawtypes")
public void putAll(Map t) {
@ -253,7 +254,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
public Set<K> keySet() {
HashSet<K> result = new HashSet<K>();
for (int i = 0; i < size(); i++) {
result.add((K)getName(i));
result.add((K) getName(i));
}
return result;
}
@ -267,14 +268,13 @@ public class AttributeMap<K,V> implements Map<K,V> {
public Collection<V> values() {
ArrayList<V> result = new ArrayList<V>();
for (int i = 0; i < size(); i++) {
result.add((V)attributes.getValue(i));
result.add((V) attributes.getValue(i));
}
return result;
}
/**
* 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.
* 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.
*
* @see java.util.Map#entrySet()
* @return An entry set.
@ -293,7 +293,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* 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.
*/
public boolean equals(Object o) {
@ -320,7 +320,8 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* Creates AttributeMapEntry with key object.
* @param key The key.
*
* @param key The key.
*/
protected AttributeMapEntry(Object key) {
this.key = key;
@ -335,6 +336,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
/**
* Sets the value of this Map.Entry.
*
* @param value The value to set.
* @return The old value.
*/

View file

@ -20,12 +20,11 @@
* 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.
*/
package org.x4o.sax3.io;
package org.x4o.sax3.io;
import java.io.Closeable;
import java.io.IOException;
/**
* Functional closable callback for indenting api flow.
*

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3.io;
package org.x4o.sax3.io;
import java.io.Closeable;
import java.io.IOException;
@ -30,7 +30,6 @@ import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
/**
* ContentWriter is ContentHandler for writing sax events.
*
@ -43,7 +42,7 @@ public interface ContentWriter extends ContentHandler, LexicalHandler, Closeable
* Wrap startDocument and endDocument in a body closable code block.
*
* @return An closable resource block reference.
* @throws SAXException When IOException is thrown.
* @throws SAXException When IOException is thrown.
*/
default ContentCloseable startDocumentClosure() throws SAXException {
startDocument();
@ -58,46 +57,52 @@ public interface ContentWriter extends ContentHandler, LexicalHandler, Closeable
/**
* Starts and ends an element in one call.
* @param uri The uri of the element.
* @param localName The localName of the element.
* @param name The name of the element.
* @param atts The attributes of the element.
* @throws SAXException When IOException is thrown.
*
* @param uri The uri of the element.
* @param localName The localName of the element.
* @param name The name of the element.
* @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;
/**
* 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;
/**
* 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;
/**
* Writes a whitespace character to the body.
* @param c The character to write.
*
* @param c The character to write.
* @throws SAXException On error;
*/
void ignorableWhitespace(char c) throws SAXException;
/**
* 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;
/**
* 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;
}

View file

@ -20,13 +20,12 @@
* 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.
*/
package org.x4o.sax3.io;
package org.x4o.sax3.io;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
/**
* ContentWriterAdapter is base ContentHandler for writing SAX3 events.
*
@ -44,7 +43,7 @@ abstract public class ContentWriterAdapter implements ContentWriter {
}
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 {
@ -53,7 +52,7 @@ abstract public class ContentWriterAdapter implements ContentWriter {
}
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 {

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3.io;
package org.x4o.sax3.io;
import java.io.File;
import java.util.ArrayList;
@ -39,7 +39,7 @@ import java.util.function.Supplier;
public final class SAX3PropertyConfig implements Cloneable {
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 String keyPrefix;
@ -57,7 +57,7 @@ public final class SAX3PropertyConfig implements Cloneable {
}
this.readOnly = readOnly;
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);
copyParentPropertyConfig(fillItems, parentPropertyConfig);
if (fillItems.isEmpty()) {
@ -79,14 +79,14 @@ public final class SAX3PropertyConfig implements Cloneable {
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++) {
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) {
return;
}
@ -171,6 +171,7 @@ public final class SAX3PropertyConfig implements Cloneable {
/**
* Clones all the fields into the new PropertyConfigItem.
*
* @see java.lang.Object#clone()
*/
@Override
@ -230,7 +231,7 @@ public final class SAX3PropertyConfig implements Cloneable {
return Collections.unmodifiableList(result);
}
public final void setProperty(String key,Object value) {
public final void setProperty(String key, Object value) {
if (readOnly) {
throw new IllegalStateException("This property is readonly for key:" + key);
}
@ -268,7 +269,7 @@ public final class SAX3PropertyConfig implements Cloneable {
public final File getPropertyFile(String key) {
Object value = getProperty(key);
if (value instanceof File) {
return (File)value;
return (File) value;
}
if (value == null) {
return null;
@ -287,7 +288,7 @@ public final class SAX3PropertyConfig implements Cloneable {
public final Boolean getPropertyBoolean(String key) {
Object value = getProperty(key);
if (value instanceof Boolean) {
return (Boolean)value;
return (Boolean) value;
}
if (value == null) {
return null;
@ -306,7 +307,7 @@ public final class SAX3PropertyConfig implements Cloneable {
public final Integer getPropertyInteger(String key) {
Object value = getProperty(key);
if (value instanceof Integer) {
return (Integer)value;
return (Integer) value;
}
if (value == null) {
return null;
@ -326,7 +327,7 @@ public final class SAX3PropertyConfig implements Cloneable {
public final List<String> getPropertyList(String key) {
Object value = getProperty(key);
if (value instanceof List) {
return (List<String>)value;
return (List<String>) value;
}
if (value == null) {
return null;
@ -343,10 +344,10 @@ public final class SAX3PropertyConfig implements Cloneable {
}
@SuppressWarnings("unchecked")
public final Map<String,String> getPropertyMap(String key) {
public final Map<String, String> getPropertyMap(String key) {
Object value = getProperty(key);
if (value instanceof Map) {
return (Map<String,String>)value;
return (Map<String, String>) value;
}
if (value == null) {
return null;
@ -354,8 +355,8 @@ public final class SAX3PropertyConfig implements Cloneable {
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
}
public final Map<String,String> getPropertyMap(String key, Supplier<Map<String,String>> defaultValue) {
Map<String,String> result = getPropertyMap(key);
public final Map<String, String> getPropertyMap(String key, Supplier<Map<String, String>> defaultValue) {
Map<String, String> result = getPropertyMap(key);
if (result != null) {
return result;
}
@ -365,7 +366,7 @@ public final class SAX3PropertyConfig implements Cloneable {
public final String getPropertyString(String key) {
Object value = getProperty(key);
if (value instanceof String) {
return (String)value;
return (String) value;
}
if (value == null) {
return null;
@ -373,7 +374,7 @@ public final class SAX3PropertyConfig implements Cloneable {
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);
if (propertyValue == null) {
return defaultValue;
@ -382,7 +383,7 @@ public final class SAX3PropertyConfig implements Cloneable {
}
}
public final String getPropertyString(String key,Supplier<String> defaultValue) {
public final String getPropertyString(String key, Supplier<String> defaultValue) {
String result = getPropertyString(key);
if (result != null) {
return result;
@ -401,7 +402,7 @@ public final class SAX3PropertyConfig implements Cloneable {
}
@SuppressWarnings("unchecked")
public final void setPropertyParsedValue(String key,String value) {
public final void setPropertyParsedValue(String key, String value) {
Class<?> valueType = getPropertyType(key);
if (String.class.equals(valueType)) {
setProperty(key, value);
@ -429,7 +430,7 @@ public final class SAX3PropertyConfig implements Cloneable {
}
if (List.class.equals(valueType)) {
String[] listValues = value.split(",");
List<String> result = (List<String>)getProperty(key);
List<String> result = (List<String>) getProperty(key);
if (result == null) {
result = new ArrayList<String>(10);
setProperty(key, result);
@ -441,9 +442,9 @@ public final class SAX3PropertyConfig implements Cloneable {
}
if (Map.class.equals(valueType)) {
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) {
result = new HashMap<String,String>(10);
result = new HashMap<String, String>(10);
setProperty(key, result);
}
if (listValues.length != 2) {
@ -458,6 +459,7 @@ public final class SAX3PropertyConfig implements Cloneable {
/**
* Clones all the properties into the new PropertyConfig.
*
* @see java.lang.Object#clone()
*/
@Override

View file

@ -60,7 +60,7 @@ public final class SAX3XMLConstants {
/**
* 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.
@ -69,6 +69,7 @@ public final class SAX3XMLConstants {
/**
* 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>
*/
public static final String NULL_NS_URI = javax.xml.XMLConstants.NULL_NS_URI; // ""
@ -131,12 +132,12 @@ public final class SAX3XMLConstants {
/**
* 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.
*/
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
@ -161,7 +162,7 @@ public final class SAX3XMLConstants {
public static final int CODE_POINT_ENTIY_REF_TERMINATOR = ';';
static public String getDocumentDeclaration(String encoding) {
return getDocumentDeclaration(encoding,null);
return getDocumentDeclaration(encoding, null);
}
static public String getDocumentDeclaration(String encoding, String version) {
@ -176,45 +177,106 @@ public final class SAX3XMLConstants {
static public boolean isChar(int c) {
// Exclude "compatibility characters", as defined in section 2.3 of [Unicode]
if (c>=0x7F & c<=0x84) { return false; }
if (c>=0x86 & c<=0x9F) { 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>=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; }
if (c >= 0x7F & c <= 0x84) {
return false;
}
if (c >= 0x86 & c <= 0x9F) {
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 >= 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;
// #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
if (c==0x9) { return true; }
if (c==0xA) { 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; }
if (c == 0x9) {
return true;
}
if (c == 0xA) {
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;
}
static public boolean isNameStartChar(int c) {
// 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]
if (c>='a' & c<='z') { return true; }
if (c>='A' & c<='Z') { return true; }
if (c==':' || c=='_') { return true; }
if (c>=0xC0 & c<=0xD6) { return true; }
if (c>=0xD8 & c<=0xF6) { 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; }
// ":" | [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]
if (c >= 'a' & c <= 'z') {
return true;
}
if (c >= 'A' & c <= 'Z') {
return true;
}
if (c == ':' || c == '_') {
return true;
}
if (c >= 0xC0 & c <= 0xD6) {
return true;
}
if (c >= 0xD8 & c <= 0xF6) {
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;
}
@ -224,11 +286,21 @@ public final class SAX3XMLConstants {
if (isNameStartChar(c)) {
return true;
}
if (c=='-' || c=='.') { return true; }
if (c>='0' & c<='9') { return true; }
if (c==0xB7) { return true; }
if (c>=0x0300 & c<=0x036F) { return true; }
if (c>=0x203F & c<=0x2040) { return true; }
if (c == '-' || c == '.') {
return true;
}
if (c >= '0' & c <= '9') {
return true;
}
if (c == 0xB7) {
return true;
}
if (c >= 0x0300 & c <= 0x036F) {
return true;
}
if (c >= 0x203F & c <= 0x2040) {
return true;
}
return false;
}
@ -286,14 +358,14 @@ public final class SAX3XMLConstants {
}
static public String escapeAttributeValue(String value) {
// Reference ::= EntityRef | CharRef
// AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
// Reference ::= EntityRef | CharRef
// AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
StringBuilder result = new StringBuilder(value.length());
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
while (iterator.hasNext()) {
int c = iterator.nextInt();
// 3.3.3 Attribute-Value Normalization.
if (escapeXMLValueAppend(c,result)) {
if (escapeXMLValueAppend(c, result)) {
continue;
}
result.appendCodePoint(c);
@ -323,18 +395,18 @@ public final class SAX3XMLConstants {
result.append(entity);
continue; // contine to next i char.
} else {
//i = iOrg; // continue normal escape.
// i = iOrg; // continue normal escape.
PrimitiveIterator.OfInt entityIterator = entity.codePoints().iterator();
while (entityIterator.hasNext()) {
int entityCodePoint = entityIterator.nextInt();
if (escapeXMLValueAppend(entityCodePoint,result)) {
if (escapeXMLValueAppend(entityCodePoint, result)) {
continue;
}
result.appendCodePoint(entityCodePoint);
}
}
} else {
if (escapeXMLValueAppend(c,result)) {
if (escapeXMLValueAppend(c, result)) {
continue;
}
result.appendCodePoint(c);
@ -348,7 +420,7 @@ public final class SAX3XMLConstants {
// Hex code points
if (entity.startsWith("&#")) {
String hex = entity.substring(2,entity.length() - 1);
String hex = entity.substring(2, entity.length() - 1);
if (hex.startsWith("x")) {
hex = hex.substring(1);
}
@ -357,45 +429,95 @@ public final class SAX3XMLConstants {
}
// XML
if ("&lt;".equals(entity)) { return true; }
if ("&gt;".equals(entity)) { return true; }
if ("&amp;".equals(entity)) { return true; }
if ("&quot;".equals(entity)) { return true; }
if ("&apos;".equals(entity)) { return true; }
if ("&lt;".equals(entity)) {
return true;
}
if ("&gt;".equals(entity)) {
return true;
}
if ("&amp;".equals(entity)) {
return true;
}
if ("&quot;".equals(entity)) {
return true;
}
if ("&apos;".equals(entity)) {
return true;
}
// HTML
if ("&acute;".equals(entity)) { return true; }
if ("&alefsym;".equals(entity)) { return true; }
if ("&asymp;".equals(entity)) { return true; }
if ("&ang;".equals(entity)) { return true; }
if ("&lowast;".equals(entity)) { return true; }
if ("&clubs;".equals(entity)) { return true; }
if ("&diams;".equals(entity)) { return true; }
if ("&hearts;".equals(entity)) { return true; }
if ("&spades;".equals(entity)) { return true; }
if ("&acute;".equals(entity)) {
return true;
}
if ("&alefsym;".equals(entity)) {
return true;
}
if ("&asymp;".equals(entity)) {
return true;
}
if ("&ang;".equals(entity)) {
return true;
}
if ("&lowast;".equals(entity)) {
return true;
}
if ("&clubs;".equals(entity)) {
return true;
}
if ("&diams;".equals(entity)) {
return true;
}
if ("&hearts;".equals(entity)) {
return true;
}
if ("&spades;".equals(entity)) {
return true;
}
// TODO: etc/etc
if ("&yuml;".equals(entity)) { return true; }
if ("&yacute;".equals(entity)) { return true; }
if ("&ugrave;".equals(entity)) { return true; }
if ("&uuml;".equals(entity)) { return true; }
if ("&ucirc;".equals(entity)) { return true; }
if ("&uacute;".equals(entity)) { return true; }
if ("&yuml;".equals(entity)) {
return true;
}
if ("&yacute;".equals(entity)) {
return true;
}
if ("&ugrave;".equals(entity)) {
return true;
}
if ("&uuml;".equals(entity)) {
return true;
}
if ("&ucirc;".equals(entity)) {
return true;
}
if ("&uacute;".equals(entity)) {
return true;
}
if ("&divide;".equals(entity)) { return true; }
if ("&nbsp;".equals(entity)) { return true; }
if ("&reg;".equals(entity)) { return true; }
if ("&trade;".equals(entity)) { return true; }
if ("&copy;".equals(entity)) { return true; }
if ("&divide;".equals(entity)) {
return true;
}
if ("&nbsp;".equals(entity)) {
return true;
}
if ("&reg;".equals(entity)) {
return true;
}
if ("&trade;".equals(entity)) {
return true;
}
if ("&copy;".equals(entity)) {
return true;
}
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_END_REGEX, replaceCdataEnd);
value = value.replaceAll(CDATA_END_REGEX, replaceCdataEnd);
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_END, "");
StringBuilder result = new StringBuilder(value.length());

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3.io.xdbx;
package org.x4o.sax3.io.xdbx;
import java.io.OutputStream;
@ -38,7 +38,8 @@ public abstract class AbstractXDBXWriter extends AbstractXDBXWriterLexical imple
/**
* 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) {
super(out);
@ -46,10 +47,11 @@ public abstract class AbstractXDBXWriter extends AbstractXDBXWriterLexical imple
/**
* 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)
*/
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);
}
}

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3.io.xdbx;
package org.x4o.sax3.io.xdbx;
import java.io.BufferedReader;
import java.io.Closeable;
@ -60,11 +60,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
private final SAX3PropertyConfig propertyConfig;
private final OutputStream out;
private Map<String,String> prefixMapping = null;
private Map<String, String> prefixMapping = null;
private List<String> printedMappings = 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/";
public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG;
public final static String OUTPUT_DECLARATION = PROPERTY_CONTEXT_PREFIX+"output/declaration";
@ -94,14 +95,16 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
new PropertyConfigItem(ROOT_START_NAMESPACE_ALL, Boolean.class, true)
);
}
//@formatter:on
/**
* 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) {
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.elements = new Stack<String>();
this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX);
@ -146,9 +149,9 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
writeLengthValue("1.0");
writeTag(XDBXContentTag.ENCODING);
writeLengthValue("utf-8");
//Standalone in TV(standalone) form where the value of 'standalone' is either 0 or 1.
//write(XDBXContentTag.STANDALONE);
//write(1);
// Standalone in TV(standalone) form where the value of 'standalone' is either 0 or 1.
// write(XDBXContentTag.STANDALONE);
// write(1);
}
prologWriteLicence();
prologWriteUserComment();
@ -168,7 +171,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
}
licenceInput = cl.getResourceAsStream(licenceResource);
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) {
@ -202,7 +205,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
sb.append('\n');
String line = br.readLine();
while (line != null) {
if (line.length()>0) {
if (line.length() > 0) {
sb.append(" ");
}
sb.append(line);
@ -228,8 +231,8 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
if (userComment.isEmpty()) {
return;
}
String chEnter = "\n"; //getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE);
String chTab = "\t"; //getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB);
String chEnter = "\n"; // getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE);
String chTab = "\t"; // getPropertyConfig().getPropertyString(OUTPUT_CHAR_TAB);
userComment = userComment.replaceAll("\n", chEnter + chTab);
comment(chEnter + chTab + userComment + chEnter);
}
@ -246,10 +249,10 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
}
/**
* @param uri The xml namespace uri.
* @param localName The local name of the xml tag.
* @param name The (full) name of the xml tag.
* @param atts The attributes of the xml tag.
* @param uri The xml namespace uri.
* @param localName The local name of the xml tag.
* @param name The (full) name 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)
*/
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);
startElementAttributes(atts);
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
@ -291,7 +294,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
public void startElementTag(String uri, String localName, String name) throws SAXException {
boolean localNameIdx = xdbxStringId(localName);
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri==null) {
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
if (localNameIdx) {
writeTag(XDBXContentTag.ELEMENT_I);
writeVariableInteger(xdbxStringStore(localName));
@ -305,7 +308,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
} else {
String prefix = prefixMapping.get(uri);
if (prefix == null) {
throw new SAXException("preFixUri: "+uri+" is not started.");
throw new SAXException("preFixUri: " + uri + " is not started.");
}
if (localNameIdx) {
writeTag(XDBXContentTag.ELEMENT_III);
@ -323,7 +326,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
if ((uri != null && SAX3XMLConstants.NULL_NS_URI.equals(uri) == false) && printedMappings.contains(uri) == false) {
String prefix = prefixMapping.get(uri);
if (prefix == null) {
throw new SAXException("preFixUri: "+uri+" is not started.");
throw new SAXException("preFixUri: " + uri + " is not started.");
}
printedMappings.add(uri);
@ -343,7 +346,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
if (printedMappings.contains(uri2) == false) {
prefix = prefixMapping.get(uri2);
if (prefix == null) {
throw new SAXException("preFixUri: "+uri+" is not started.");
throw new SAXException("preFixUri: " + uri + " is not started.");
}
printedMappings.add(uri2);
@ -366,7 +369,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
boolean attributeValueSimple = attributeValue.equals(attributeValueSafe);
boolean attributeNameIdx = xdbxStringId(attributeName);
if (SAX3XMLConstants.NULL_NS_URI.equals(attributeUri) || attributeUri ==null) {
if (SAX3XMLConstants.NULL_NS_URI.equals(attributeUri) || attributeUri == null) {
if (attributeNameIdx) {
writeTag(XDBXContentTag.ATTRIBUTE_I);
writeVariableInteger(xdbxStringStore(attributeName));
@ -401,13 +404,13 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
}
/**
* @param uri The xml namespace uri.
* @param localName The local name of the xml tag.
* @param name The (full) name of the xml tag.
* @param uri The xml namespace uri.
* @param localName The local 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)
*/
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) {
throw new SAXException("Unexpected end tag: " + localName + " should be: " + elements.peek());
}
@ -423,8 +426,9 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
/**
* 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)
*/
public void startPrefixMapping(String prefix, String uri) throws SAXException {
@ -445,13 +449,13 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
}
/**
* @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)
*/
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;
for (Map.Entry<String,String> e : s) {
for (Map.Entry<String, String> e : s) {
if (e.getValue() == null) {
continue; // way ?
}
@ -467,8 +471,8 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
/**
* Prints xml characters and uses characters(java.lang.String) method.
*
* @param ch Character buffer.
* @param start The start index of the chars in the ch buffer.
* @param ch Character 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.
* @throws SAXException When IOException has happend while printing.
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
@ -479,6 +483,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
/**
* Escape and prints xml characters.
*
* @param text The text to write.
* @throws SAXException When IOException has happend while printing.
* @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String)
@ -491,7 +496,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
}
public void characters(char c) throws SAXException {
characters(new char[]{c}, 0, 1);
characters(new char[] { c }, 0, 1);
}
// move or remove ?
@ -505,8 +510,8 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
/**
* Prints xml ignorable whitespace.
*
* @param ch Character buffer.
* @param start The start index of the chars in the ch buffer.
* @param ch Character 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.
* @throws SAXException When IOException has happend while printing.
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
@ -518,7 +523,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
/**
* Prints xml ignorable whitespace.
*
* @param text The text to print.
* @param text The text to print.
* @throws SAXException When IOException has happend while printing.
* @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String)
*/
@ -532,11 +537,11 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
/**
* 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.
*/
public void ignorableWhitespace(char c) throws SAXException {
ignorableWhitespace(new char[]{c}, 0, 1);
ignorableWhitespace(new char[] { c }, 0, 1);
}
/**
@ -544,7 +549,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
*
* @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
* @param target The target.
* @param data The data.
* @param data The data.
*/
public void processingInstruction(String target, String data) throws SAXException {
String targetLow = target.toLowerCase();
@ -558,12 +563,12 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
throw new SAXException("Processing instruction data is invalid char; '" + data + "'");
}
//'I' LengthValue StringID
// 'I' LengthValue StringID
int targetIdx = xdbxStringStore(target);
writeTagLengthValue(XDBXContentTag.STRING_ID, target);
writeVariableInteger(targetIdx);
//'P' StringID LengthValue
// 'P' StringID LengthValue
writeTag(XDBXContentTag.PROCESSING_INSTRUCTION);
writeVariableInteger(targetIdx);
writeLengthValue(data);
@ -593,8 +598,8 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
/**
* Prints xml comment.
*
* @param ch Character buffer.
* @param start The start index of the chars in the ch buffer.
* @param ch Character 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.
* @throws SAXException When IOException has happend while printing.
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
@ -621,7 +626,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
char textStart = text.charAt(0);
char textEnd = text.charAt(text.length() - 1);
if (textStart != ' ' && textStart != '\t' && textStart != '\n') {
text = " "+text;
text = " " + text;
}
if (textEnd != ' ' && textEnd != '\t' && textEnd != '\n') {
text = text + " ";

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3.io.xdbx;
package org.x4o.sax3.io.xdbx;
import java.io.OutputStream;
@ -40,7 +40,8 @@ public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandle
/**
* 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) {
super(out);

View file

@ -30,7 +30,7 @@ package org.x4o.sax3.io.xdbx;
*/
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_VERSION = 0x01;

View file

@ -54,8 +54,7 @@ public enum XDBXContentTag {
PROCESSING_INSTRUCTION('P'),
STRING_ID('I'),
HINT('H'),
SEQUENCE_SEPERATOR('@'),
;
SEQUENCE_SEPERATOR('@'),;
private final int tagNumber;

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3.io.xdbx;
package org.x4o.sax3.io.xdbx;
import java.io.IOException;
import java.io.InputStream;
@ -233,7 +233,7 @@ public class XDBXReaderXml {
return; // NOP is done by caller
}
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());
}
}
@ -303,6 +303,7 @@ public class XDBXReaderXml {
XDBXElement() {
atts = new AttributesImpl();
}
XDBXElement(String localName) {
this();
this.localName = localName;

View file

@ -20,7 +20,7 @@
* 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.
*/
package org.x4o.sax3.io.xdbx;
package org.x4o.sax3.io.xdbx;
import java.io.OutputStream;
@ -34,7 +34,8 @@ public class XDBXWriterXml extends AbstractXDBXWriter {
/**
* 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) {
super(out);

View file

@ -54,13 +54,13 @@ public class SAX3WriterXmlAttributeTest {
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
writer.startDocument();
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "attr", "", "", "foobar");
atts.addAttribute("", "attr", "", "", "foobar");
writer.startElementEnd("", "test", "", atts);
writer.endDocument();
}
String output = outputWriter.toString();
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);
}
@ -70,14 +70,16 @@ public class SAX3WriterXmlAttributeTest {
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
writer.startDocument();
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "attr", "", "", "<test/> & 'foobar' is \"quoted\"!");
atts.addAttribute("", "attr", "", "", "<test/> & 'foobar' is \"quoted\"!");
writer.startElementEnd("", "test", "", atts);
writer.endDocument();
}
String output = outputWriter.toString();
Assertions.assertNotNull(output);
Assertions.assertTrue(output.length()>0);
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test attr=\"&lt;test/&gt; &amp; &apos;foobar&apos; is &quot;quoted&quot;!\"/>"), output);
Assertions.assertTrue(output.length() > 0);
Assertions.assertTrue(
output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test attr=\"&lt;test/&gt; &amp; &apos;foobar&apos; is &quot;quoted&quot;!\"/>"),
output);
}
@Test
@ -87,32 +89,32 @@ public class SAX3WriterXmlAttributeTest {
writer.startDocument();
Assertions.assertThrows(SAXException.class, () -> {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "", "", "", "junit");
atts.addAttribute("", "", "", "", "junit");
writer.startElementEnd("", "test", "", atts);
});
Assertions.assertThrows(SAXException.class, () -> {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", " ", "", "", "junit");
atts.addAttribute("", " ", "", "", "junit");
writer.startElementEnd("", "test", "", atts);
});
Assertions.assertThrows(SAXException.class, () -> {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "foo bar", "", "", "junit");
atts.addAttribute("", "foo bar", "", "", "junit");
writer.startElementEnd("", "test", "", atts);
});
Assertions.assertThrows(SAXException.class, () -> {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "foobar", "", "", "junit");
atts.addAttribute("", "foobar", "", "", "junit");
writer.startElementEnd("", "test junit", "", atts);
});
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "abc", "", "", " junit ");
atts.addAttribute("", "abc", "", "", " junit ");
writer.startElementEnd("", "root", "", atts);
writer.endDocument();
}
String output = outputWriter.toString();
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);
}
@ -122,18 +124,18 @@ public class SAX3WriterXmlAttributeTest {
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
writer.startDocument();
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "仙上主天", "", "", "仙上主天");
atts.addAttribute("", "仙上主天", "", "", "仙上主天");
writer.startElementEnd("", "chinees", "", atts);
writer.endDocument();
}
String output = outputWriter.toString();
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);
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxFactory.newSAXParser();
XMLReader saxReader = saxParser.getXMLReader();
XMLReader saxReader = saxParser.getXMLReader();
saxReader.parse(new InputSource(new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8))));
Assertions.assertNotNull(saxReader);
}
@ -145,29 +147,31 @@ public class SAX3WriterXmlAttributeTest {
// Legal by spec, but not in JVM SAX Reader
writer.startDocument();
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕", "", "", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕");
atts.addAttribute ("", "ᒡᒢᑊᒻᒻᓫᔿ", "", "", "ᒡᒢᑊᒻᒻᓫᔿ");
atts.addAttribute("", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕", "", "", "𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕");
atts.addAttribute("", "ᒡᒢᑊᒻᒻᓫᔿ", "", "", "ᒡᒢᑊᒻᒻᓫᔿ");
writer.startElementEnd("", "test", "", atts);
writer.endDocument();
}
String output = outputWriter.toString();
Assertions.assertNotNull(output);
Assertions.assertTrue(output.length()>0);
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test 𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕=\"𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕\" ᒡᒢᑊᒻᒻᓫᔿ=\"ᒡᒢᑊᒻᒻᓫᔿ\"/>"), output);
Assertions.assertTrue(output.length() > 0);
Assertions.assertTrue(output.equals(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test 𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕=\"𑀳𑁂𑀮𑀺𑀉𑁄𑀤𑁄𑀭𑁂𑀡𑀪𑀸𑀕\" ᒡᒢᑊᒻᒻᓫᔿ=\"ᒡᒢᑊᒻᒻᓫᔿ\"/>"),
output);
// TODO: fix SAX impl
Assertions.assertThrows(SAXException.class, () -> {
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxFactory.newSAXParser();
XMLReader saxReader = saxParser.getXMLReader();
XMLReader saxReader = saxParser.getXMLReader();
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();
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
for (String key:para.keySet()) {
for (String key : para.keySet()) {
Object value = para.get(key);
writer.getPropertyConfig().setProperty(key, value);
}
@ -175,8 +179,8 @@ public class SAX3WriterXmlAttributeTest {
AttributesImpl atts = new AttributesImpl();
String data = "_FOR_FOO_BAR";
String dataValue = "LOOP";
for (int i=0;i<15;i++) {
atts.addAttribute("", "attr"+i, "", "", dataValue+=data);
for (int i = 0; i < 15; i++) {
atts.addAttribute("", "attr" + i, "", "", dataValue += data);
}
writer.startDocument();
writer.startElement("", "test", "", atts);
@ -190,40 +194,40 @@ public class SAX3WriterXmlAttributeTest {
@Test
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);
int newlines = output.split("\n").length;
Assertions.assertNotNull(output);
Assertions.assertTrue(newlines==4, "outputs: "+newlines);
Assertions.assertTrue(newlines == 4, "outputs: " + newlines);
}
@Test
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);
String output = createLongAttribute(para);
int newlines = output.split("\n").length;
Assertions.assertNotNull(output);
Assertions.assertTrue(newlines==20, "outputs: "+newlines);
Assertions.assertTrue(newlines == 20, "outputs: " + newlines);
}
@Test
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);
String output = createLongAttribute(para);
int newlines = output.split("\n").length;
Assertions.assertNotNull(output);
Assertions.assertTrue(newlines==16, "outputs: "+newlines);
Assertions.assertTrue(newlines == 16, "outputs: " + newlines);
}
@Test
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);
String output = createLongAttribute(para);
int newlines = output.split("\n").length;
Assertions.assertNotNull(output);
Assertions.assertTrue(newlines==11, "outputs: "+newlines);
Assertions.assertTrue(newlines == 11, "outputs: " + newlines);
}
}

View file

@ -46,7 +46,7 @@ public class SAX3WriterXmlCDataTest {
}
String output = outputWriter.toString();
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);
}
@ -60,7 +60,7 @@ public class SAX3WriterXmlCDataTest {
}
String output = outputWriter.toString();
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&lt;test/&gt;"), output);
}
@ -76,7 +76,7 @@ public class SAX3WriterXmlCDataTest {
}
String output = outputWriter.toString();
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);
}
@ -92,7 +92,7 @@ public class SAX3WriterXmlCDataTest {
}
String output = outputWriter.toString();
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);
}
@ -108,7 +108,7 @@ public class SAX3WriterXmlCDataTest {
}
String output = outputWriter.toString();
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);
}
@ -124,7 +124,7 @@ public class SAX3WriterXmlCDataTest {
}
String output = outputWriter.toString();
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);
}
@ -140,7 +140,7 @@ public class SAX3WriterXmlCDataTest {
}
String output = outputWriter.toString();
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);
}
@ -156,7 +156,7 @@ public class SAX3WriterXmlCDataTest {
}
String output = outputWriter.toString();
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);
}
@ -172,7 +172,7 @@ public class SAX3WriterXmlCDataTest {
}
String output = outputWriter.toString();
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>]]>"));
}
}

View file

@ -48,7 +48,7 @@ public class SAX3WriterXmlTest {
}
String output = outputWriter.toString();
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);
}
@ -62,7 +62,7 @@ public class SAX3WriterXmlTest {
}
String output = outputWriter.toString();
Assertions.assertNotNull(output);
Assertions.assertTrue(output.length()>0);
Assertions.assertTrue(output.length() > 0);
Assertions.assertTrue(output.equals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>&lt;test/&gt; &amp; &apos;foobar&apos; is &quot;quoted&quot;!"), output);
}
@ -76,7 +76,7 @@ public class SAX3WriterXmlTest {
}
String output = outputWriter.toString();
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);
}
@ -89,14 +89,14 @@ public class SAX3WriterXmlTest {
writer.endDocument();
}
// 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)
// 3) " foobar " - escapes
// 4) "<!-- foobar -->" - printed
// 3) " foobar " - escapes
// 4) "<!-- foobar -->" - printed
String output = outputWriter.toString();
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);
}
@ -147,7 +147,7 @@ public class SAX3WriterXmlTest {
}
String output = outputWriter.toString();
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);
}
@ -165,8 +165,9 @@ public class SAX3WriterXmlTest {
}
String output = outputWriter.toString();
Assertions.assertNotNull(output);
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.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);
}
@Test
@ -202,7 +203,7 @@ public class SAX3WriterXmlTest {
try (SAX3WriterXml writer = new SAX3WriterXml(outputWriter)) {
SAXException e = Assertions.assertThrows(SAXException.class, () -> {
writer.startDocument();
writer.processingInstruction("target", "isInvalidChar="+0xD800);
writer.processingInstruction("target", "isInvalidChar=" + 0xD800);
});
Assertions.assertTrue(e.getMessage().contains("instruction"));
Assertions.assertTrue(e.getMessage().contains("invalid char"));

View file

@ -52,7 +52,7 @@ public class XDBXReaderXmlTest {
try (XDBXWriterXml writer = new XDBXWriterXml(baos)) {
writer.startDocument();
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "attr", "", "", "foobar");
atts.addAttribute("", "attr", "", "", "foobar");
writer.startElementEnd("", "test", "", atts);
writer.endDocument();
}
@ -75,7 +75,7 @@ public class XDBXReaderXmlTest {
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
saxFactory.setNamespaceAware(true);
SAXParser saxParser = saxFactory.newSAXParser();
XMLReader saxReader = saxParser.getXMLReader();
XMLReader saxReader = saxParser.getXMLReader();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XDBXWriterXml writer = new XDBXWriterXml(baos);

View file

@ -48,8 +48,8 @@ public class XDBXWriterXmlTest {
writer.startDocument();
writer.startElement("", "root", "", new AttributesImpl());
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "mgr", "", "", "NO");
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "mgr", "", "", "NO");
writer.startElement("", "name", "", atts);
writer.characters("Joe");
writer.endElement("", "name", "");
@ -69,74 +69,73 @@ public class XDBXWriterXmlTest {
int outIdx = 8;
Assertions.assertNotNull(output);
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)'r', output[outIdx++]);
Assertions.assertEquals((byte)'o', output[outIdx++]);
Assertions.assertEquals((byte)'o', output[outIdx++]);
Assertions.assertEquals((byte)'t', output[outIdx++]);
Assertions.assertEquals((byte) 'r', output[outIdx++]);
Assertions.assertEquals((byte) 'o', output[outIdx++]);
Assertions.assertEquals((byte) 'o', output[outIdx++]);
Assertions.assertEquals((byte) 't', output[outIdx++]);
Assertions.assertEquals((byte) 1, 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)'n', output[outIdx++]);
Assertions.assertEquals((byte)'a', output[outIdx++]);
Assertions.assertEquals((byte)'m', output[outIdx++]);
Assertions.assertEquals((byte)'e', output[outIdx++]);
Assertions.assertEquals((byte) 'n', output[outIdx++]);
Assertions.assertEquals((byte) 'a', output[outIdx++]);
Assertions.assertEquals((byte) 'm', output[outIdx++]);
Assertions.assertEquals((byte) 'e', output[outIdx++]);
Assertions.assertEquals((byte) 2, 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)'m', output[outIdx++]);
Assertions.assertEquals((byte)'g', output[outIdx++]);
Assertions.assertEquals((byte)'r', output[outIdx++]);
Assertions.assertEquals((byte) 'm', output[outIdx++]);
Assertions.assertEquals((byte) 'g', output[outIdx++]);
Assertions.assertEquals((byte) 'r', output[outIdx++]);
Assertions.assertEquals((byte) 3, output[outIdx++]);
Assertions.assertEquals((byte) 0, output[outIdx++]);
Assertions.assertEquals((byte) 0, output[outIdx++]);
Assertions.assertEquals((byte) 2, output[outIdx++]);
Assertions.assertEquals((byte)'N', output[outIdx++]);
Assertions.assertEquals((byte)'O', output[outIdx++]);
Assertions.assertEquals((byte)'T', output[outIdx++]);
Assertions.assertEquals((byte) 'N', output[outIdx++]);
Assertions.assertEquals((byte) 'O', output[outIdx++]);
Assertions.assertEquals((byte) 'T', output[outIdx++]);
Assertions.assertEquals((byte) 3, output[outIdx++]);
Assertions.assertEquals((byte)'J', output[outIdx++]);
Assertions.assertEquals((byte)'o', output[outIdx++]);
Assertions.assertEquals((byte)'e', output[outIdx++]);
Assertions.assertEquals((byte) 'J', output[outIdx++]);
Assertions.assertEquals((byte) 'o', output[outIdx++]);
Assertions.assertEquals((byte) 'e', 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) 'z', output[outIdx++]);
Assertions.assertEquals((byte) 'e', output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
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)'T', 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) 'T', output[outIdx++]);
Assertions.assertEquals((byte) 5, output[outIdx++]);
Assertions.assertEquals((byte)'S', output[outIdx++]);
Assertions.assertEquals((byte)'u', output[outIdx++]);
Assertions.assertEquals((byte)'s', output[outIdx++]);
Assertions.assertEquals((byte)'a', output[outIdx++]);
Assertions.assertEquals((byte)'n', output[outIdx++]);
Assertions.assertEquals((byte) 'S', output[outIdx++]);
Assertions.assertEquals((byte) 'u', output[outIdx++]);
Assertions.assertEquals((byte) 's', output[outIdx++]);
Assertions.assertEquals((byte) 'a', output[outIdx++]);
Assertions.assertEquals((byte) 'n', 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) 'z', output[outIdx++]);
Assertions.assertEquals((byte) 'e', output[outIdx++]); // IBM SPEC example FAIL: 'x' is for WITH namespace
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)'T', 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) 'T', output[outIdx++]);
Assertions.assertEquals((byte) 4, output[outIdx++]);
Assertions.assertEquals((byte)'B', output[outIdx++]);
Assertions.assertEquals((byte)'i', output[outIdx++]);
Assertions.assertEquals((byte)'l', output[outIdx++]);
Assertions.assertEquals((byte)'l', output[outIdx++]);
Assertions.assertEquals((byte) 'B', output[outIdx++]);
Assertions.assertEquals((byte) 'i', 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
public void testExample3StringIds() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -149,8 +148,8 @@ public class XDBXWriterXmlTest {
writer.startElement("", "root", "", new AttributesImpl());
writer.startElement("", "Person", "", new AttributesImpl());
atts = new AttributesImpl();
atts.addAttribute ("", "mgr", "", "", "NO");
atts = new AttributesImpl();
atts.addAttribute("", "mgr", "", "", "NO");
writer.startElement("", "name", "", atts);
writer.characters("Bill");
writer.endElement("", "name", "");
@ -160,8 +159,8 @@ public class XDBXWriterXmlTest {
writer.endElement("", "Person", "");
writer.startElement("", "Person", "", new AttributesImpl());
atts = new AttributesImpl();
atts.addAttribute ("", "mgr", "", "", "NO");
atts = new AttributesImpl();
atts.addAttribute("", "mgr", "", "", "NO");
writer.startElement("", "name", "", atts);
writer.characters("Joe");
writer.endElement("", "name", "");
@ -178,118 +177,118 @@ public class XDBXWriterXmlTest {
int outIdx = 8;
Assertions.assertNotNull(output);
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)'f', output[outIdx++]);
Assertions.assertEquals((byte)'o', output[outIdx++]);
Assertions.assertEquals((byte)'o', output[outIdx++]);
Assertions.assertEquals((byte) 'f', output[outIdx++]);
Assertions.assertEquals((byte) 'o', output[outIdx++]);
Assertions.assertEquals((byte) 'o', 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)'b', output[outIdx++]);
Assertions.assertEquals((byte)'a', output[outIdx++]);
Assertions.assertEquals((byte)'r', output[outIdx++]);
Assertions.assertEquals((byte) 'b', output[outIdx++]);
Assertions.assertEquals((byte) 'a', output[outIdx++]);
Assertions.assertEquals((byte) 'r', 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)'r', output[outIdx++]);
Assertions.assertEquals((byte)'o', output[outIdx++]);
Assertions.assertEquals((byte)'o', output[outIdx++]);
Assertions.assertEquals((byte)'t', output[outIdx++]);
Assertions.assertEquals((byte) 'r', output[outIdx++]);
Assertions.assertEquals((byte) 'o', output[outIdx++]);
Assertions.assertEquals((byte) 'o', output[outIdx++]);
Assertions.assertEquals((byte) 't', output[outIdx++]);
Assertions.assertEquals((byte) 3, 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) 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)'P', output[outIdx++]);
Assertions.assertEquals((byte)'e', output[outIdx++]);
Assertions.assertEquals((byte)'r', output[outIdx++]);
Assertions.assertEquals((byte)'s', output[outIdx++]);
Assertions.assertEquals((byte)'o', output[outIdx++]);
Assertions.assertEquals((byte)'n', output[outIdx++]);
Assertions.assertEquals((byte) 'P', output[outIdx++]);
Assertions.assertEquals((byte) 'e', output[outIdx++]);
Assertions.assertEquals((byte) 'r', output[outIdx++]);
Assertions.assertEquals((byte) 's', output[outIdx++]);
Assertions.assertEquals((byte) 'o', output[outIdx++]);
Assertions.assertEquals((byte) 'n', output[outIdx++]);
Assertions.assertEquals((byte) 4, 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)'n', output[outIdx++]);
Assertions.assertEquals((byte)'a', output[outIdx++]);
Assertions.assertEquals((byte)'m', output[outIdx++]);
Assertions.assertEquals((byte)'e', output[outIdx++]);
Assertions.assertEquals((byte) 'n', output[outIdx++]);
Assertions.assertEquals((byte) 'a', output[outIdx++]);
Assertions.assertEquals((byte) 'm', output[outIdx++]);
Assertions.assertEquals((byte) 'e', output[outIdx++]);
Assertions.assertEquals((byte) 5, 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)'m', output[outIdx++]);
Assertions.assertEquals((byte)'g', output[outIdx++]);
Assertions.assertEquals((byte)'r', output[outIdx++]);
Assertions.assertEquals((byte) 'm', output[outIdx++]);
Assertions.assertEquals((byte) 'g', output[outIdx++]);
Assertions.assertEquals((byte) 'r', output[outIdx++]);
Assertions.assertEquals((byte) 6, output[outIdx++]);
Assertions.assertEquals((byte) 0, output[outIdx++]);
Assertions.assertEquals((byte) 0, output[outIdx++]);
Assertions.assertEquals((byte) 2, output[outIdx++]);
Assertions.assertEquals((byte)'N', output[outIdx++]);
Assertions.assertEquals((byte)'O', output[outIdx++]);
Assertions.assertEquals((byte) 'N', 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)'B', output[outIdx++]);
Assertions.assertEquals((byte)'i', output[outIdx++]);
Assertions.assertEquals((byte)'l', output[outIdx++]);
Assertions.assertEquals((byte)'l', output[outIdx++]);
Assertions.assertEquals((byte)'z', output[outIdx++]);
Assertions.assertEquals((byte) 'B', output[outIdx++]);
Assertions.assertEquals((byte) 'i', output[outIdx++]);
Assertions.assertEquals((byte) 'l', output[outIdx++]);
Assertions.assertEquals((byte) 'l', 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)'a', output[outIdx++]);
Assertions.assertEquals((byte)'g', output[outIdx++]);
Assertions.assertEquals((byte)'e', output[outIdx++]);
Assertions.assertEquals((byte) 'a', output[outIdx++]);
Assertions.assertEquals((byte) 'g', output[outIdx++]);
Assertions.assertEquals((byte) 'e', output[outIdx++]);
Assertions.assertEquals((byte) 7, output[outIdx++]);
Assertions.assertEquals((byte) 1, output[outIdx++]);
Assertions.assertEquals((byte) 2, output[outIdx++]);
Assertions.assertEquals((byte) 'T', output[outIdx++]);
Assertions.assertEquals((byte) 2, output[outIdx++]);
Assertions.assertEquals((byte)'3', output[outIdx++]);
Assertions.assertEquals((byte)'5', output[outIdx++]);
Assertions.assertEquals((byte)'z', output[outIdx++]);
Assertions.assertEquals((byte)'z', output[outIdx++]);
Assertions.assertEquals((byte)'e', output[outIdx++]);
Assertions.assertEquals((byte) '3', output[outIdx++]);
Assertions.assertEquals((byte) '5', output[outIdx++]);
Assertions.assertEquals((byte) 'z', output[outIdx++]);
Assertions.assertEquals((byte) 'z', output[outIdx++]);
Assertions.assertEquals((byte) 'e', 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)'a', output[outIdx++]);
Assertions.assertEquals((byte) 'a', output[outIdx++]);
Assertions.assertEquals((byte) 6, output[outIdx++]);
Assertions.assertEquals((byte) 2, output[outIdx++]);
Assertions.assertEquals((byte)'N', output[outIdx++]);
Assertions.assertEquals((byte)'O', output[outIdx++]);
Assertions.assertEquals((byte) 'N', 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)'J', output[outIdx++]);
Assertions.assertEquals((byte)'o', output[outIdx++]);
Assertions.assertEquals((byte)'e', output[outIdx++]);
Assertions.assertEquals((byte)'z', output[outIdx++]);
Assertions.assertEquals((byte)'x', output[outIdx++]);
Assertions.assertEquals((byte) 'J', output[outIdx++]);
Assertions.assertEquals((byte) 'o', output[outIdx++]);
Assertions.assertEquals((byte) 'e', output[outIdx++]);
Assertions.assertEquals((byte) 'z', output[outIdx++]);
Assertions.assertEquals((byte) 'x', output[outIdx++]);
Assertions.assertEquals((byte) 7, output[outIdx++]);
Assertions.assertEquals((byte) 1, 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)'4', output[outIdx++]);
Assertions.assertEquals((byte)'5', output[outIdx++]);
Assertions.assertEquals((byte) '4', 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();
SAX3WriterXml outputXml = new SAX3WriterXml(outputXmlStr);