| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.style; |
| 9 |
|
| 10 |
import net.sf.saxon.lib.NamespaceConstant; |
| 11 |
import net.sf.saxon.om.*; |
| 12 |
import net.sf.saxon.trans.XPathException; |
| 13 |
import net.sf.saxon.trans.packages.VersionedPackageName; |
| 14 |
import net.sf.saxon.tree.iter.AxisIterator; |
| 15 |
import net.sf.saxon.tree.linked.NodeImpl; |
| 16 |
import net.sf.saxon.tree.util.AttributeCollectionImpl; |
| 17 |
import net.sf.saxon.type.SchemaType; |
| 18 |
import net.sf.saxon.type.Type; |
| 19 |
import net.sf.saxon.value.Whitespace; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public class XSLPackage extends XSLModuleRoot { |
| 28 |
|
| 29 |
private String nameAtt = null; |
| 30 |
private PackageVersion packageVersion = null; |
| 31 |
private boolean declaredModes = true; |
| 32 |
private boolean prepared = false; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
@Override |
| 44 |
public void initialise(NodeName elemName, SchemaType elementType, AttributeCollectionImpl atts, NodeInfo parent, int sequenceNumber) { |
| 45 |
super.initialise(elemName, elementType, atts, parent, sequenceNumber); |
| 46 |
declaredModes = getLocalPart().equals("package"); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public String getName() { |
| 55 |
if (nameAtt == null) { |
| 56 |
try { |
| 57 |
prepareAttributes(); |
| 58 |
} catch (XPathException e) { |
| 59 |
nameAtt = "default"; |
| 60 |
} |
| 61 |
} |
| 62 |
return nameAtt; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public int getVersion() { |
| 71 |
if (version == -1) { |
| 72 |
try { |
| 73 |
prepareAttributes(); |
| 74 |
} catch (XPathException e) { |
| 75 |
version = 30; |
| 76 |
} |
| 77 |
} |
| 78 |
return version; |
| 79 |
} |
| 80 |
|
| 81 |
public VersionedPackageName getNameAndVersion() { |
| 82 |
return new VersionedPackageName(getName(), getPackageVersion()); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public PackageVersion getPackageVersion() { |
| 90 |
if (packageVersion == null) { |
| 91 |
try { |
| 92 |
prepareAttributes(); |
| 93 |
} catch (XPathException e) { |
| 94 |
packageVersion = PackageVersion.ONE; |
| 95 |
} |
| 96 |
} |
| 97 |
return packageVersion; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
@Override |
| 103 |
protected void prepareAttributes() throws XPathException { |
| 104 |
if (prepared) { |
| 105 |
|
| 106 |
return; |
| 107 |
} |
| 108 |
prepared = true; |
| 109 |
|
| 110 |
String inputTypeAnnotationsAtt = null; |
| 111 |
String packageVersionAtt = null; |
| 112 |
AttributeCollection atts = getAttributeList(); |
| 113 |
|
| 114 |
for (int a = 0; a < atts.getLength(); a++) { |
| 115 |
String lexicalName = atts.getQName(a); |
| 116 |
if (lexicalName.equals("name") && getLocalPart().equals("package")) { |
| 117 |
nameAtt = Whitespace.trim(atts.getValue(a)); |
| 118 |
} else if (lexicalName.equals("id")) { |
| 119 |
|
| 120 |
} else if (lexicalName.equals("version")) { |
| 121 |
if (version == -1) { |
| 122 |
processVersionAttribute(""); |
| 123 |
} |
| 124 |
} else if (lexicalName.equals("package-version") && getLocalPart().equals("package")) { |
| 125 |
packageVersionAtt = Whitespace.trim(atts.getValue(a)); |
| 126 |
|
| 127 |
} else if (lexicalName.equals("declared-modes") && getLocalPart().equals("package")) { |
| 128 |
declaredModes = processBooleanAttribute("declared-modes", atts.getValue(a)); |
| 129 |
|
| 130 |
} else if (lexicalName.equals("input-type-annotations")) { |
| 131 |
inputTypeAnnotationsAtt = atts.getValue(a); |
| 132 |
} else { |
| 133 |
checkUnknownAttribute(atts.getNodeName(a)); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
if (packageVersionAtt == null) { |
| 138 |
packageVersion = PackageVersion.ONE; |
| 139 |
} else { |
| 140 |
try { |
| 141 |
packageVersion = new PackageVersion(packageVersionAtt); |
| 142 |
} catch (XPathException ex) { |
| 143 |
compileErrorInAttribute(ex.getMessage(), ex.getErrorCodeLocalPart(), "package-version"); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
if (version == -1) { |
| 148 |
version = 30; |
| 149 |
reportAbsence("version"); |
| 150 |
} |
| 151 |
if (inputTypeAnnotationsAtt != null) { |
| 152 |
switch (inputTypeAnnotationsAtt) { |
| 153 |
case "strip": |
| 154 |
|
| 155 |
break; |
| 156 |
case "preserve": |
| 157 |
|
| 158 |
break; |
| 159 |
case "unspecified": |
| 160 |
|
| 161 |
break; |
| 162 |
default: |
| 163 |
compileError("Invalid value for input-type-annotations attribute. " + |
| 164 |
"Permitted values are (strip, preserve, unspecified)", "XTSE0020"); |
| 165 |
break; |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
@Override |
| 177 |
public boolean isDeclaredModes() { |
| 178 |
if (nameAtt == null) { |
| 179 |
try { |
| 180 |
prepareAttributes(); |
| 181 |
} catch (XPathException e) { |
| 182 |
|
| 183 |
nameAtt = null; |
| 184 |
} |
| 185 |
} |
| 186 |
return declaredModes; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
public void validate(ComponentDeclaration decl) throws XPathException { |
| 197 |
|
| 198 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 199 |
NodeImpl child; |
| 200 |
while ((child = (NodeImpl)kids.next()) != null) { |
| 201 |
int fp = child.getFingerprint(); |
| 202 |
if (child.getNodeKind() == Type.TEXT || |
| 203 |
(child instanceof StyleElement && ((StyleElement) child).isDeclaration()) || |
| 204 |
child instanceof DataElement ) { |
| 205 |
|
| 206 |
} else if (getLocalPart().equals("package") && |
| 207 |
(fp == StandardNames.XSL_USE_PACKAGE || fp == StandardNames.XSL_EXPOSE)) { |
| 208 |
|
| 209 |
} else if (!NamespaceConstant.XSLT.equals(child.getURI()) && !"".equals(child.getURI())) { |
| 210 |
|
| 211 |
} else if (child instanceof AbsentExtensionElement && ((StyleElement) child).forwardsCompatibleModeIsEnabled()) { |
| 212 |
|
| 213 |
} else if (NamespaceConstant.XSLT.equals(child.getURI())) { |
| 214 |
if (child instanceof AbsentExtensionElement) { |
| 215 |
|
| 216 |
} else { |
| 217 |
((StyleElement) child).compileError( |
| 218 |
"Element " + child.getDisplayName() + |
| 219 |
" must not appear directly within " + getDisplayName(), "XTSE0010"); |
| 220 |
} |
| 221 |
} else { |
| 222 |
((StyleElement) child).compileError("Element " + child.getDisplayName() + |
| 223 |
" must not appear directly within " + getDisplayName() + |
| 224 |
" because it is not in a namespace", "XTSE0130"); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
if (declaredModes) { |
| 229 |
String defaultMode = getAttributeValue("default-mode"); |
| 230 |
if (defaultMode != null && getPrincipalStylesheetModule().getRuleManager().obtainMode(getDefaultMode(), false) == null) { |
| 231 |
compileError("The default mode " + defaultMode + " has not been declared in an xsl:mode declaration", "XTSE3085"); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
} |