1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
package com.jclark.xsl.sax;
import org.xml.sax.*;
import com.jclark.xsl.tr.*;
import com.jclark.xsl.om.*;
class OutputMethodAttributeList implements AttributeList {
final private OutputMethod method;
final private Name[] names;
private Name[] cdataSectionElements;
OutputMethodAttributeList(OutputMethod method) {
this.method = method;
this.names = method.getAttributeNames();
this.cdataSectionElements = method.getCdataSectionElements();
if (cdataSectionElements.length == 0)
cdataSectionElements = null;
}
public int getLength() {
return names.length;
}
public String getName(int i) {
if (cdataSectionElements != null && i-- == 0)
return "cdata-section-elements";
return nameToString(names[i]);
}
static private final String nameToString(Name name) {
if (name.getNamespace() == null)
return name.getLocalPart();
return (name.getNamespace()
+ OutputMethodHandler.namespaceSeparator
+ name.getLocalPart());
}
public String getValue(int i) {
if (cdataSectionElements != null && i-- == 0) {
StringBuffer buf = new StringBuffer();
for (i = 0; i < cdataSectionElements.length; i++) {
if (i != 0)
buf.append(' ');
buf.append(nameToString(cdataSectionElements[i]));
}
return buf.toString();
}
return method.getAttributeValue(names[i]);
}
public String getType(int i) {
return "CDATA";
}
public String getType(String name) {
return "CDATA";
}
public String getValue(String nameString) {
if (nameString.equals("cdata-section-elements"))
return cdataSectionElements == null ? null : getValue(0);
int ns = nameString.lastIndexOf(OutputMethodHandler.namespaceSeparator);
Name name;
if (ns < 0)
name = method.getNameTable().createName(nameString);
else
name = method.getNameTable().createName(nameString.substring(0, ns),
nameString.substring(ns + 1));
return method.getAttributeValue(name);
}
}
|