Skip to content

Commit

Permalink
add seperate methods for namespace aware document builders, #101
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Jun 1, 2015
1 parent 7b03478 commit 823a725
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 22 additions & 1 deletion de.dentrassi.pm.common/src/de/dentrassi/pm/common/XmlHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,14 @@ public boolean hasNext ()

private final DocumentBuilderFactory dbf;

private final DocumentBuilderFactory dbfNs;

public XmlHelper ()
{
this.dbf = DocumentBuilderFactory.newInstance ();
this.dbf.setNamespaceAware ( true );

this.dbfNs = DocumentBuilderFactory.newInstance ();
this.dbfNs.setNamespaceAware ( true );

this.transformerFactory = TransformerFactory.newInstance ();

Expand All @@ -158,11 +162,28 @@ public Document create ()
}
}

public Document createNs ()
{
try
{
return this.dbfNs.newDocumentBuilder ().newDocument ();
}
catch ( final ParserConfigurationException e )
{
throw new RuntimeException ( e );
}
}

public Document parse ( final InputStream stream ) throws Exception
{
return this.dbf.newDocumentBuilder ().parse ( stream );
}

public Document parseNs ( final InputStream stream ) throws Exception
{
return this.dbfNs.newDocumentBuilder ().parse ( stream );
}

public String toString ( final Document doc )
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ public ContextImpl ( final OutputStream primaryStream, final OutputStream fileli
this.filelistsStream = filelistsStream;
this.otherStream = otherStream;

this.primary = xml.create ();
this.primary = xml.createNs ();
this.primaryRoot = this.primary.createElementNS ( "http://linux.duke.edu/metadata/common", "metadata" );
this.primaryRoot.setAttribute ( "xmlns:rpm", "http://linux.duke.edu/metadata/rpm" );
this.primary.appendChild ( this.primaryRoot );

this.filelists = xml.create ();
this.filelists = xml.createNs ();
this.filelistsRoot = this.filelists.createElementNS ( "http://linux.duke.edu/metadata/filelists", "filelists" );
this.filelists.appendChild ( this.filelistsRoot );

this.other = xml.create ();
this.other = xml.createNs ();
this.otherRoot = this.other.createElementNS ( "http://linux.duke.edu/metadata/other", "otherdata" );
this.other.appendChild ( this.otherRoot );

Expand Down Expand Up @@ -418,7 +418,7 @@ private ContextImpl makeContext ( final OutputStream primaryStream, final Output

private void writeRepoMd ( final OutputStream stream, final long now ) throws IOException
{
final Document doc = this.xml.create ();
final Document doc = this.xml.createNs ();

final Element root = doc.createElementNS ( "http://linux.duke.edu/metadata/repo", "repomd" );
doc.appendChild ( root );
Expand Down

0 comments on commit 823a725

Please sign in to comment.