1
package dk.brics.xsugar.xml;
5
import dk.brics.xsugar.stylesheet.*;
8
* Inserts XML namespace declarations in the first start tag in an output string.
10
public class NamespaceAdder {
12
private Stylesheet stylesheet;
15
* Constructs a new namespace adder.
16
* @param stylesheet stylesheet
18
public NamespaceAdder(Stylesheet stylesheet) {
19
this.stylesheet = stylesheet;
23
* Fixes the given output string.
25
* @return fixed string
27
public String fix(String s) {
28
StringBuilder b = new StringBuilder();
30
boolean insert = false;
31
for (int i = 0; i < s.length(); i++) {
34
char c2 = s.charAt(i + 1);
35
insert = d == 0 && c2 != '/';
42
for (Map.Entry<String,String> ns : stylesheet.getNamespaces().entrySet()) {
43
String prefix = ns.getKey();
44
String uri = ns.getValue();
46
if (prefix != null || !uri.equals("")) {
50
name = "xmlns:" + prefix;
51
b.append(' ').append(name).append("=\"").append(uri).append("\"");