Skip to content

Commit

Permalink
minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
clausnagel committed Dec 10, 2023
1 parent 5eb517b commit 9d17d36
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/main/java/org/xmlobjects/stream/XMLOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public abstract class XMLOutput<T extends XMLOutput<?>> extends SAXFilter implem
protected boolean writeXMLDeclaration = true;
protected String[] headerComment;

protected abstract T self();

public XMLOutput() {
super(new DefaultHandler());
}
Expand All @@ -57,11 +59,10 @@ String createPrefix(String namespaceURI) {
return prefixMapping.createPrefix(namespaceURI);
}

@SuppressWarnings("unchecked")
public T withPrefix(String prefix, String namespaceURI) {
prefixMapping.pushContext();
prefixMapping.declarePrefix(prefix, namespaceURI);
return (T) this;
return self();
}

public String getNamespaceURI(String prefix) {
Expand All @@ -76,46 +77,42 @@ public String getSchemaLocation(String namespaceURI) {
return schemaLocations.get(namespaceURI);
}

@SuppressWarnings("unchecked")
public T withSchemaLocation(String namespaceURI, String schemaLocation) {
if (namespaceURI != null && schemaLocation != null) {
schemaLocations.put(namespaceURI, schemaLocation);
withPrefix("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
}

return (T) this;
return self();
}

public String getIndent() {
return indent;
}

@SuppressWarnings("unchecked")
public T withIndent(String indent) {
this.indent = indent;
return (T) this;
return self();
}

public boolean isWriteXMLDeclaration() {
return writeXMLDeclaration;
}

@SuppressWarnings("unchecked")
public T writeXMLDeclaration(boolean writeXMLDeclaration) {
this.writeXMLDeclaration = writeXMLDeclaration;
return (T) this;
return self();
}

public String[] getHeaderComment() {
return headerComment;
}

@SuppressWarnings("unchecked")
public T withHeaderComment(String... headerMessage) {
if (headerMessage != null) {
this.headerComment = headerMessage;
}

return (T) this;
return self();
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/xmlobjects/util/xml/SAXOutputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,9 @@ public void endElement(String uri, String localName, String qName) throws SAXExc

prefixMapping.popContext();
}

@Override
protected SAXOutputHandler self() {
return this;
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/xmlobjects/util/xml/SAXWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,9 @@ private void writeAttributeContent(String content) throws IOException {

writer.write(content, pos, end - pos);
}

@Override
protected SAXWriter self() {
return this;
}
}

0 comments on commit 9d17d36

Please sign in to comment.