Added more white space and tab space in the code

This commit is contained in:
Willem Cazander 2025-01-29 18:43:31 +01:00
parent 275c4aa161
commit 5ba12c3a3e
15 changed files with 349 additions and 357 deletions

View file

@ -91,12 +91,12 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
}
public ContentCloseable printTag(TAG tag, Attributes atts) throws IOException {
printTagStart(tag,atts);
printTagStart(tag, atts);
return () -> printTagEnd(tag);
}
public void printTagStartEnd(TAG tag, Attributes atts) throws IOException {
printTagStart(tag,atts);
printTagStart(tag, atts);
printTagEnd(tag);
}
@ -106,7 +106,7 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
}
public void printTagStart(TAG tag) throws IOException {
printTagStart(tag,EMPTY_ATTRIBUTES);
printTagStart(tag, EMPTY_ATTRIBUTES);
}
public void printTagStart(TAG tag, Attributes atts) throws IOException {
@ -127,8 +127,7 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
private String toTagString(TAG tag) {
String result = tag.name();
if (result.startsWith("_"))
{
if (result.startsWith("_")) {
result = result.substring(1); // remove _
}
return result;
@ -136,7 +135,7 @@ public class SAX3WriterEnum<TAG extends Enum<?>,TAG_WRITER extends ContentWriter
public void printTagCharacters(TAG tag, String text) throws IOException {
printTagStart(tag);
if (text==null) {
if (text == null) {
text = " ";
}
printCharacters(text);

View file

@ -42,15 +42,15 @@ public interface SAX3WriterEnumHammer<TAG extends Enum<?>> {
void printTagStartEnd(TAG tag) throws IOException;
void printTagStartEnd(TAG tag,Attributes atts) throws IOException;
void printTagStartEnd(TAG tag, Attributes atts) throws IOException;
void printTagStart(TAG tag) throws IOException;
void printTagStart(TAG tag,Attributes atts) throws IOException;
void printTagStart(TAG tag, Attributes atts) throws IOException;
void printTagEnd(TAG tag) throws IOException;
void printTagCharacters(TAG tag,String text) throws IOException;
void printTagCharacters(TAG tag, String text) throws IOException;
void printCharacters(String text) throws IOException;

View file

@ -40,7 +40,7 @@ import org.xml.sax.helpers.AttributesImpl;
*/
public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3WriterXml> {
public SAX3WriterHtml(Writer out,String encoding) {
public SAX3WriterHtml(Writer out, String encoding) {
super(new SAX3WriterXml(out, encoding), "", SAX3XMLConstants.NULL_NS_URI);
}
@ -58,10 +58,10 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
public void printHtmlStart(String language) throws IOException {
AttributesImpl atts = new AttributesImpl();
if (language!=null) {
if (language != null) {
atts.addAttribute("", "lang", "", "", language);
}
printTagStart(Tag.html,atts);
printTagStart(Tag.html, atts);
}
public void printHtmlEnd() throws IOException {
@ -70,11 +70,11 @@ 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 {
printTagCharacters(Tag.title,title);
printTagCharacters(Tag.title, title);
}
public void printHeadMetaContentType() throws IOException {
@ -104,7 +104,7 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
public void printScriptInline(String script) throws IOException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "type", "", "", "text/javascript");
printTagStart(Tag.script,atts);
printTagStart(Tag.script, atts);
printComment(script);
printTagEnd(Tag.script);
}
@ -125,7 +125,7 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
public void printHrefNamed(String name) throws IOException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "name", "", "", name);
printTagStart(Tag.a,atts);
printTagStart(Tag.a, atts);
printComment(" ");
printTagEnd(Tag.a);
}
@ -134,7 +134,7 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
AttributesImpl atts = new AttributesImpl();
atts.addAttribute("", "href", "", "", href);
atts.addAttribute("", "target", "", "", target);
printTagStart(Tag.a,atts);
printTagStart(Tag.a, atts);
printCharacters(text);
printTagEnd(Tag.a);
}
@ -156,7 +156,7 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
printTagStart(Tag.a,atts);
if (spanClass != null) {
atts = new AttributesImpl();
if (spanClass.length()>0) {
if (spanClass.length() > 0) {
atts.addAttribute("", "class", "", "", spanClass);
}
printTagStart(Tag.span,atts);
@ -286,9 +286,9 @@ public class SAX3WriterHtml extends SAX3WriterEnum<SAX3WriterHtml.Tag,SAX3Writer
private final String systemId;
private DocType(String name, String publicId, String systemId) {
this.name=name;
this.publicId=publicId;
this.systemId=systemId;
this.name = name;
this.publicId = publicId;
this.systemId = systemId;
}
/**

View file

@ -42,7 +42,7 @@ public class SAX3WriterXml extends AbstractContentWriter {
* Creates XmlWriter which prints to the Writer interface.
* @param out The writer to print the xml to.
*/
public SAX3WriterXml(Writer out,String encoding) {
public SAX3WriterXml(Writer out, String encoding) {
super(out);
getPropertyConfig().setProperty(OUTPUT_ENCODING, encoding);
}
@ -61,7 +61,7 @@ public class SAX3WriterXml extends AbstractContentWriter {
* @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);
this(new OutputStreamWriter(out, SAX3XMLConstants.XML_DEFAULT_ENCODING), SAX3XMLConstants.XML_DEFAULT_ENCODING);
}
/**
@ -71,6 +71,6 @@ public class SAX3WriterXml extends AbstractContentWriter {
* @throws UnsupportedEncodingException Is thrown when UTF-8 can't we printed.
*/
public SAX3WriterXml(OutputStream out,String encoding) throws UnsupportedEncodingException {
this(new OutputStreamWriter(out, encoding),encoding);
this(new OutputStreamWriter(out, encoding), encoding);
}
}

View file

@ -37,39 +37,39 @@ import org.xml.sax.helpers.AttributesImpl;
*/
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);
public SAX3WriterXsd(Writer out, String encoding) {
super(new SAX3WriterXml(out, encoding), SAX3XMLConstants.XML_SCHEMA_NS_URI, SAX3XMLConstants.NULL_NS_URI);
}
public SAX3PropertyConfig getPropertyConfig() {
return getContentWriterWrapped().getPropertyConfig();
}
public void printXsdImport(String namespace,String schemaLocation) throws IOException {
public void printXsdImport(String namespace, String schemaLocation) throws IOException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "namespace", "", "", namespace);
atts.addAttribute ("", "schemaLocation", "", "", schemaLocation);
atts.addAttribute("", "namespace", "", "", namespace);
atts.addAttribute("", "schemaLocation", "", "", schemaLocation);
printTagStartEnd(Tag._import, atts);
}
public void printXsdDocumentation(String description) throws IOException {
if (description==null) {
if (description == null) {
return;
}
printTagStart(Tag.annotation);
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "xml:lang", "", "", "en");
printTagStart(Tag.documentation,atts);
atts.addAttribute("", "xml:lang", "", "", "en");
printTagStart(Tag.documentation, atts);
printCharacters(description);
printTagEnd(Tag.documentation);
printTagEnd(Tag.annotation);
}
public void printXsdElementAttribute(String name,String type,String description) throws IOException {
public void printXsdElementAttribute(String name, String type, String description) throws IOException {
AttributesImpl atts = new AttributesImpl();
atts.addAttribute ("", "name", "", "", name);
atts.addAttribute ("", "type", "", "", type);
printTagStart(Tag.attribute,atts);
atts.addAttribute("", "name", "", "", name);
atts.addAttribute("", "type", "", "", type);
printTagStart(Tag.attribute, atts);
printXsdDocumentation(description);
printTagEnd(Tag.attribute);
}

View file

@ -48,7 +48,7 @@ public abstract class AbstractContentWriter extends AbstractContentWriterLexical
* @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

@ -65,24 +65,24 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
private String lastElement = null;
private Stack<String> elements = null;
private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX+"content/"; // TODO: change to "writer/xml"
private final static String PROPERTY_CONTEXT_PREFIX = SAX3PropertyConfig.X4O_PROPERTIES_PREFIX + "content/"; // TODO: change to "writer/xml"
public final static SAX3PropertyConfig DEFAULT_PROPERTY_CONFIG;
public final static String OUTPUT_ENCODING = PROPERTY_CONTEXT_PREFIX+"output/encoding";
public final static String OUTPUT_CHAR_TAB = PROPERTY_CONTEXT_PREFIX+"output/char-tab";
public final static String OUTPUT_CHAR_NEWLINE = PROPERTY_CONTEXT_PREFIX+"output/char-newline";
public final static String OUTPUT_CHAR_NULL = PROPERTY_CONTEXT_PREFIX+"output/char-null";
public final static String OUTPUT_COMMENT_ENABLE = PROPERTY_CONTEXT_PREFIX+"output/comment-enable";
public final static String OUTPUT_COMMENT_AUTO_SPACE = PROPERTY_CONTEXT_PREFIX+"output/comment-auto-space";
public final static String OUTPUT_LINE_BREAK_WIDTH = PROPERTY_CONTEXT_PREFIX+"output/line-break-width";
public final static String OUTPUT_LINE_PER_ATTRIBUTE = PROPERTY_CONTEXT_PREFIX+"output/line-per-attribute";
public final static String PROLOG_LICENCE_FILE = PROPERTY_CONTEXT_PREFIX+"prolog/licence-file";
public final static String PROLOG_LICENCE_RESOURCE = PROPERTY_CONTEXT_PREFIX+"prolog/licence-resource";
public final static String PROLOG_LICENCE_ENCODING = PROPERTY_CONTEXT_PREFIX+"prolog/licence-encoding";
public final static String PROLOG_LICENCE_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/licence-enable";
public final static String PROLOG_USER_COMMENT = PROPERTY_CONTEXT_PREFIX+"prolog/user-comment";
public final static String PROLOG_USER_COMMENT_ENABLE = PROPERTY_CONTEXT_PREFIX+"prolog/user-comment-enable";
public final static String ROOT_END_APPEND_NEWLINE = PROPERTY_CONTEXT_PREFIX+"root/end-append-newline";
public final static String ROOT_START_NAMESPACE_ALL = PROPERTY_CONTEXT_PREFIX+"root/start-namespace-all";
public final static String OUTPUT_ENCODING = PROPERTY_CONTEXT_PREFIX + "output/encoding";
public final static String OUTPUT_CHAR_TAB = PROPERTY_CONTEXT_PREFIX + "output/char-tab";
public final static String OUTPUT_CHAR_NEWLINE = PROPERTY_CONTEXT_PREFIX + "output/char-newline";
public final static String OUTPUT_CHAR_NULL = PROPERTY_CONTEXT_PREFIX + "output/char-null";
public final static String OUTPUT_COMMENT_ENABLE = PROPERTY_CONTEXT_PREFIX + "output/comment-enable";
public final static String OUTPUT_COMMENT_AUTO_SPACE = PROPERTY_CONTEXT_PREFIX + "output/comment-auto-space";
public final static String OUTPUT_LINE_BREAK_WIDTH = PROPERTY_CONTEXT_PREFIX + "output/line-break-width";
public final static String OUTPUT_LINE_PER_ATTRIBUTE = PROPERTY_CONTEXT_PREFIX + "output/line-per-attribute";
public final static String PROLOG_LICENCE_FILE = PROPERTY_CONTEXT_PREFIX + "prolog/licence-file";
public final static String PROLOG_LICENCE_RESOURCE = PROPERTY_CONTEXT_PREFIX + "prolog/licence-resource";
public final static String PROLOG_LICENCE_ENCODING = PROPERTY_CONTEXT_PREFIX + "prolog/licence-encoding";
public final static String PROLOG_LICENCE_ENABLE = PROPERTY_CONTEXT_PREFIX + "prolog/licence-enable";
public final static String PROLOG_USER_COMMENT = PROPERTY_CONTEXT_PREFIX + "prolog/user-comment";
public final static String PROLOG_USER_COMMENT_ENABLE = PROPERTY_CONTEXT_PREFIX + "prolog/user-comment-enable";
public final static String ROOT_END_APPEND_NEWLINE = PROPERTY_CONTEXT_PREFIX + "root/end-append-newline";
public final static String ROOT_START_NAMESPACE_ALL = PROPERTY_CONTEXT_PREFIX + "root/start-namespace-all";
static {
DEFAULT_PROPERTY_CONFIG = new SAX3PropertyConfig(true,null,PROPERTY_CONTEXT_PREFIX,
@ -114,7 +114,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
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);
this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX);
}
public SAX3PropertyConfig getPropertyConfig() {
@ -143,19 +143,19 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
InputStream licenceInput = null;
String licenceEncoding = propertyConfig.getPropertyString(PROLOG_LICENCE_ENCODING);
String licenceResource = propertyConfig.getPropertyString(PROLOG_LICENCE_RESOURCE);
if (licenceResource!=null) {
if (licenceResource != null) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = this.getClass().getClassLoader();
}
licenceInput = cl.getResourceAsStream(licenceResource);
if (licenceInput==null) {
throw new NullPointerException("Could not load licence resource from: "+licenceResource);
if (licenceInput == null) {
throw new NullPointerException("Could not load licence resource from: " + licenceResource);
}
}
if (licenceInput==null) {
if (licenceInput == null) {
File licenceFile = propertyConfig.getPropertyFile(PROLOG_LICENCE_FILE);
if (licenceFile==null) {
if (licenceFile == null) {
return;
}
try {
@ -166,7 +166,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
String licenceText;
try {
licenceText = readLicenceStream(licenceInput,licenceEncoding);
licenceText = readLicenceStream(licenceInput, licenceEncoding);
} catch (IOException e) {
throw new SAXException(e);
}
@ -174,24 +174,24 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
private String readLicenceStream(InputStream inputStream, String encoding) throws IOException {
if (encoding==null) {
if (encoding == null) {
encoding = SAX3XMLConstants.XML_DEFAULT_ENCODING;
}
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,Charset.forName(encoding)));
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, Charset.forName(encoding)));
try {
StringBuilder sb = new StringBuilder();
sb.append('\n'); // like plugin
sb.append('\n'); // like plugin
sb.append('\n');
sb.append('\n');
String line = br.readLine();
while (line != null) {
if (line.length()>0) {
sb.append(" "); // like plugin
if (line.length() > 0) {
sb.append(" ");
}
sb.append(line);
sb.append('\n');
line = br.readLine();
}
sb.append('\n'); // like plugin
sb.append('\n');
String out = sb.toString();
return out;
} finally {
@ -221,8 +221,8 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
*/
public void endDocument() throws SAXException {
writeFlush();
if (elements.size()>0) {
throw new SAXException("Invalid xml still have "+elements.size()+" elements open.");
if (elements.size() > 0) {
throw new SAXException("Invalid xml still have " + elements.size() + " elements open.");
}
}
@ -234,13 +234,13 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @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) {
if (localName == null) {
throw new SAXException("LocalName may not be null.");
}
if (SAX3XMLConstants.isNameString(localName)==false) {
throw new SAXException("LocalName of element is not valid in xml; '"+localName+"'");
throw new SAXException("LocalName of element is not valid in xml; '" + localName + "'");
}
for (int i=0;i<atts.getLength();i++) {
for (int i = 0; i < atts.getLength(); i++) {
boolean isFirst = true;
String attrLocalName = atts.getLocalName(i);
if (attrLocalName.isEmpty()) {
@ -252,11 +252,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
if (isFirst) {
isFirst = false;
if (!SAX3XMLConstants.isNameStartChar(attrLocalName.codePoints().findFirst().getAsInt())) {
throw new SAXException("LocalAttributeName has illegal start character: " + attrLocalName);
throw new SAXException("LocalAttributeName has illegal start character: " + attrLocalName);
}
}
if (!SAX3XMLConstants.isNameChar(c)) {
throw new SAXException("LocalAttributeName has illegal name character: " + attrLocalName);
throw new SAXException("LocalAttributeName has illegal name character: " + attrLocalName);
}
}
}
@ -279,14 +279,14 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
public void startElementTag(String uri, String localName) throws SAXException {
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) | uri==null) {
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
startElement.append(localName);
} else {
String prefix = prefixMapping.get(uri);
if (prefix==null) {
throw new SAXException("preFixUri: "+uri+" is not started.");
if (prefix == null) {
throw new SAXException("preFixUri: " + uri + " is not started.");
}
if (SAX3XMLConstants.NULL_NS_URI.equals(prefix)==false) {
if (SAX3XMLConstants.NULL_NS_URI.equals(prefix) == false) {
startElement.append(prefix);
startElement.append(SAX3XMLConstants.XMLNS_ASSIGN);
}
@ -306,13 +306,13 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
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);
startElement.append(' ');
startElement.append(SAX3XMLConstants.XMLNS_ATTRIBUTE);
if ("".equals(prefix)==false) {
if ("".equals(prefix) == false) {
startElement.append(SAX3XMLConstants.XMLNS_ASSIGN);
startElement.append(prefix);
}
@ -327,27 +327,25 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
String prefix = null;
boolean first = true;
for (String uri2:prefixMapping.keySet()) {
for (String uri2 : prefixMapping.keySet()) {
if (printedMappings.contains(uri2)) {
continue;
}
prefix = prefixMapping.get(uri2);
if (prefix==null) {
throw new SAXException("preFixUri: "+uri2+" is not started.");
if (prefix == null) {
throw new SAXException("preFixUri: " + uri2 + " is not started.");
}
printedMappings.add(uri2);
if (SAX3XMLConstants.NULL_NS_URI.equals(uri2)) {
continue; // don't print empty namespace uri location
}
if (first) {
startElement.append(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
first = false;
}
startElement.append(' ');
startElement.append(SAX3XMLConstants.XMLNS_ATTRIBUTE);
if ("".equals(prefix)==false) {
if ("".equals(prefix) == false) {
startElement.append(SAX3XMLConstants.XMLNS_ASSIGN);
startElement.append(prefix);
}
@ -367,24 +365,23 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
private void startElementAttributes(Attributes atts) throws SAXException {
int prevChars = 0;
for (int i=0;i<atts.getLength();i++) {
for (int i = 0; i < atts.getLength(); i++) {
String attributeUri = atts.getURI(i);
String attributeName = atts.getLocalName(i);
String attributeValue = atts.getValue(i);
if (attributeValue==null) {
if (attributeValue == null) {
attributeValue = propertyConfig.getPropertyString(OUTPUT_CHAR_NULL);
}
String attributeValueSafe = SAX3XMLConstants.escapeAttributeValue(attributeValue);
if (propertyConfig.getPropertyBoolean(OUTPUT_LINE_PER_ATTRIBUTE)) {
if (i==0) {
if (i == 0) {
printElementAttributeNewLineSpace();
}
} else {
startElement.append(' ');
}
if (SAX3XMLConstants.NULL_NS_URI.equals(attributeUri) | attributeUri ==null) {
if (SAX3XMLConstants.NULL_NS_URI.equals(attributeUri) || attributeUri == null) {
startElement.append(attributeName);
} else {
startElement.append(attributeUri);
@ -400,12 +397,12 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
int breakLines = propertyConfig.getPropertyInteger(OUTPUT_LINE_BREAK_WIDTH);
if (breakLines>0) {
if (prevChars==0 && startElement.length() > breakLines) {
if (breakLines > 0) {
if (prevChars == 0 && startElement.length() > breakLines) {
printElementAttributeNewLineSpace();
prevChars = startElement.length();
}
if (prevChars>0 && (startElement.length()-prevChars) > breakLines) {
if (prevChars > 0 && (startElement.length() - prevChars) > breakLines) {
printElementAttributeNewLineSpace();
prevChars = startElement.length();
}
@ -420,17 +417,16 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @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 (elements.size()>0 && elements.peek().equals((localName))==false) {
throw new SAXException("Unexpected end tag: "+localName+" should be: "+elements.peek());
if (elements.size() > 0 && elements.peek().equals((localName)) == false) {
throw new SAXException("Unexpected end tag: " + localName + " should be: " + elements.peek());
}
elements.pop();
if (startElement!=null) {
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;
startElement = null;
indent--;
return;
}
@ -442,19 +438,19 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
} else {
printReturn = true;
}
if (localName==null) {
if (localName == null) {
localName = "null";
}
write(SAX3XMLConstants.TAG_OPEN_END);
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) | uri==null) {
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
write(localName);
} else {
String prefix = prefixMapping.get(uri);
if (prefix==null) {
throw new SAXException("preFixUri: "+uri+" is not started.");
if (prefix == null) {
throw new SAXException("preFixUri: " + uri + " is not started.");
}
if (SAX3XMLConstants.NULL_NS_URI.equals(prefix)==false) {
if (SAX3XMLConstants.NULL_NS_URI.equals(prefix) == false) {
write(prefix);
write(SAX3XMLConstants.XMLNS_ASSIGN);
}
@ -484,14 +480,14 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
Set<Map.Entry<String,String>> s = prefixMapping.entrySet();
String uri = null;
for (Map.Entry<String,String> e:s) {
if (e.getValue()==null) {
if (e.getValue() == null) {
continue; // way ?
}
if (e.getValue().equals(prefix)) {
uri = e.getKey();
}
}
if (uri!=null) {
if (uri != null) {
printedMappings.remove(uri);
prefixMapping.remove(uri);
}
@ -507,7 +503,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
*/
public void characters(char[] ch, int start, int length) throws SAXException {
characters(new String(ch,start,length));
characters(new String(ch, start, length));
}
/**
@ -517,19 +513,19 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String)
*/
public void characters(String text) throws SAXException {
if (text==null) {
if (text == null) {
return;
}
charactersRaw(SAX3XMLConstants.escapeCharacters(text));
}
public void characters(char c) throws SAXException {
characters(new char[]{c},0,1);
characters(new char[]{c}, 0, 1);
}
// move or remove ?
protected void charactersRaw(String text) throws SAXException {
if (text==null) {
if (text == null) {
return;
}
autoCloseStartElement();
@ -547,7 +543,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
*/
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
ignorableWhitespace(new String(ch,start,length));
ignorableWhitespace(new String(ch, start, length));
}
/**
@ -558,7 +554,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String)
*/
public void ignorableWhitespace(String text) throws SAXException {
if (text==null) {
if (text == null) {
return;
}
autoCloseStartElement();
@ -572,7 +568,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @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);
}
/**
@ -587,11 +583,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
if (targetLow.startsWith(SAX3XMLConstants.XML)) {
throw new SAXException("Processing instruction may not start with xml.");
}
if (SAX3XMLConstants.isNameString(target)==false) {
throw new SAXException("Processing instruction target is invalid name; '"+target+"'");
if (SAX3XMLConstants.isNameString(target) == false) {
throw new SAXException("Processing instruction target is invalid name; '" + target + "'");
}
if (SAX3XMLConstants.isCharString(data)==false) {
throw new SAXException("Processing instruction data is invalid char; '"+data+"'");
if (SAX3XMLConstants.isCharString(data) == false) {
throw new SAXException("Processing instruction data is invalid char; '" + data + "'");
}
autoCloseStartElement();
write(getPropertyConfig().getPropertyString(OUTPUT_CHAR_NEWLINE));
@ -634,7 +630,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
*/
public void comment(char[] ch, int start, int length) throws SAXException {
comment(new String(ch,start,length));
comment(new String(ch, start, length));
}
/**
@ -645,7 +641,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @see org.x4o.sax3.io.ContentWriter#comment(java.lang.String)
*/
public void comment(String text) throws SAXException {
if (text==null) {
if (text == null) {
return;
}
if (!propertyConfig.getPropertyBoolean(OUTPUT_COMMENT_ENABLE)) {
@ -653,11 +649,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
}
if (propertyConfig.getPropertyBoolean(OUTPUT_COMMENT_AUTO_SPACE)) {
char textStart = text.charAt(0);
char textEnd = text.charAt(text.length()-1);
if (textStart!=' ' && textStart!='\t' && textStart!='\n') {
text = " "+text;
char textEnd = text.charAt(text.length() - 1);
if (textStart != ' ' && textStart != '\t' && textStart != '\n') {
text = " " + text;
}
if (textEnd!=' ' && textEnd!='\t' && textEnd!='\n') {
if (textEnd != ' ' && textEnd != '\t' && textEnd != '\n') {
text = text + " ";
}
}
@ -666,7 +662,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;
}
@ -677,7 +673,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @param value The value to check.
*/
private void checkPrintedReturn(String value) {
if (value.indexOf(SAX3XMLConstants.CHAR_NEWLINE)>0) {
if (value.indexOf(SAX3XMLConstants.CHAR_NEWLINE) > 0) {
printReturn = true;
} else {
printReturn = false;
@ -689,11 +685,11 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @throws SAXException When prints gives exception.
*/
protected void autoCloseStartElement() throws SAXException {
if (startElement==null) {
if (startElement == null) {
return;
}
write(startElement.toString());
startElement=null;
startElement = null;
}
/**

View file

@ -69,11 +69,11 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter
charactersRaw(SAX3XMLConstants.XML_DOCTYPE_TAG_OPEN);
charactersRaw(" ");
charactersRaw(name);
if (publicId!=null) {
if (publicId != null) {
charactersRaw(" ");
charactersRaw(publicId);
}
if (systemId!=null) {
if (systemId != null) {
charactersRaw(" \"");
charactersRaw(systemId);
charactersRaw("\"");
@ -114,7 +114,7 @@ public abstract class AbstractContentWriterLexical extends AbstractContentWriter
@Override
public void characters(String text) throws SAXException {
if (printCDATA) {
charactersRaw(SAX3XMLConstants.escapeCharactersCdata(text,"",""));
charactersRaw(SAX3XMLConstants.escapeCharactersCdata(text, "", ""));
} else {
super.characters(text);
}

View file

@ -358,7 +358,7 @@ public class AttributeMap<K,V> implements Map<K,V> {
public boolean equals(Object o) {
if (o instanceof Map.Entry) {
Map.Entry mapEntry = (Map.Entry) o;
if (mapEntry.getKey().equals(key) & mapEntry.getValue().equals(value)) {
if (mapEntry.getKey().equals(key) && mapEntry.getValue().equals(value)) {
return true;
}
}

View file

@ -36,28 +36,28 @@ import org.xml.sax.SAXException;
abstract public class ContentWriterAdapter implements ContentWriter {
public void comment(char[] ch, int start, int length) throws SAXException {
comment(new String(ch,start,length));
comment(new String(ch, start, length));
}
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
ignorableWhitespace(new String(ch,start,length));
ignorableWhitespace(new String(ch, start, length));
}
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 {
startElement(uri,localName,name, atts);
startElement(uri, localName, name, atts);
endElement(uri, localName, name);
}
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 {
characters(new String(ch,start,length));
characters(new String(ch, start, length));
}
@Override

View file

@ -43,54 +43,54 @@ public final class SAX3PropertyConfig implements Cloneable {
private final boolean readOnly;
private final String keyPrefix;
public SAX3PropertyConfig(String keyPrefix,PropertyConfigItem...items) {
this(false,null,keyPrefix,items);
public SAX3PropertyConfig(String keyPrefix, PropertyConfigItem... items) {
this(false, null, keyPrefix, items);
}
public SAX3PropertyConfig(SAX3PropertyConfig parentPropertyConfig,String keyPrefix,PropertyConfigItem...items) {
this(false,parentPropertyConfig,keyPrefix,items);
public SAX3PropertyConfig(SAX3PropertyConfig parentPropertyConfig, String keyPrefix, PropertyConfigItem... items) {
this(false, parentPropertyConfig, keyPrefix, items);
}
public SAX3PropertyConfig(boolean readOnly,SAX3PropertyConfig parentPropertyConfig,String keyPrefix,PropertyConfigItem...itemConfig) {
if (keyPrefix==null) {
public SAX3PropertyConfig(boolean readOnly, SAX3PropertyConfig parentPropertyConfig, String keyPrefix, PropertyConfigItem... itemConfig) {
if (keyPrefix == null) {
throw new NullPointerException("Can't create PropertyConfig with null keyPrefix.");
}
this.readOnly=readOnly;
this.keyPrefix=appendSlashIfMissing(keyPrefix);
this.readOnly = readOnly;
this.keyPrefix = appendSlashIfMissing(keyPrefix);
Map<String,PropertyConfigItem> fillItems = new HashMap<String,PropertyConfigItem>(itemConfig.length);
fillPropertyConfigItems(fillItems,itemConfig);
copyParentPropertyConfig(fillItems,parentPropertyConfig);
fillPropertyConfigItems(fillItems, itemConfig);
copyParentPropertyConfig(fillItems, parentPropertyConfig);
if (fillItems.isEmpty()) {
throw new IllegalArgumentException("Can't create PropertyConfig with zero PropertyConfigItems.");
}
for (String key:fillItems.keySet()) {
for (String key : fillItems.keySet()) {
if (!key.startsWith(X4O_PROPERTIES_PREFIX)) {
throw new IllegalArgumentException("Illegal key missing prefix; "+key);
throw new IllegalArgumentException("Illegal key missing prefix; " + key);
}
fillItems.put(key,fillItems.get(key).clone());
fillItems.put(key, fillItems.get(key).clone());
}
items = Collections.unmodifiableMap(fillItems);
}
private final String appendSlashIfMissing(String keyPrefix) {
if (keyPrefix.endsWith("/")==false) {
if (keyPrefix.endsWith("/") == false) {
keyPrefix += "/";
}
return keyPrefix;
}
private final void fillPropertyConfigItems(Map<String,PropertyConfigItem> fillItems,PropertyConfigItem...itemConfig) {
for (int i=0;i<itemConfig.length;i++) {
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);
}
}
private final void copyParentPropertyConfig(Map<String,PropertyConfigItem> fillItems,SAX3PropertyConfig parentPropertyConfig) {
if (parentPropertyConfig==null) {
private final void copyParentPropertyConfig(Map<String,PropertyConfigItem> fillItems, SAX3PropertyConfig parentPropertyConfig) {
if (parentPropertyConfig == null) {
return;
}
for (String key:parentPropertyConfig.getPropertyKeys()) {
for (String key : parentPropertyConfig.getPropertyKeys()) {
fillItems.put(key, parentPropertyConfig.getPropertyConfigItem(key));
}
}
@ -102,29 +102,29 @@ public final class SAX3PropertyConfig implements Cloneable {
private final Object valueDefault;
private Object value = null;
public PropertyConfigItem(boolean valueRequired,String valueKey,Class<?> valueType) {
this(valueRequired,valueKey,valueType,null);
public PropertyConfigItem(boolean valueRequired, String valueKey, Class<?> valueType) {
this(valueRequired, valueKey, valueType, null);
}
public PropertyConfigItem(String valueKey,Class<?> valueType) {
this(false,valueKey,valueType,null);
public PropertyConfigItem(String valueKey, Class<?> valueType) {
this(false, valueKey, valueType, null);
}
public PropertyConfigItem(String valueKey,Class<?> valueType,Object valueDefault) {
this(false,valueKey,valueType,valueDefault); // with default then value can not be required.
public PropertyConfigItem(String valueKey, Class<?> valueType, Object valueDefault) {
this(false, valueKey, valueType, valueDefault); // with default then value can not be required.
}
private PropertyConfigItem(boolean valueRequired,String valueKey,Class<?> valueType,Object valueDefault) {
if (valueKey==null) {
private PropertyConfigItem(boolean valueRequired, String valueKey, Class<?> valueType, Object valueDefault) {
if (valueKey == null) {
throw new NullPointerException("Can't create PropertyConfigItem with null valueKey.");
}
if (valueType==null) {
if (valueType == null) {
throw new NullPointerException("Can't create PropertyConfigItem with null valueType.");
}
this.valueRequired=valueRequired;
this.valueKey=valueKey;
this.valueType=valueType;
this.valueDefault=valueDefault;
this.valueRequired = valueRequired;
this.valueKey = valueKey;
this.valueType = valueType;
this.valueDefault = valueDefault;
}
/**
@ -175,19 +175,19 @@ public final class SAX3PropertyConfig implements Cloneable {
*/
@Override
protected PropertyConfigItem clone() {
PropertyConfigItem clone = new PropertyConfigItem(valueRequired,valueKey,valueType,valueDefault);
PropertyConfigItem clone = new PropertyConfigItem(valueRequired, valueKey, valueType, valueDefault);
clone.setValue(getValue());
return clone;
}
}
private final PropertyConfigItem getPropertyConfigItem(String key) {
if (key==null) {
if (key == null) {
throw new NullPointerException("Can't search with null key.");
}
PropertyConfigItem item = items.get(key);
if (item==null) {
throw new IllegalArgumentException("No config item found for key: "+key);
if (item == null) {
throw new IllegalArgumentException("No config item found for key: " + key);
}
return item;
}
@ -210,14 +210,14 @@ public final class SAX3PropertyConfig implements Cloneable {
private final List<String> findPropertyKeysRequired(boolean checkValue) {
List<String> result = new ArrayList<String>(10);
for (String key:getPropertyKeys()) {
for (String key : getPropertyKeys()) {
PropertyConfigItem item = getPropertyConfigItem(key);
if (!item.isValueRequired()) {
continue;
}
if (!checkValue) {
result.add(item.getValueKey());
} else if (item.getValue()==null && item.getValueDefault()==null) {
} else if (item.getValue() == null && item.getValueDefault() == null) {
result.add(item.getValueKey());
}
}
@ -232,7 +232,7 @@ public final class SAX3PropertyConfig implements Cloneable {
public final void setProperty(String key,Object value) {
if (readOnly) {
throw new IllegalStateException("This property is readonly for key:"+key);
throw new IllegalStateException("This property is readonly for key:" + key);
}
PropertyConfigItem item = getPropertyConfigItem(key);
item.setValue(value);
@ -246,7 +246,7 @@ public final class SAX3PropertyConfig implements Cloneable {
public final Object getProperty(String key) {
PropertyConfigItem item = getPropertyConfigItem(key);
Object value = item.getValue();
if (value==null) {
if (value == null) {
value = item.getValueDefault();
}
return value;
@ -257,7 +257,7 @@ public final class SAX3PropertyConfig implements Cloneable {
return item.getValueType();
}
public final Class<?> getPropertyType(String key,Supplier<Class<?>> defaultValue) {
public final Class<?> getPropertyType(String key, Supplier<Class<?>> defaultValue) {
Class<?> result = getPropertyType(key);
if (result != null) {
return result;
@ -270,13 +270,13 @@ public final class SAX3PropertyConfig implements Cloneable {
if (value instanceof File) {
return (File)value;
}
if (value==null) {
if (value == null) {
return null;
}
throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key);
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
}
public final File getPropertyFile(String key,Supplier<File> defaultValue) {
public final File getPropertyFile(String key, Supplier<File> defaultValue) {
File result = getPropertyFile(key);
if (result != null) {
return result;
@ -289,13 +289,13 @@ public final class SAX3PropertyConfig implements Cloneable {
if (value instanceof Boolean) {
return (Boolean)value;
}
if (value==null) {
if (value == null) {
return null;
}
throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key);
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
}
public final Boolean getPropertyBoolean(String key,Supplier<Boolean> defaultValue) {
public final Boolean getPropertyBoolean(String key, Supplier<Boolean> defaultValue) {
Boolean result = getPropertyBoolean(key);
if (result != null) {
return result;
@ -308,13 +308,13 @@ public final class SAX3PropertyConfig implements Cloneable {
if (value instanceof Integer) {
return (Integer)value;
}
if (value==null) {
if (value == null) {
return null;
}
throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key);
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
}
public final Integer getPropertyInteger(String key,Supplier<Integer> defaultValue) {
public final Integer getPropertyInteger(String key, Supplier<Integer> defaultValue) {
Integer result = getPropertyInteger(key);
if (result != null) {
return result;
@ -328,10 +328,10 @@ public final class SAX3PropertyConfig implements Cloneable {
if (value instanceof List) {
return (List<String>)value;
}
if (value==null) {
if (value == null) {
return null;
}
throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key);
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
}
public final List<String> getPropertyList(String key, Supplier<List<String>> defaultValue) {
@ -348,10 +348,10 @@ public final class SAX3PropertyConfig implements Cloneable {
if (value instanceof Map) {
return (Map<String,String>)value;
}
if (value==null) {
if (value == null) {
return null;
}
throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key);
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
}
public final Map<String,String> getPropertyMap(String key, Supplier<Map<String,String>> defaultValue) {
@ -367,15 +367,15 @@ public final class SAX3PropertyConfig implements Cloneable {
if (value instanceof String) {
return (String)value;
}
if (value==null) {
if (value == null) {
return null;
}
throw new IllegalStateException("Wrong value type: "+value.getClass()+" for key: "+key);
throw new IllegalStateException("Wrong value type: " + value.getClass() + " for key: " + key);
}
public final String getPropertyString(String key,String defaultValue) {
String propertyValue = getPropertyString(key);
if (propertyValue==null) {
if (propertyValue == null) {
return defaultValue;
} else {
return propertyValue;
@ -391,9 +391,9 @@ public final class SAX3PropertyConfig implements Cloneable {
}
public final void copyParentProperties(SAX3PropertyConfig config) {
for (String key:getPropertyKeys()) {
for (String key : getPropertyKeys()) {
Object value = config.getProperty(key);
if (value==null) {
if (value == null) {
continue;
}
setProperty(key, value);
@ -403,7 +403,6 @@ public final class SAX3PropertyConfig implements Cloneable {
@SuppressWarnings("unchecked")
public final void setPropertyParsedValue(String key,String value) {
Class<?> valueType = getPropertyType(key);
//System.out.println("key: "+key+" value: "+value+" type: "+valueType);
if (String.class.equals(valueType)) {
setProperty(key, value);
return;
@ -431,11 +430,11 @@ public final class SAX3PropertyConfig implements Cloneable {
if (List.class.equals(valueType)) {
String[] listValues = value.split(",");
List<String> result = (List<String>)getProperty(key);
if (result==null) {
if (result == null) {
result = new ArrayList<String>(10);
setProperty(key, result);
}
for (String listValue:listValues) {
for (String listValue : listValues) {
result.add(listValue);
}
return;
@ -443,12 +442,12 @@ public final class SAX3PropertyConfig implements Cloneable {
if (Map.class.equals(valueType)) {
String[] listValues = value.split(",");
Map<String,String> result = (Map<String,String>)getProperty(key);
if (result==null) {
if (result == null) {
result = new HashMap<String,String>(10);
setProperty(key, result);
}
if (listValues.length!=2) {
throw new IllegalArgumentException("Coult not parse map value: '"+value+"' parsed length: "+listValues.length+" needs to be 2.");
if (listValues.length != 2) {
throw new IllegalArgumentException("Coult not parse map value: '" + value + "' parsed length: " + listValues.length + " needs to be 2.");
}
String mKey = listValues[0];
String mValue = listValues[1];
@ -463,7 +462,7 @@ public final class SAX3PropertyConfig implements Cloneable {
*/
@Override
public SAX3PropertyConfig clone() {
SAX3PropertyConfig clone = new SAX3PropertyConfig(this,this.keyPrefix);
SAX3PropertyConfig clone = new SAX3PropertyConfig(this, this.keyPrefix);
clone.copyParentProperties(this);
return clone;
}

View file

@ -164,14 +164,14 @@ public final class SAX3XMLConstants {
return getDocumentDeclaration(encoding,null);
}
static public String getDocumentDeclaration(String encoding,String version) {
if (encoding==null) {
encoding=XML_DEFAULT_ENCODING;
static public String getDocumentDeclaration(String encoding, String version) {
if (encoding == null) {
encoding = XML_DEFAULT_ENCODING;
}
if (version==null) {
version=XML_DEFAULT_VERSION;
if (version == null) {
version = XML_DEFAULT_VERSION;
}
return String.format("<?xml version=\"%s\" encoding=\"%s\"?>", version,encoding);
return String.format("<?xml version=\"%s\" encoding=\"%s\"?>", version, encoding);
}
static public boolean isChar(int c) {
@ -236,7 +236,7 @@ public final class SAX3XMLConstants {
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
while (iterator.hasNext()) {
int c = iterator.nextInt();
if (isNameChar(c)==false) {
if (isNameChar(c) == false) {
return false;
}
}
@ -250,11 +250,11 @@ public final class SAX3XMLConstants {
int c = iterator.nextInt();
if (first) {
first = false;
if (isNameStartChar(c)==false) {
if (isNameStartChar(c) == false) {
return false;
}
}
if (isNameChar(c)==false) {
if (isNameChar(c) == false) {
return false;
}
}
@ -348,7 +348,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);
}
@ -397,7 +397,7 @@ public final class SAX3XMLConstants {
static public String escapeCharactersComment(String value,String charTab,int indent) {
value = value.replaceAll(COMMENT_START, "");
value = value.replaceAll(COMMENT_END, "");
value = value.replaceAll(COMMENT_END, "");
StringBuilder result = new StringBuilder(value.length());
PrimitiveIterator.OfInt iterator = value.codePoints().iterator();
while (iterator.hasNext()) {
@ -407,7 +407,6 @@ public final class SAX3XMLConstants {
for (int ii = 0; ii < indent; ii++) {
result.append(charTab);
}
continue;
}
result.appendCodePoint(c);

View file

@ -104,7 +104,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
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);
this.propertyConfig = new SAX3PropertyConfig(DEFAULT_PROPERTY_CONFIG, PROPERTY_CONTEXT_PREFIX);
this.stringIdx = new HashMap<>();
}
@ -161,19 +161,19 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
InputStream licenceInput = null;
String licenceEncoding = propertyConfig.getPropertyString(PROLOG_LICENCE_ENCODING);
String licenceResource = propertyConfig.getPropertyString(PROLOG_LICENCE_RESOURCE);
if (licenceResource!=null) {
if (licenceResource != null) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = this.getClass().getClassLoader();
}
licenceInput = cl.getResourceAsStream(licenceResource);
if (licenceInput==null) {
if (licenceInput == null) {
throw new NullPointerException("Could not load licence resource from: "+licenceResource);
}
}
if (licenceInput==null) {
if (licenceInput == null) {
File licenceFile = propertyConfig.getPropertyFile(PROLOG_LICENCE_FILE);
if (licenceFile==null) {
if (licenceFile == null) {
return;
}
try {
@ -184,32 +184,32 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
}
String licenceText;
try {
licenceText = readLicenceStream(licenceInput,licenceEncoding);
licenceText = readLicenceStream(licenceInput, licenceEncoding);
} catch (IOException e) {
throw new SAXException(e);
}
comment(licenceText);
}
private String readLicenceStream(InputStream inputStream,String encoding) throws IOException {
if (encoding==null) {
private String readLicenceStream(InputStream inputStream, String encoding) throws IOException {
if (encoding == null) {
encoding = SAX3XMLConstants.XML_DEFAULT_ENCODING;
}
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,Charset.forName(encoding)));
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, Charset.forName(encoding)));
try {
StringBuilder sb = new StringBuilder();
sb.append('\n'); // like plugin
sb.append('\n'); // like plugin
sb.append('\n');
sb.append('\n');
String line = br.readLine();
while (line != null) {
if (line.length()>0) {
sb.append(" "); // like plugin
sb.append(" ");
}
sb.append(line);
sb.append('\n');
line = br.readLine();
}
sb.append('\n'); // like plugin
sb.append('\n');
String out = sb.toString();
return out;
} finally {
@ -240,8 +240,8 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
public void endDocument() throws SAXException {
writeTag(XDBXContentTag.DOCUMENT_END);
writeFlush();
if (elements.size()>0) {
throw new SAXException("Invalid xml still have "+elements.size()+" elements open.");
if (elements.size() > 0) {
throw new SAXException("Invalid xml still have " + elements.size() + " elements open.");
}
}
@ -253,13 +253,13 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
* @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) {
if (localName == null) {
throw new SAXException("LocalName may not be null.");
}
if (SAX3XMLConstants.isNameString(localName)==false) {
throw new SAXException("LocalName of element is not valid in xml; '"+localName+"'");
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++) {
for (int i = 0; i < atts.getLength(); i++) {
boolean isFirst = true;
String attrLocalName = atts.getLocalName(i);
if (attrLocalName.isEmpty()) {
@ -271,27 +271,27 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
if (isFirst) {
isFirst = false;
if (!SAX3XMLConstants.isNameStartChar(attrLocalName.codePoints().findFirst().getAsInt())) {
throw new SAXException("LocalAttributeName has illegal start character: " + attrLocalName);
throw new SAXException("LocalAttributeName has illegal start character: " + attrLocalName);
}
}
if (!SAX3XMLConstants.isNameChar(c)) {
throw new SAXException("LocalAttributeName has illegal name character: " + attrLocalName);
throw new SAXException("LocalAttributeName has illegal name character: " + attrLocalName);
}
}
}
startElementTag(uri,localName,name);
startElementNamespace(uri);
startElementAttributes(atts);
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) | uri==null) {
if (SAX3XMLConstants.NULL_NS_URI.equals(uri) || uri == null) {
elements.push(localName);
} else {
elements.push(uri + ":" + name);
}
}
public void startElementTag(String uri, String localName,String name) throws SAXException {
public void startElementTag(String uri, String localName, String name) throws SAXException {
boolean localNameIdx = xdbxStringId(localName);
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));
@ -304,7 +304,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
}
} else {
String prefix = prefixMapping.get(uri);
if (prefix==null) {
if (prefix == null) {
throw new SAXException("preFixUri: "+uri+" is not started.");
}
if (localNameIdx) {
@ -320,9 +320,9 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
}
public void startElementNamespace(String uri) throws SAXException {
if ((uri!=null & SAX3XMLConstants.NULL_NS_URI.equals(uri)==false) && printedMappings.contains(uri)==false) {
if ((uri != null && SAX3XMLConstants.NULL_NS_URI.equals(uri) == false) && printedMappings.contains(uri) == false) {
String prefix = prefixMapping.get(uri);
if (prefix==null) {
if (prefix == null) {
throw new SAXException("preFixUri: "+uri+" is not started.");
}
printedMappings.add(uri);
@ -339,10 +339,10 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
return;
}
String prefix = null;
for (String uri2:prefixMapping.keySet()) {
if (printedMappings.contains(uri2)==false) {
for (String uri2 : prefixMapping.keySet()) {
if (printedMappings.contains(uri2) == false) {
prefix = prefixMapping.get(uri2);
if (prefix==null) {
if (prefix == null) {
throw new SAXException("preFixUri: "+uri+" is not started.");
}
printedMappings.add(uri2);
@ -355,18 +355,18 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
}
private void startElementAttributes(Attributes atts) throws SAXException {
for (int i=0;i<atts.getLength();i++) {
for (int i = 0; i < atts.getLength(); i++) {
String attributeUri = atts.getURI(i);
String attributeName = atts.getLocalName(i);
String attributeValue = atts.getValue(i);
if (attributeValue==null) {
if (attributeValue == null) {
attributeValue = propertyConfig.getPropertyString(OUTPUT_CHAR_NULL);
}
String attributeValueSafe = SAX3XMLConstants.escapeAttributeValue(attributeValue);
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));
@ -379,8 +379,8 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
}
} else {
String attributeUriPrefix = prefixMapping.get(attributeUri);
if (attributeUriPrefix==null) {
throw new SAXException("preFixUri: "+attributeUri+" is not started.");
if (attributeUriPrefix == null) {
throw new SAXException("preFixUri: " + attributeUri + " is not started.");
}
if (attributeNameIdx) {
if (attributeValueSimple) {
@ -407,14 +407,14 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
* @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 (elements.size()>0 && elements.peek().equals(localName)==false) {
throw new SAXException("Unexpected end tag: "+localName+" should be: "+elements.peek());
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());
}
} else {
String qName = uri + ":" + name;
if (elements.size()>0 && elements.peek().equals(qName)==false) {
throw new SAXException("Unexpected end tag: "+qName+" should be: "+elements.peek());
if (elements.size() > 0 && elements.peek().equals(qName) == false) {
throw new SAXException("Unexpected end tag: " + qName + " should be: " + elements.peek());
}
}
elements.pop();
@ -436,7 +436,6 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
writeTagLengthValue(XDBXContentTag.STRING_ID, prefix);
writeVariableInteger(prefixIdxNum);
}
boolean uriIdx = xdbxStringId(uri);
if (!uriIdx) {
int uriIdxNum = xdbxStringStore(uri);
@ -452,15 +451,15 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
public void endPrefixMapping(String prefix) throws SAXException {
Set<Map.Entry<String,String>> s = prefixMapping.entrySet();
String uri = null;
for (Map.Entry<String,String> e:s) {
if (e.getValue()==null) {
for (Map.Entry<String,String> e : s) {
if (e.getValue() == null) {
continue; // way ?
}
if (e.getValue().equals(prefix)) {
uri = e.getKey();
}
}
if (uri!=null) {
if (uri != null) {
prefixMapping.remove(uri);
}
}
@ -475,7 +474,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
*/
public void characters(char[] ch, int start, int length) throws SAXException {
characters(new String(ch,start,length));
characters(new String(ch, start, length));
}
/**
@ -485,19 +484,19 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
* @see org.x4o.sax3.io.ContentWriter#characters(java.lang.String)
*/
public void characters(String text) throws SAXException {
if (text==null) {
if (text == null) {
return;
}
charactersRaw(SAX3XMLConstants.escapeCharacters(text));
}
public void characters(char c) throws SAXException {
characters(new char[]{c},0,1);
characters(new char[]{c}, 0, 1);
}
// move or remove ?
protected void charactersRaw(String text) throws SAXException {
if (text==null) {
if (text == null) {
return;
}
writeTagLengthValue(XDBXContentTag.TEXT_T, text);
@ -513,7 +512,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
*/
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
ignorableWhitespace(new String(ch,start,length));
ignorableWhitespace(new String(ch, start, length));
}
/**
@ -524,7 +523,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
* @see org.x4o.sax3.io.ContentWriter#ignorableWhitespace(java.lang.String)
*/
public void ignorableWhitespace(String text) throws SAXException {
if (text==null) {
if (text == null) {
return;
}
writeTagLengthValue(XDBXContentTag.TEXT_WHITE_SPACE, text);
@ -537,7 +536,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
* @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);
}
/**
@ -552,11 +551,11 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
if (targetLow.startsWith(SAX3XMLConstants.XML)) {
throw new SAXException("Processing instruction may not start with xml.");
}
if (SAX3XMLConstants.isNameString(target)==false) {
throw new SAXException("Processing instruction target is invalid name; '"+target+"'");
if (SAX3XMLConstants.isNameString(target) == false) {
throw new SAXException("Processing instruction target is invalid name; '" + target + "'");
}
if (SAX3XMLConstants.isCharString(data)==false) {
throw new SAXException("Processing instruction data is invalid char; '"+data+"'");
if (SAX3XMLConstants.isCharString(data) == false) {
throw new SAXException("Processing instruction data is invalid char; '" + data + "'");
}
//'I' LengthValue StringID
@ -601,7 +600,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
* @see org.xml.sax.ext.DefaultHandler2#comment(char[], int, int)
*/
public void comment(char[] ch, int start, int length) throws SAXException {
comment(new String(ch,start,length));
comment(new String(ch, start, length));
}
/**
@ -612,7 +611,7 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
* @see org.x4o.sax3.io.ContentWriter#comment(java.lang.String)
*/
public void comment(String text) throws SAXException {
if (text==null) {
if (text == null) {
return;
}
if (!propertyConfig.getPropertyBoolean(OUTPUT_COMMENT_ENABLE)) {
@ -620,15 +619,15 @@ public class AbstractXDBXWriterHandler implements ContentHandler, Closeable {
}
if (propertyConfig.getPropertyBoolean(OUTPUT_COMMENT_AUTO_SPACE)) {
char textStart = text.charAt(0);
char textEnd = text.charAt(text.length()-1);
if (textStart!=' ' && textStart!='\t' && textStart!='\n') {
char textEnd = text.charAt(text.length() - 1);
if (textStart != ' ' && textStart != '\t' && textStart != '\n') {
text = " "+text;
}
if (textEnd!=' ' && textEnd!='\t' && textEnd!='\n') {
if (textEnd != ' ' && textEnd != '\t' && textEnd != '\n') {
text = text + " ";
}
}
writeTagLengthValue(XDBXContentTag.COMMENT, SAX3XMLConstants.escapeCharactersComment(text,"", 0));
writeTagLengthValue(XDBXContentTag.COMMENT, SAX3XMLConstants.escapeCharactersComment(text, "", 0));
}
protected void writeFlush() throws SAXException {

View file

@ -99,7 +99,7 @@ public abstract class AbstractXDBXWriterLexical extends AbstractXDBXWriterHandle
@Override
public void characters(String text) throws SAXException {
if (printCDATA) {
String textSafe = SAX3XMLConstants.escapeCharactersCdata(text,"","");
String textSafe = SAX3XMLConstants.escapeCharactersCdata(text, "", "");
writeTagLengthValue(XDBXContentTag.TEXT_CDATA, textSafe);
} else {
super.characters(text);