| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.lib; |
| 9 |
|
| 10 |
import net.sf.saxon.Configuration; |
| 11 |
import net.sf.saxon.event.*; |
| 12 |
import net.sf.saxon.om.NameChecker; |
| 13 |
import net.sf.saxon.om.NamespaceResolver; |
| 14 |
import net.sf.saxon.om.QNameException; |
| 15 |
import net.sf.saxon.om.TreeInfo; |
| 16 |
import net.sf.saxon.query.SequenceWrapper; |
| 17 |
import net.sf.saxon.serialize.*; |
| 18 |
import net.sf.saxon.stax.StAXResultHandlerImpl; |
| 19 |
import net.sf.saxon.trans.Err; |
| 20 |
import net.sf.saxon.trans.SaxonErrorCode; |
| 21 |
import net.sf.saxon.trans.XPathException; |
| 22 |
import net.sf.saxon.value.AtomicValue; |
| 23 |
import net.sf.saxon.value.BigDecimalValue; |
| 24 |
|
| 25 |
import javax.xml.transform.OutputKeys; |
| 26 |
import javax.xml.transform.Result; |
| 27 |
import javax.xml.transform.Source; |
| 28 |
import javax.xml.transform.TransformerException; |
| 29 |
import javax.xml.transform.sax.SAXResult; |
| 30 |
import javax.xml.transform.stax.StAXResult; |
| 31 |
import javax.xml.transform.stream.StreamResult; |
| 32 |
import java.io.Writer; |
| 33 |
import java.util.*; |
| 34 |
import java.util.regex.Pattern; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public class SerializerFactory { |
| 48 |
|
| 49 |
Configuration config; |
| 50 |
PipelineConfiguration pipe; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public SerializerFactory(Configuration config) { |
| 59 |
this.config = config; |
| 60 |
} |
| 61 |
|
| 62 |
public SerializerFactory(PipelineConfiguration pipe) { |
| 63 |
this.pipe = pipe; |
| 64 |
this.config = pipe.getConfiguration(); |
| 65 |
} |
| 66 |
|
| 67 |
public Configuration getConfiguration() { |
| 68 |
return config; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public StreamWriterToReceiver getXMLStreamWriter( |
| 82 |
StreamResult result, |
| 83 |
Properties properties) throws XPathException { |
| 84 |
Receiver r = getReceiver(result, new SerializationProperties(properties)); |
| 85 |
r = new NamespaceReducer(r); |
| 86 |
return new StreamWriterToReceiver(r); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
public Receiver getReceiver(Result result, |
| 119 |
PipelineConfiguration pipe, |
| 120 |
Properties props) |
| 121 |
throws XPathException { |
| 122 |
return getReceiver(result, new SerializationProperties(props), pipe); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
public Receiver getReceiver(Result result) throws XPathException { |
| 140 |
return getReceiver(result, new SerializationProperties(), config.makePipelineConfiguration()); |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
public Receiver getReceiver(Result result, SerializationProperties params) throws XPathException { |
| 159 |
return getReceiver(result, params, config.makePipelineConfiguration()); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
public Receiver getReceiver(Result result, |
| 185 |
SerializationProperties params, |
| 186 |
PipelineConfiguration pipe) |
| 187 |
throws XPathException { |
| 188 |
|
| 189 |
Objects.requireNonNull(result); |
| 190 |
Objects.requireNonNull(params); |
| 191 |
Objects.requireNonNull(pipe); |
| 192 |
|
| 193 |
Properties props = params.getProperties(); |
| 194 |
CharacterMapIndex charMapIndex = params.getCharacterMapIndex(); |
| 195 |
if (charMapIndex == null) { |
| 196 |
charMapIndex = new CharacterMapIndex(); |
| 197 |
} |
| 198 |
String nextInChain = props.getProperty(SaxonOutputKeys.NEXT_IN_CHAIN); |
| 199 |
if (nextInChain != null && !nextInChain.isEmpty()) { |
| 200 |
String href = props.getProperty(SaxonOutputKeys.NEXT_IN_CHAIN); |
| 201 |
String base = props.getProperty(SaxonOutputKeys.NEXT_IN_CHAIN_BASE_URI); |
| 202 |
if (base == null) { |
| 203 |
base = ""; |
| 204 |
} |
| 205 |
Properties sansNext = new Properties(props); |
| 206 |
sansNext.setProperty(SaxonOutputKeys.NEXT_IN_CHAIN, ""); |
| 207 |
return prepareNextStylesheet(pipe, href, base, result); |
| 208 |
} |
| 209 |
String paramDoc = props.getProperty(SaxonOutputKeys.PARAMETER_DOCUMENT); |
| 210 |
if (paramDoc != null) { |
| 211 |
String base = props.getProperty(SaxonOutputKeys.PARAMETER_DOCUMENT_BASE_URI); |
| 212 |
if (base == null) { |
| 213 |
base = result.getSystemId(); |
| 214 |
} |
| 215 |
Properties props2 = new Properties(props); |
| 216 |
Source source; |
| 217 |
try { |
| 218 |
source = config.getURIResolver().resolve(paramDoc, base); |
| 219 |
} catch (TransformerException e) { |
| 220 |
throw XPathException.makeXPathException(e); |
| 221 |
} |
| 222 |
ParseOptions options = new ParseOptions(); |
| 223 |
options.setSchemaValidationMode(Validation.LAX); |
| 224 |
TreeInfo doc = config.buildDocumentTree(source); |
| 225 |
SerializationParamsHandler ph = new SerializationParamsHandler(); |
| 226 |
ph.setSerializationParams(doc.getRootNode()); |
| 227 |
Properties paramDocProps = ph.getSerializationProperties().getProperties(); |
| 228 |
Enumeration<?> names = paramDocProps.propertyNames(); |
| 229 |
while (names.hasMoreElements()) { |
| 230 |
String name = (String)names.nextElement(); |
| 231 |
String value = paramDocProps.getProperty(name); |
| 232 |
props2.setProperty(name, value); |
| 233 |
} |
| 234 |
CharacterMap charMap = ph.getCharacterMap(); |
| 235 |
if (charMap != null) { |
| 236 |
props2.setProperty(SaxonOutputKeys.USE_CHARACTER_MAPS, charMap.getName().getClarkName()); |
| 237 |
charMapIndex.putCharacterMap(charMap.getName(), charMap); |
| 238 |
} |
| 239 |
props = props2; |
| 240 |
} |
| 241 |
if (result instanceof StreamResult) { |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
SequenceReceiver target; |
| 250 |
String method = props.getProperty(OutputKeys.METHOD); |
| 251 |
if (method == null) { |
| 252 |
return newUncommittedSerializer(result, new Sink(pipe), params); |
| 253 |
} |
| 254 |
|
| 255 |
Emitter emitter = null; |
| 256 |
|
| 257 |
switch (method) { |
| 258 |
case "html": { |
| 259 |
emitter = newHTMLEmitter(props); |
| 260 |
emitter.setPipelineConfiguration(pipe); |
| 261 |
target = createHTMLSerializer(emitter, params, pipe); |
| 262 |
break; |
| 263 |
} |
| 264 |
case "xml": { |
| 265 |
emitter = newXMLEmitter(props); |
| 266 |
emitter.setPipelineConfiguration(pipe); |
| 267 |
target = createXMLSerializer((XMLEmitter) emitter, params); |
| 268 |
break; |
| 269 |
} |
| 270 |
case "xhtml": { |
| 271 |
emitter = newXHTMLEmitter(props); |
| 272 |
emitter.setPipelineConfiguration(pipe); |
| 273 |
target = createXHTMLSerializer(emitter, params, pipe); |
| 274 |
break; |
| 275 |
} |
| 276 |
case "text": { |
| 277 |
emitter = newTEXTEmitter(); |
| 278 |
emitter.setPipelineConfiguration(pipe); |
| 279 |
target = createTextSerializer(emitter, params); |
| 280 |
break; |
| 281 |
} |
| 282 |
case "json": { |
| 283 |
StreamResult sr = (StreamResult) result; |
| 284 |
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); |
| 285 |
JSONEmitter je = new JSONEmitter(pipe, sr, props); |
| 286 |
JSONSerializer js = new JSONSerializer(pipe, je, props); |
| 287 |
String sortOrder = props.getProperty(SaxonOutputKeys.PROPERTY_ORDER); |
| 288 |
if (sortOrder != null) { |
| 289 |
js.setPropertySorter(getPropertySorter(sortOrder)); |
| 290 |
} |
| 291 |
CharacterMapExpander characterMapExpander = makeCharacterMapExpander(pipe, props, charMapIndex); |
| 292 |
ProxyReceiver normalizer = makeUnicodeNormalizer(pipe, props); |
| 293 |
return customizeJSONSerializer(js, props, characterMapExpander, normalizer); |
| 294 |
|
| 295 |
} |
| 296 |
case "adaptive": { |
| 297 |
ExpandedStreamResult esr = new ExpandedStreamResult(pipe.getConfiguration(), (StreamResult)result, props); |
| 298 |
Writer writer = esr.obtainWriter(); |
| 299 |
AdaptiveEmitter je = new AdaptiveEmitter(pipe, writer); |
| 300 |
je.setOutputProperties(props); |
| 301 |
CharacterMapExpander characterMapExpander = makeCharacterMapExpander(pipe, props, charMapIndex); |
| 302 |
ProxyReceiver normalizer = makeUnicodeNormalizer(pipe, props); |
| 303 |
return customizeAdaptiveSerializer(je, props, characterMapExpander, normalizer); |
| 304 |
} |
| 305 |
default: { |
| 306 |
if (method.startsWith("{" + NamespaceConstant.SAXON + "}")) { |
| 307 |
CharacterMapExpander characterMapExpander = makeCharacterMapExpander(pipe, props, charMapIndex); |
| 308 |
ProxyReceiver normalizer = makeUnicodeNormalizer(pipe, props); |
| 309 |
target = createSaxonSerializationMethod( |
| 310 |
method, params, pipe, characterMapExpander, normalizer, (StreamResult)result); |
| 311 |
if (target instanceof Emitter) { |
| 312 |
emitter = (Emitter) target; |
| 313 |
} |
| 314 |
} else { |
| 315 |
Receiver userReceiver; |
| 316 |
if (pipe == null) { |
| 317 |
throw new XPathException("Unsupported serialization method " + method); |
| 318 |
} else { |
| 319 |
userReceiver = createUserDefinedOutputMethod(method, props, pipe); |
| 320 |
if (userReceiver instanceof Emitter) { |
| 321 |
emitter = (Emitter) userReceiver; |
| 322 |
target = params.makeSequenceNormalizer(emitter); |
| 323 |
} else { |
| 324 |
return params.makeSequenceNormalizer(userReceiver); |
| 325 |
} |
| 326 |
} |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
if (emitter != null) { |
| 331 |
emitter.setOutputProperties(props); |
| 332 |
StreamResult sr = (StreamResult) result; |
| 333 |
emitter.setStreamResult(sr); |
| 334 |
} |
| 335 |
|
| 336 |
target.setSystemId(result.getSystemId()); |
| 337 |
return target; |
| 338 |
} else { |
| 339 |
|
| 340 |
return getReceiverForNonSerializedResult(result, props, pipe); |
| 341 |
|
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
private ProxyReceiver makeUnicodeNormalizer(PipelineConfiguration pipe, Properties props) throws XPathException { |
| 346 |
String normForm = props.getProperty(SaxonOutputKeys.NORMALIZATION_FORM); |
| 347 |
if (normForm != null && !normForm.equals("none")) { |
| 348 |
return newUnicodeNormalizer(new Sink(pipe), props); |
| 349 |
} |
| 350 |
return null; |
| 351 |
} |
| 352 |
|
| 353 |
private CharacterMapExpander makeCharacterMapExpander(PipelineConfiguration pipe, Properties props, CharacterMapIndex charMapIndex) throws XPathException { |
| 354 |
String useMaps = props.getProperty(SaxonOutputKeys.USE_CHARACTER_MAPS); |
| 355 |
if (useMaps != null) { |
| 356 |
return charMapIndex.makeCharacterMapExpander(useMaps, new Sink(pipe), this); |
| 357 |
} |
| 358 |
return null; |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
private Receiver getReceiverForNonSerializedResult(Result result, Properties props, PipelineConfiguration pipe) throws XPathException { |
| 372 |
if (result instanceof Emitter) { |
| 373 |
if (((Emitter) result).getOutputProperties() == null) { |
| 374 |
((Emitter) result).setOutputProperties(props); |
| 375 |
} |
| 376 |
return (Emitter) result; |
| 377 |
} else if (result instanceof JSONSerializer) { |
| 378 |
if (((JSONSerializer) result).getOutputProperties() == null) { |
| 379 |
((JSONSerializer) result).setOutputProperties(props); |
| 380 |
} |
| 381 |
return (JSONSerializer) result; |
| 382 |
} else if (result instanceof AdaptiveEmitter) { |
| 383 |
if (((AdaptiveEmitter) result).getOutputProperties() == null) { |
| 384 |
((AdaptiveEmitter) result).setOutputProperties(props); |
| 385 |
} |
| 386 |
return (AdaptiveEmitter) result; |
| 387 |
} else if (result instanceof ComplexContentOutputter) { |
| 388 |
return (ComplexContentOutputter)result; |
| 389 |
} else if (result instanceof Receiver) { |
| 390 |
Receiver receiver = (Receiver) result; |
| 391 |
receiver.setSystemId(result.getSystemId()); |
| 392 |
receiver.setPipelineConfiguration(pipe); |
| 393 |
if (((Receiver) result).handlesAppend() && "no".equals(props.getProperty(SaxonOutputKeys.BUILD_TREE))) { |
| 394 |
return receiver; |
| 395 |
|
| 396 |
} else { |
| 397 |
return new ComplexContentOutputter(receiver); |
| 398 |
} |
| 399 |
} else if (result instanceof SAXResult) { |
| 400 |
ContentHandlerProxy proxy = newContentHandlerProxy(); |
| 401 |
proxy.setUnderlyingContentHandler(((SAXResult) result).getHandler()); |
| 402 |
proxy.setPipelineConfiguration(pipe); |
| 403 |
proxy.setOutputProperties(props); |
| 404 |
if ("yes".equals(props.getProperty(SaxonOutputKeys.SUPPLY_SOURCE_LOCATOR))) { |
| 405 |
if (config.isCompileWithTracing() && pipe.getController() != null) { |
| 406 |
pipe.getController().addTraceListener(proxy.getTraceListener()); |
| 407 |
} else { |
| 408 |
throw new XPathException( |
| 409 |
"Cannot use saxon:supply-source-locator unless tracing was enabled at compile time", SaxonErrorCode.SXSE0002); |
| 410 |
} |
| 411 |
} |
| 412 |
|
| 413 |
return makeSequenceNormalizer(proxy, props); |
| 414 |
|
| 415 |
} else if (result instanceof StAXResult) { |
| 416 |
StAXResultHandler handler = new StAXResultHandlerImpl(); |
| 417 |
Receiver r = handler.getReceiver(result, props); |
| 418 |
r.setPipelineConfiguration(pipe); |
| 419 |
return makeSequenceNormalizer(r, props); |
| 420 |
|
| 421 |
} else { |
| 422 |
if (pipe != null) { |
| 423 |
|
| 424 |
List externalObjectModels = pipe.getConfiguration().getExternalObjectModels(); |
| 425 |
for (Object externalObjectModel : externalObjectModels) { |
| 426 |
ExternalObjectModel model = (ExternalObjectModel) externalObjectModel; |
| 427 |
Receiver builder = model.getDocumentBuilder(result); |
| 428 |
if (builder != null) { |
| 429 |
builder.setSystemId(result.getSystemId()); |
| 430 |
builder.setPipelineConfiguration(pipe); |
| 431 |
return new TreeReceiver(builder); |
| 432 |
} |
| 433 |
} |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
throw new IllegalArgumentException("Unknown type of result: " + result.getClass()); |
| 438 |
} |
| 439 |
|
| 440 |
public SequenceReceiver makeSequenceNormalizer(Receiver receiver, Properties properties) { |
| 441 |
String method = properties.getProperty(OutputKeys.METHOD); |
| 442 |
if ("json".equals(method) || "adaptive".equals(method)) { |
| 443 |
return receiver instanceof SequenceReceiver ? (SequenceReceiver)receiver : new TreeReceiver(receiver); |
| 444 |
} else { |
| 445 |
PipelineConfiguration pipe = receiver.getPipelineConfiguration(); |
| 446 |
SequenceReceiver result; |
| 447 |
String separator = properties.getProperty(SaxonOutputKeys.ITEM_SEPARATOR); |
| 448 |
if (separator == null || "#absent".equals(separator)) { |
| 449 |
result = new SequenceNormalizerWithSpaceSeparator(receiver); |
| 450 |
} else { |
| 451 |
result = new SequenceNormalizerWithItemSeparator(receiver, separator); |
| 452 |
} |
| 453 |
result.setPipelineConfiguration(pipe); |
| 454 |
return result; |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
protected SequenceReceiver createHTMLSerializer( |
| 470 |
Emitter emitter, SerializationProperties params, PipelineConfiguration pipe) throws XPathException { |
| 471 |
Receiver target; |
| 472 |
target = emitter; |
| 473 |
Properties props = params.getProperties(); |
| 474 |
if (!"no".equals(props.getProperty(OutputKeys.INDENT))) { |
| 475 |
target = newHTMLIndenter(target, props); |
| 476 |
} |
| 477 |
target = injectUnicodeNormalizer(params, target); |
| 478 |
target = injectCharacterMapExpander(params, target, true); |
| 479 |
String cdataElements = props.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); |
| 480 |
if (cdataElements != null && !cdataElements.isEmpty()) { |
| 481 |
target = newCDATAFilter(target, props); |
| 482 |
} |
| 483 |
|
| 484 |
if (SaxonOutputKeys.isHtmlVersion5(props)) { |
| 485 |
target = addHtml5Component(target, props); |
| 486 |
} |
| 487 |
|
| 488 |
if (!"no".equals(props.getProperty(SaxonOutputKeys.ESCAPE_URI_ATTRIBUTES))) { |
| 489 |
target = newHTMLURIEscaper(target, props); |
| 490 |
} |
| 491 |
if (!"no".equals(props.getProperty(SaxonOutputKeys.INCLUDE_CONTENT_TYPE))) { |
| 492 |
target = newHTMLMetaTagAdjuster(target, props); |
| 493 |
} |
| 494 |
String attributeOrder = props.getProperty(SaxonOutputKeys.ATTRIBUTE_ORDER); |
| 495 |
if (attributeOrder != null && !attributeOrder.isEmpty()) { |
| 496 |
target = newAttributeSorter(target, props); |
| 497 |
} |
| 498 |
if (params.getValidationFactory() != null) { |
| 499 |
target = params.getValidationFactory().makeFilter(target); |
| 500 |
} |
| 501 |
return makeSequenceNormalizer(target, props); |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
protected SequenceReceiver createTextSerializer( |
| 515 |
Emitter emitter, SerializationProperties params) throws XPathException { |
| 516 |
Properties props = params.getProperties(); |
| 517 |
Receiver target; |
| 518 |
target = injectUnicodeNormalizer(params, emitter); |
| 519 |
target = injectCharacterMapExpander(params, target, false); |
| 520 |
target = addTextOutputFilter(target, props); |
| 521 |
if (params.getValidationFactory() != null) { |
| 522 |
target = params.getValidationFactory().makeFilter(target); |
| 523 |
} |
| 524 |
return makeSequenceNormalizer(target, props); |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
protected SequenceReceiver customizeJSONSerializer( |
| 539 |
JSONSerializer emitter, Properties props, |
| 540 |
CharacterMapExpander characterMapExpander, ProxyReceiver normalizer) throws XPathException { |
| 541 |
if (normalizer instanceof UnicodeNormalizer) { |
| 542 |
emitter.setNormalizer(((UnicodeNormalizer)normalizer).getNormalizer()); |
| 543 |
} |
| 544 |
if (characterMapExpander != null) { |
| 545 |
emitter.setCharacterMap(characterMapExpander.getCharacterMap()); |
| 546 |
} |
| 547 |
return emitter; |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
protected SequenceReceiver customizeAdaptiveSerializer( |
| 562 |
AdaptiveEmitter emitter, Properties props, |
| 563 |
CharacterMapExpander characterMapExpander, ProxyReceiver normalizer) { |
| 564 |
if (normalizer instanceof UnicodeNormalizer) { |
| 565 |
emitter.setNormalizer(((UnicodeNormalizer) normalizer).getNormalizer()); |
| 566 |
} |
| 567 |
if (characterMapExpander != null) { |
| 568 |
emitter.setCharacterMap(characterMapExpander.getCharacterMap()); |
| 569 |
} |
| 570 |
return emitter; |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
protected SequenceReceiver createXHTMLSerializer( |
| 586 |
Emitter emitter, SerializationProperties params, PipelineConfiguration pipe) throws XPathException { |
| 587 |
Receiver target = emitter; |
| 588 |
Properties props = params.getProperties(); |
| 589 |
if (!"no".equals(props.getProperty(OutputKeys.INDENT))) { |
| 590 |
target = newXHTMLIndenter(target, props); |
| 591 |
} |
| 592 |
target = injectUnicodeNormalizer(params, target); |
| 593 |
target = injectCharacterMapExpander(params, target, true); |
| 594 |
String cdataElements = props.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); |
| 595 |
if (cdataElements != null && !cdataElements.isEmpty()) { |
| 596 |
target = newCDATAFilter(target, props); |
| 597 |
} |
| 598 |
|
| 599 |
if (SaxonOutputKeys.isXhtmlHtmlVersion5(props)) { |
| 600 |
target = addHtml5Component(target, props); |
| 601 |
} |
| 602 |
if (!"no".equals(props.getProperty(SaxonOutputKeys.ESCAPE_URI_ATTRIBUTES))) { |
| 603 |
target = newXHTMLURIEscaper(target, props); |
| 604 |
} |
| 605 |
if (!"no".equals(props.getProperty(SaxonOutputKeys.INCLUDE_CONTENT_TYPE))) { |
| 606 |
target = newXHTMLMetaTagAdjuster(target, props); |
| 607 |
} |
| 608 |
String attributeOrder = props.getProperty(SaxonOutputKeys.ATTRIBUTE_ORDER); |
| 609 |
if (attributeOrder != null && !attributeOrder.isEmpty()) { |
| 610 |
target = newAttributeSorter(target, props); |
| 611 |
} |
| 612 |
if (params.getValidationFactory() != null) { |
| 613 |
target = params.getValidationFactory().makeFilter(target); |
| 614 |
} |
| 615 |
return makeSequenceNormalizer(target, props); |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
public Receiver addHtml5Component(Receiver target, Properties outputProperties) { |
| 629 |
target = new NamespaceReducer(target); |
| 630 |
target = new XHTMLPrefixRemover(target); |
| 631 |
return target; |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
protected SequenceReceiver createXMLSerializer( |
| 645 |
XMLEmitter emitter, SerializationProperties params) throws XPathException { |
| 646 |
Receiver target; |
| 647 |
Properties props = params.getProperties(); |
| 648 |
boolean canonical = "yes".equals(props.getProperty(SaxonOutputKeys.CANONICAL)); |
| 649 |
if ("yes".equals(props.getProperty(OutputKeys.INDENT)) || canonical) { |
| 650 |
target = newXMLIndenter(emitter, props); |
| 651 |
} else { |
| 652 |
target = emitter; |
| 653 |
} |
| 654 |
if ("1.0".equals(props.getProperty(OutputKeys.VERSION)) && |
| 655 |
config.getXMLVersion() == Configuration.XML11) { |
| 656 |
|
| 657 |
|
| 658 |
target = newXML10ContentChecker(target, props); |
| 659 |
} |
| 660 |
target = injectUnicodeNormalizer(params, target); |
| 661 |
if (!canonical) { |
| 662 |
target = injectCharacterMapExpander(params, target, true); |
| 663 |
} |
| 664 |
String cdataElements = props.getProperty(OutputKeys.CDATA_SECTION_ELEMENTS); |
| 665 |
if (cdataElements != null && !cdataElements.isEmpty() && !canonical) { |
| 666 |
target = newCDATAFilter(target, props); |
| 667 |
} |
| 668 |
if (canonical) { |
| 669 |
target = newAttributeSorter(target, props); |
| 670 |
target = newNamespaceSorter(target, props); |
| 671 |
} else { |
| 672 |
String attributeOrder = props.getProperty(SaxonOutputKeys.ATTRIBUTE_ORDER); |
| 673 |
if (attributeOrder != null && !attributeOrder.isEmpty()) { |
| 674 |
target = newAttributeSorter(target, props); |
| 675 |
} |
| 676 |
} |
| 677 |
if (params.getValidationFactory() != null) { |
| 678 |
target = params.getValidationFactory().makeFilter(target); |
| 679 |
} |
| 680 |
return makeSequenceNormalizer(target, props); |
| 681 |
} |
| 682 |
|
| 683 |
protected SequenceReceiver createSaxonSerializationMethod( |
| 684 |
String method, SerializationProperties params, |
| 685 |
PipelineConfiguration pipe, CharacterMapExpander characterMapExpander, |
| 686 |
ProxyReceiver normalizer, StreamResult result) throws XPathException { |
| 687 |
throw new XPathException("Saxon serialization methods require Saxon-PE to be enabled"); |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
protected SequenceReceiver createUserDefinedOutputMethod(String method, Properties props, PipelineConfiguration pipe) throws XPathException { |
| 703 |
Receiver userReceiver; |
| 704 |
userReceiver = pipe.getConfiguration().makeEmitter(method, props); |
| 705 |
userReceiver.setPipelineConfiguration(pipe); |
| 706 |
if (userReceiver instanceof ContentHandlerProxy && |
| 707 |
"yes".equals(props.getProperty(SaxonOutputKeys.SUPPLY_SOURCE_LOCATOR))) { |
| 708 |
if (pipe.getConfiguration().isCompileWithTracing() && pipe.getController() != null) { |
| 709 |
pipe.getController().addTraceListener( |
| 710 |
((ContentHandlerProxy) userReceiver).getTraceListener()); |
| 711 |
} else { |
| 712 |
throw new XPathException( |
| 713 |
"Cannot use saxon:supply-source-locator unless tracing was enabled at compile time", SaxonErrorCode.SXSE0002); |
| 714 |
} |
| 715 |
} |
| 716 |
return userReceiver instanceof SequenceReceiver ? (SequenceReceiver)userReceiver : new TreeReceiver(userReceiver); |
| 717 |
} |
| 718 |
|
| 719 |
protected Receiver injectCharacterMapExpander(SerializationProperties params, Receiver out, boolean useNullMarkers) throws XPathException { |
| 720 |
CharacterMapIndex charMapIndex = params.getCharacterMapIndex(); |
| 721 |
if (charMapIndex != null) { |
| 722 |
String useMaps = params.getProperties().getProperty(SaxonOutputKeys.USE_CHARACTER_MAPS); |
| 723 |
if (useMaps != null) { |
| 724 |
CharacterMapExpander expander = charMapIndex.makeCharacterMapExpander(useMaps, out, this); |
| 725 |
expander.setUseNullMarkers(useNullMarkers); |
| 726 |
return expander; |
| 727 |
} |
| 728 |
} |
| 729 |
return out; |
| 730 |
} |
| 731 |
|
| 732 |
protected Receiver injectUnicodeNormalizer(SerializationProperties params, Receiver out) throws XPathException { |
| 733 |
Properties props = params.getProperties(); |
| 734 |
String normForm = props.getProperty(SaxonOutputKeys.NORMALIZATION_FORM); |
| 735 |
if (normForm != null && !normForm.equals("none")) { |
| 736 |
return newUnicodeNormalizer(out, props); |
| 737 |
} |
| 738 |
return out; |
| 739 |
} |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
protected ContentHandlerProxy newContentHandlerProxy() { |
| 748 |
return new ContentHandlerProxy(); |
| 749 |
} |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
protected UncommittedSerializer newUncommittedSerializer(Result result, Receiver next, SerializationProperties params) { |
| 761 |
return new UncommittedSerializer(result, next, params); |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
protected Emitter newXMLEmitter(Properties properties) { |
| 772 |
return new XMLEmitter(); |
| 773 |
} |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
protected Emitter newHTMLEmitter(Properties properties) { |
| 783 |
HTMLEmitter emitter; |
| 784 |
|
| 785 |
if (SaxonOutputKeys.isHtmlVersion5(properties)) { |
| 786 |
emitter = new HTML50Emitter(); |
| 787 |
} else { |
| 788 |
emitter = new HTML40Emitter(); |
| 789 |
} |
| 790 |
return emitter; |
| 791 |
} |
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
protected Emitter newXHTMLEmitter(Properties properties) { |
| 801 |
boolean is5 = SaxonOutputKeys.isXhtmlHtmlVersion5(properties); |
| 802 |
return is5 ? new XHTML5Emitter() : new XHTML1Emitter(); |
| 803 |
} |
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
public Receiver addTextOutputFilter(Receiver next, Properties properties) throws XPathException { |
| 816 |
return next; |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
protected Emitter newTEXTEmitter() { |
| 826 |
return new TEXTEmitter(); |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
protected ProxyReceiver newXMLIndenter(XMLEmitter next, Properties outputProperties) { |
| 838 |
XMLIndenter r = new XMLIndenter(next); |
| 839 |
r.setOutputProperties(outputProperties); |
| 840 |
return r; |
| 841 |
} |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
protected ProxyReceiver newHTMLIndenter(Receiver next, Properties outputProperties) { |
| 852 |
HTMLIndenter r = new HTMLIndenter(next, "html"); |
| 853 |
r.setOutputProperties(outputProperties); |
| 854 |
return r; |
| 855 |
} |
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
protected ProxyReceiver newXHTMLIndenter(Receiver next, Properties outputProperties) { |
| 866 |
String method = "xhtml"; |
| 867 |
String htmlVersion = outputProperties.getProperty("html-version"); |
| 868 |
if (htmlVersion != null && htmlVersion.startsWith("5")) { |
| 869 |
method="xhtml5"; |
| 870 |
} |
| 871 |
HTMLIndenter r = new HTMLIndenter(next, method); |
| 872 |
r.setOutputProperties(outputProperties); |
| 873 |
return r; |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
protected MetaTagAdjuster newXHTMLMetaTagAdjuster(Receiver next, Properties outputProperties) { |
| 886 |
MetaTagAdjuster r = new MetaTagAdjuster(next); |
| 887 |
r.setIsXHTML(true); |
| 888 |
r.setOutputProperties(outputProperties); |
| 889 |
return r; |
| 890 |
} |
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
protected MetaTagAdjuster newHTMLMetaTagAdjuster(Receiver next, Properties outputProperties) { |
| 902 |
MetaTagAdjuster r = new MetaTagAdjuster(next); |
| 903 |
r.setIsXHTML(false); |
| 904 |
r.setOutputProperties(outputProperties); |
| 905 |
return r; |
| 906 |
} |
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
protected ProxyReceiver newHTMLURIEscaper(Receiver next, Properties outputProperties) { |
| 918 |
return new HTMLURIEscaper(next); |
| 919 |
} |
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
protected ProxyReceiver newXHTMLURIEscaper(Receiver next, Properties outputProperties) { |
| 931 |
return new XHTMLURIEscaper(next); |
| 932 |
} |
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
protected ProxyReceiver newCDATAFilter(Receiver next, Properties outputProperties) throws XPathException { |
| 946 |
CDATAFilter r = new CDATAFilter(next); |
| 947 |
r.setOutputProperties(outputProperties); |
| 948 |
return r; |
| 949 |
} |
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
protected Receiver newAttributeSorter(Receiver next, Properties outputProperties) throws XPathException { |
| 964 |
return next; |
| 965 |
} |
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
protected Receiver newNamespaceSorter(Receiver next, Properties outputProperties) throws XPathException { |
| 976 |
return next; |
| 977 |
} |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
protected ProxyReceiver newXML10ContentChecker(Receiver next, Properties outputProperties) { |
| 990 |
return new XML10ContentChecker(next); |
| 991 |
} |
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
protected ProxyReceiver newUnicodeNormalizer(Receiver next, Properties outputProperties) throws XPathException { |
| 1004 |
String normForm = outputProperties.getProperty(SaxonOutputKeys.NORMALIZATION_FORM); |
| 1005 |
return new UnicodeNormalizer(normForm, next); |
| 1006 |
} |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
public CharacterMapExpander newCharacterMapExpander(Receiver next) { |
| 1016 |
return new CharacterMapExpander(next); |
| 1017 |
} |
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
public SequenceReceiver prepareNextStylesheet(PipelineConfiguration pipe, String href, String baseURI, Result result) |
| 1034 |
throws XPathException { |
| 1035 |
pipe.getConfiguration().checkLicensedFeature(Configuration.LicenseFeature.PROFESSIONAL_EDITION, "saxon:next-in-chain", -1); |
| 1036 |
return null; |
| 1037 |
} |
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
public SequenceWrapper newSequenceWrapper(Receiver destination) { |
| 1047 |
return new SequenceWrapper(destination); |
| 1048 |
} |
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
public String checkOutputProperty(String key, String value) throws XPathException { |
| 1062 |
if (!key.startsWith("{")) { |
| 1063 |
switch (key) { |
| 1064 |
case SaxonOutputKeys.ALLOW_DUPLICATE_NAMES: |
| 1065 |
if (value != null) { |
| 1066 |
value = checkYesOrNo(key, value); |
| 1067 |
} |
| 1068 |
break; |
| 1069 |
case SaxonOutputKeys.BUILD_TREE: |
| 1070 |
if (value != null) { |
| 1071 |
value = checkYesOrNo(key, value); |
| 1072 |
} |
| 1073 |
break; |
| 1074 |
case SaxonOutputKeys.BYTE_ORDER_MARK: |
| 1075 |
if (value != null) { |
| 1076 |
value = checkYesOrNo(key, value); |
| 1077 |
} |
| 1078 |
break; |
| 1079 |
case OutputKeys.CDATA_SECTION_ELEMENTS: |
| 1080 |
if (value != null) { |
| 1081 |
checkListOfClarkNames(key, value); |
| 1082 |
} |
| 1083 |
break; |
| 1084 |
case OutputKeys.DOCTYPE_PUBLIC: |
| 1085 |
if (value != null) { |
| 1086 |
checkPublicIdentifier(value); |
| 1087 |
} |
| 1088 |
break; |
| 1089 |
case OutputKeys.DOCTYPE_SYSTEM: |
| 1090 |
if (value != null) { |
| 1091 |
checkSystemIdentifier(value); |
| 1092 |
} |
| 1093 |
break; |
| 1094 |
case OutputKeys.ENCODING: |
| 1095 |
|
| 1096 |
break; |
| 1097 |
case SaxonOutputKeys.ESCAPE_URI_ATTRIBUTES: |
| 1098 |
if (value != null) { |
| 1099 |
value = checkYesOrNo(key, value); |
| 1100 |
} |
| 1101 |
break; |
| 1102 |
case SaxonOutputKeys.HTML_VERSION: |
| 1103 |
if (value != null) { |
| 1104 |
checkDecimal(key, value); |
| 1105 |
} |
| 1106 |
break; |
| 1107 |
case SaxonOutputKeys.INCLUDE_CONTENT_TYPE: |
| 1108 |
if (value != null) { |
| 1109 |
value = checkYesOrNo(key, value); |
| 1110 |
} |
| 1111 |
break; |
| 1112 |
case OutputKeys.INDENT: |
| 1113 |
if (value != null) { |
| 1114 |
value = checkYesOrNo(key, value); |
| 1115 |
} |
| 1116 |
break; |
| 1117 |
case SaxonOutputKeys.ITEM_SEPARATOR: |
| 1118 |
|
| 1119 |
|
| 1120 |
break; |
| 1121 |
case OutputKeys.METHOD: |
| 1122 |
case SaxonOutputKeys.JSON_NODE_OUTPUT_METHOD: |
| 1123 |
if (value != null) { |
| 1124 |
checkMethod(key, value); |
| 1125 |
} |
| 1126 |
break; |
| 1127 |
case OutputKeys.MEDIA_TYPE: |
| 1128 |
|
| 1129 |
break; |
| 1130 |
case SaxonOutputKeys.NORMALIZATION_FORM: |
| 1131 |
if (value != null) { |
| 1132 |
checkNormalizationForm(value); |
| 1133 |
} |
| 1134 |
break; |
| 1135 |
case OutputKeys.OMIT_XML_DECLARATION: |
| 1136 |
if (value != null) { |
| 1137 |
value = checkYesOrNo(key, value); |
| 1138 |
} |
| 1139 |
break; |
| 1140 |
case OutputKeys.STANDALONE: |
| 1141 |
if (value != null && !value.equals("omit")) { |
| 1142 |
value = checkYesOrNo(key, value); |
| 1143 |
} |
| 1144 |
break; |
| 1145 |
case SaxonOutputKeys.SUPPRESS_INDENTATION: |
| 1146 |
if (value != null) { |
| 1147 |
checkListOfClarkNames(key, value); |
| 1148 |
} |
| 1149 |
break; |
| 1150 |
case SaxonOutputKeys.UNDECLARE_PREFIXES: |
| 1151 |
if (value != null) { |
| 1152 |
value = checkYesOrNo(key, value); |
| 1153 |
} |
| 1154 |
break; |
| 1155 |
case SaxonOutputKeys.USE_CHARACTER_MAPS: |
| 1156 |
if (value != null) { |
| 1157 |
checkListOfClarkNames(key, value); |
| 1158 |
} |
| 1159 |
break; |
| 1160 |
case OutputKeys.VERSION: |
| 1161 |
|
| 1162 |
|
| 1163 |
break; |
| 1164 |
case SaxonOutputKeys.PARAMETER_DOCUMENT: |
| 1165 |
|
| 1166 |
break; |
| 1167 |
default: |
| 1168 |
throw new XPathException("Unknown serialization parameter " + Err.wrap(key), "XQST0109"); |
| 1169 |
} |
| 1170 |
} else if (key.startsWith("{http://saxon.sf.net/}")) { |
| 1171 |
|
| 1172 |
switch (key) { |
| 1173 |
case SaxonOutputKeys.STYLESHEET_VERSION: |
| 1174 |
|
| 1175 |
break; |
| 1176 |
case SaxonOutputKeys.PARAMETER_DOCUMENT_BASE_URI: |
| 1177 |
|
| 1178 |
break; |
| 1179 |
case SaxonOutputKeys.SUPPLY_SOURCE_LOCATOR: |
| 1180 |
if (value != null) { |
| 1181 |
value = checkYesOrNo(key, value); |
| 1182 |
} |
| 1183 |
break; |
| 1184 |
case SaxonOutputKeys.UNFAILING: |
| 1185 |
if (value != null) { |
| 1186 |
value = checkYesOrNo(key, value); |
| 1187 |
} |
| 1188 |
break; |
| 1189 |
default: |
| 1190 |
throw new XPathException("Serialization parameter " + Err.wrap(key) + " not available in Saxon-HE", "XQST0109"); |
| 1191 |
} |
| 1192 |
} else { |
| 1193 |
|
| 1194 |
} |
| 1195 |
return value; |
| 1196 |
} |
| 1197 |
|
| 1198 |
protected static String checkYesOrNo(String key, String value) throws XPathException { |
| 1199 |
if ("yes".equals(value) || "true".equals(value) || "1".equals(value)) { |
| 1200 |
return "yes"; |
| 1201 |
} else if ("no".equals(value) || "false".equals(value) || "0".equals(value)) { |
| 1202 |
return "no"; |
| 1203 |
} else { |
| 1204 |
throw new XPathException("Serialization parameter " + Err.wrap(key) + " must have the value yes|no, true|false, or 1|0", "SEPM0016"); |
| 1205 |
} |
| 1206 |
} |
| 1207 |
|
| 1208 |
private void checkMethod(String key, String value) throws XPathException { |
| 1209 |
if (!"xml".equals(value) && !"html".equals(value) && !"xhtml".equals(value) && !"text".equals(value)) { |
| 1210 |
if (!SaxonOutputKeys.JSON_NODE_OUTPUT_METHOD.equals(key) && ("json".equals(value) || "adaptive".equals(value))) { |
| 1211 |
return; |
| 1212 |
} |
| 1213 |
if (isValidClarkName(value)) { |
| 1214 |
checkExtensions(value); |
| 1215 |
} else { |
| 1216 |
throw new XPathException("Invalid value (" + value + ") for serialization method: " + |
| 1217 |
"must be xml|html|xhtml|text|json|adaptive, or a QName in '{uri}local' form", "SEPM0016"); |
| 1218 |
} |
| 1219 |
} |
| 1220 |
|
| 1221 |
} |
| 1222 |
|
| 1223 |
private static void checkNormalizationForm(String value) throws XPathException { |
| 1224 |
if (!NameChecker.isValidNmtoken(value)) { |
| 1225 |
throw new XPathException("Invalid value for normalization-form: " + |
| 1226 |
"must be NFC, NFD, NFKC, NFKD, fully-normalized, or none", "SEPM0016"); |
| 1227 |
} |
| 1228 |
} |
| 1229 |
|
| 1230 |
private static boolean isValidClarkName( String value) { |
| 1231 |
if (value.isEmpty() || value.charAt(0) != '{') { |
| 1232 |
return false; |
| 1233 |
} |
| 1234 |
int closer = value.indexOf('}'); |
| 1235 |
return closer >= 1 && |
| 1236 |
closer != value.length() - 1 && |
| 1237 |
NameChecker.isValidNCName(value.substring(closer + 1)); |
| 1238 |
} |
| 1239 |
|
| 1240 |
protected static void checkNonNegativeInteger(String key, String value) throws XPathException { |
| 1241 |
try { |
| 1242 |
int n = Integer.parseInt(value); |
| 1243 |
if (n < 0) { |
| 1244 |
throw new XPathException("Value of " + Err.wrap(key) + " must be a non-negative integer", "SEPM0016"); |
| 1245 |
} |
| 1246 |
} catch (NumberFormatException err) { |
| 1247 |
throw new XPathException("Value of " + Err.wrap(key) + " must be a non-negative integer", "SEPM0016"); |
| 1248 |
} |
| 1249 |
} |
| 1250 |
|
| 1251 |
private static void checkDecimal(String key, String value) throws XPathException { |
| 1252 |
if (!BigDecimalValue.castableAsDecimal(value)) { |
| 1253 |
throw new XPathException("Value of " + Err.wrap(key) + |
| 1254 |
" must be a decimal number", "SEPM0016"); |
| 1255 |
} |
| 1256 |
} |
| 1257 |
|
| 1258 |
protected static void checkListOfClarkNames(String key, String value) throws XPathException { |
| 1259 |
StringTokenizer tok = new StringTokenizer(value, " \t\n\r", false); |
| 1260 |
while (tok.hasMoreTokens()) { |
| 1261 |
String s = tok.nextToken(); |
| 1262 |
if (isValidClarkName(s) || NameChecker.isValidNCName(s)) { |
| 1263 |
|
| 1264 |
} else { |
| 1265 |
throw new XPathException("Value of " + Err.wrap(key) + |
| 1266 |
" must be a list of QNames in '{uri}local' notation", "SEPM0016"); |
| 1267 |
} |
| 1268 |
} |
| 1269 |
} |
| 1270 |
|
| 1271 |
protected static void checkListOfClarkNamesAllowingStar(String key, String value) throws XPathException { |
| 1272 |
StringTokenizer tok = new StringTokenizer(value, " \t\n\r", false); |
| 1273 |
while (tok.hasMoreTokens()) { |
| 1274 |
String s = tok.nextToken(); |
| 1275 |
if ("*".equals(s) || isValidClarkName(s) || NameChecker.isValidNCName(s)) { |
| 1276 |
|
| 1277 |
} else { |
| 1278 |
throw new XPathException("Value of " + Err.wrap(key) + |
| 1279 |
" must be a list of QNames in '{uri}local' notation", "SEPM0016"); |
| 1280 |
} |
| 1281 |
} |
| 1282 |
} |
| 1283 |
|
| 1284 |
private static Pattern publicIdPattern = Pattern.compile("^[\\s\\r\\na-zA-Z0-9\\-'()+,./:=?;!*#@$_%]*$"); |
| 1285 |
|
| 1286 |
private static void checkPublicIdentifier(String value) throws XPathException { |
| 1287 |
if (!publicIdPattern.matcher(value).matches()) { |
| 1288 |
throw new XPathException("Invalid character in doctype-public parameter", "SEPM0016"); |
| 1289 |
} |
| 1290 |
} |
| 1291 |
|
| 1292 |
private static void checkSystemIdentifier( String value) throws XPathException { |
| 1293 |
if (value.contains("'") && value.contains("\"")) { |
| 1294 |
throw new XPathException("The doctype-system parameter must not contain both an apostrophe and a quotation mark", "SEPM0016"); |
| 1295 |
} |
| 1296 |
} |
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
public static String parseListOfNodeNames( |
| 1314 |
String value, NamespaceResolver nsResolver, boolean useDefaultNS, boolean prevalidated, String errorCode) |
| 1315 |
throws XPathException { |
| 1316 |
StringBuilder s = new StringBuilder(); |
| 1317 |
StringTokenizer st = new StringTokenizer(value, " \t\n\r", false); |
| 1318 |
while (st.hasMoreTokens()) { |
| 1319 |
String displayname = st.nextToken(); |
| 1320 |
if (prevalidated || (nsResolver == null)) { |
| 1321 |
s.append(' ').append(displayname); |
| 1322 |
} else if (displayname.startsWith("Q{")) { |
| 1323 |
s.append(' ').append(displayname.substring(1)); |
| 1324 |
} else { |
| 1325 |
try { |
| 1326 |
String[] parts = NameChecker.getQNameParts(displayname); |
| 1327 |
String muri = nsResolver.getURIForPrefix(parts[0], useDefaultNS); |
| 1328 |
if (muri == null) { |
| 1329 |
throw new XPathException("Namespace prefix '" + parts[0] + "' has not been declared", errorCode); |
| 1330 |
} |
| 1331 |
s.append(" {").append(muri).append('}').append(parts[1]); |
| 1332 |
} catch (QNameException err) { |
| 1333 |
throw new XPathException("Invalid element name. " + err.getMessage(), errorCode); |
| 1334 |
} |
| 1335 |
} |
| 1336 |
} |
| 1337 |
return s.toString(); |
| 1338 |
} |
| 1339 |
|
| 1340 |
protected void checkExtensions(String key ) throws XPathException { |
| 1341 |
throw new XPathException("Serialization property " + Err.wrap(key) + " is not available in Saxon-HE"); |
| 1342 |
} |
| 1343 |
|
| 1344 |
protected Comparator<AtomicValue> getPropertySorter(String sortSpecification) throws XPathException { |
| 1345 |
throw new XPathException("Serialization property saxon:property-order is not available in Saxon-HE"); |
| 1346 |
} |
| 1347 |
|
| 1348 |
|
| 1349 |
} |
| 1350 |
|