public void namespace(int namespaceCode, int properties) throws XPathException { if (!acceptAttributes) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.NAMESPACE, getNamePool().getPrefixFromNamespaceCode(namespaceCode), getPipelineConfiguration().getHostLanguage(), inDocument, false); } // avoid duplicates for (int n=0; n<countStack[depth - 1]; n++) { if (namespaces[namespacesSize - 1 - n] == namespaceCode) { return; } } addToStack(namespaceCode); countStack[depth - 1]++; }
/** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * @param attName The name of the attribute * @param typeCode The type of the attribute * @param locationId the location of the node in the source, or of the instruction that created it * @param properties Bit significant value. The following bits are defined, inter alia: * <dl> * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * <dd>IS_ID</dd> <dt>Attribute is an ID</dt> * </dl> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(NodeName attName, SimpleType typeCode, CharSequence value, Location locationId, int properties) throws XPathException { super.attribute(attName, typeCode, value, locationId, properties); if ((attName.equals(StandardNames.XML_ID_NAME)) || ((properties & ReceiverOptions.IS_ID) != 0)) { if (value.toString().equals(requiredId)) { matched = true; } } }
/** * Character data */ public void characters(CharSequence chars, Location locationId, int properties) throws XPathException { if (activeDepth > 0) { super.characters(chars, locationId, properties); } }
public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException { NodeInfo xml = (NodeInfo) arguments[0].head(); if (xml == null) { return EmptySequence.getInstance(); } boolean indent = false; if (getArity() > 1) { MapItem suppliedOptions = (MapItem) arguments[1].head(); Map<String, Sequence<?>> options = getDetails().optionDetails.processSuppliedOptions(suppliedOptions, context); indent = ((BooleanValue)options.get("indent").head()).getBooleanValue(); } PipelineConfiguration pipe = context.getController().makePipelineConfiguration(); pipe.setXPathContext(context); JsonReceiver receiver = new JsonReceiver(pipe); receiver.setIndenting(indent); Receiver r = receiver; if (xml.getNodeKind() == Type.DOCUMENT) { r = new DocumentValidator(r, "FOJS0006"); } StartTagBuffer stb = new StartTagBuffer(r); pipe.setComponent(StartTagBuffer.class.getName(), stb); stb.setPipelineConfiguration(pipe); stb.open(); xml.copy(stb, 0, ExplicitLocation.UNKNOWN_LOCATION); stb.close(); return new StringValue(receiver.getJsonString()); }
NamePool namePool = getNamePool(); int nscode = namePool.getNamespaceCode(nameCode); if (nscode == -1) { short existingURICode = getURICode((short)nsprefix); if (existingURICode == -1) { namespace(nscode, 0); return nameCode; } else { } else { String prefix = getSubstitutePrefix(nscode, seq); namePool.getURI(nameCode), namePool.getLocalName(nameCode)); namespace(namePool.allocateNamespaceCode(newCode), 0); return newCode;
/** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * @param nameCode The name of the attribute, as held in the name pool * @param typeCode The type of the attribute, as held in the name pool * @param properties Bit significant value. The following bits are defined: * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties) throws XPathException { if (!acceptAttributes) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.ATTRIBUTE, getNamePool().getDisplayName(nameCode), getPipelineConfiguration().getHostLanguage(), inDocument, false); } // Perform namespace fixup for the attribute if (((properties & ReceiverOptions.NAMESPACE_OK) == 0) && NamePool.getPrefixIndex(nameCode) != 0) { // non-null prefix nameCode = checkProposedPrefix(nameCode, attCount++); } bufferedAttributes.addAttribute(nameCode, typeCode, value.toString(), locationId, properties); // Note: we're relying on the fact that AttributeCollection can hold two attributes of the same name // and maintain their order, because the check for duplicate attributes is not done until later in the // pipeline. We validate both the attributes (see Bugzilla #4600 which legitimizes this.) }
/** * Create a TemplatesHandlerImpl and initialise variables. The constructor is protected, because * the Filter should be created using newTemplatesHandler() in the SAXTransformerFactory * class * @param config the Saxon configuration */ protected TemplatesHandlerImpl(Configuration config) { setPipelineConfiguration(config.makePipelineConfiguration()); nodeFactory = new StyleNodeFactory(config, getPipelineConfiguration().getErrorListener()); builder = new TreeBuilder(); builder.setPipelineConfiguration(getPipelineConfiguration()); builder.setNodeFactory(nodeFactory); builder.setLineNumbering(true); StartTagBuffer startTagBuffer = new StartTagBuffer(); UseWhenFilter useWhenFilter = new UseWhenFilter(startTagBuffer); useWhenFilter.setUnderlyingReceiver(builder); useWhenFilter.setPipelineConfiguration(getPipelineConfiguration()); startTagBuffer.setUnderlyingReceiver(useWhenFilter); startTagBuffer.setPipelineConfiguration(getPipelineConfiguration()); StylesheetStripper styleStripper = new StylesheetStripper(); styleStripper.setUnderlyingReceiver(startTagBuffer); styleStripper.setPipelineConfiguration(getPipelineConfiguration()); CommentStripper commentStripper = new CommentStripper(); commentStripper.setUnderlyingReceiver(styleStripper); commentStripper.setPipelineConfiguration(getPipelineConfiguration()); setReceiver(commentStripper); }
String prefix = binding.getPrefix(); String existingURI = getURIForPrefix(prefix, true); if (existingURI == null) { namespace(binding, 0); return nameCode; } else { } else { prefix = getSubstitutePrefix(binding, seq); nameCode.getURI(), nameCode.getLocalPart()); namespace(newCode.getNamespaceBinding(), 0); return newCode;
private URI processBaseUri(Location location) throws XPathException { String systemId = location.getSystemId(); if (systemId == null) { systemId = getSystemId(); } URI baseUri; if (systemId == null || systemId.equals(systemIdStack.peek())) { baseUri = baseUriStack.peek(); } else { try { baseUri = new URI(systemId); } catch (URISyntaxException e) { throw new XPathException("Invalid URI for stylesheet entity: " + systemId); } } String baseUriAtt = startTag.getAttribute(NamespaceConstant.XML, "base"); if (baseUriAtt != null) { try { baseUri = baseUri.resolve(baseUriAtt); } catch (IllegalArgumentException iae) { throw new XPathException("Invalid URI in xml:base attribute: " + baseUriAtt + ". " + iae.getMessage()); } } baseUriStack.push(baseUri); systemIdStack.push(systemId); return baseUri; }
protected void declareNamespacesForStartElement() throws XPathException { if (activeDepth == 1) { declareAllNamespaces(); } else { super.declareNamespacesForStartElement(); } }
public void namespace(NamespaceBindingSet namespaceBindings, int properties) throws XPathException { for (NamespaceBinding ns : namespaceBindings) { if (!acceptAttributes) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.NAMESPACE, ns.getPrefix(), getPipelineConfiguration().getHostLanguage(), inDocument, ExplicitLocation.UNKNOWN_LOCATION); } // avoid duplicates for (int n = 0; n < countStack[depth - 1]; n++) { if (namespaces[namespacesSize - 1 - n].equals(namespaceBindings)) { return; } } addToStack(ns); countStack[depth - 1]++; } }
throw NoOpenStartTagException.makeNoOpenStartTagException( Type.ATTRIBUTE, attName.getDisplayName(), getPipelineConfiguration().getHostLanguage(), inDocument, ExplicitLocation.UNKNOWN_LOCATION); attName = checkProposedPrefix(attName, attCount++);
/** * Create a TemplatesHandlerImpl and initialise variables. The constructor is protected, because * the Filter should be created using newTemplatesHandler() in the SAXTransformerFactory * class * * @param processor the Saxon s9api processor */ protected TemplatesHandlerImpl(Processor processor) { this.processor = processor; Configuration config = processor.getUnderlyingConfiguration(); setPipelineConfiguration(config.makePipelineConfiguration()); CompilerInfo info = new CompilerInfo(config.getDefaultXsltCompilerInfo()); Compilation compilation = new Compilation(config, info); nodeFactory = compilation.getStyleNodeFactory(true); builder = new LinkedTreeBuilder(getPipelineConfiguration()); builder.setNodeFactory(nodeFactory); builder.setLineNumbering(true); UseWhenFilter useWhenFilter = new UseWhenFilter(compilation, builder, NestedIntegerValue.TWO); StartTagBuffer startTagBuffer = new StartTagBuffer(useWhenFilter); useWhenFilter.setStartTagBuffer(startTagBuffer); StylesheetSpaceStrippingRule rule = new StylesheetSpaceStrippingRule(config.getNamePool()); Stripper styleStripper = new Stripper(rule, startTagBuffer); CommentStripper commentStripper = new CommentStripper(styleStripper); setReceiver(commentStripper); }
styleBuilder.setLineNumbering(true); StartTagBuffer startTagBuffer = new StartTagBuffer(); startTagBuffer.setUnderlyingReceiver(useWhenFilter);
boolean inXsltNamespace = elemName.hasURI(NamespaceConstant.XSLT); String stdAttUri = inXsltNamespace ? "" : NamespaceConstant.XSLT; defaultNamespaceStack.push(startTag.getAttribute(stdAttUri, "xpath-default-namespace")); if (emptyStylesheetElement) { depthOfHole++; if (inXsltNamespace) { if (fp != StandardNames.XSL_OUTPUT) { String versionAtt = startTag.getAttribute("", "version"); version = processVersionAttribute(versionAtt); String versionAtt = startTag.getAttribute(NamespaceConstant.XSLT, "version"); version = processVersionAttribute(versionAtt); String useWhen = startTag.getAttribute(stdAttUri, "use-when"); AttributeCollection allAtts = startTag.getAllAttributes(); NodeName attName = allAtts.getNodeName(allAtts.getIndex(stdAttUri, "use-when")); AttributeLocation attLoc = new AttributeLocation(elemName.getStructuredQName(), attName.getStructuredQName(), location); String staticStr = Whitespace.trim(startTag.getAttribute("", "static")); if ((isVariable || isParam) && defaultNamespaceStack.size() == 2 && StyleElement.isYes(staticStr)) { AttributeCollection atts = startTag.getAllAttributes(); String name = atts.getValue("", "name"); String pversion = atts.getValue("", "package-version");
/** * Output a comment */ public void comment(CharSequence chars, Location locationId, int properties) throws XPathException { if (activeDepth > 0) { super.comment(chars, locationId, properties); } }
/** * Get an element node representing the element whose start tag this is, as required * for implementing conditional type assignment * @return an element node. This contains all the required namespaces and attributes, and has no children; * it is untyped, as are the attributes. */ public NodeInfo getElementNode() throws XPathException { if (elementNode == null) { int len = bufferedAttributes.getLength(); TinyBuilder builder = new TinyBuilder(); builder.setSizeParameters(new int[]{2, len+2, namespacesSize+2, 16}); builder.setPipelineConfiguration(getPipelineConfiguration()); builder.open(); builder.startElement(elementNameCode, StandardNames.XS_UNTYPED_ATOMIC, 0, 0); for (int i=0; i<namespacesSize; i++) { builder.namespace(namespaces[i], 0); } for (int i=0; i<len; i++) { builder.attribute(bufferedAttributes.getNameCode(i), StandardNames.XS_UNTYPED_ATOMIC, bufferedAttributes.getValue(i), 0, 0); } builder.startContent(); builder.endElement(); elementNode = builder.getCurrentRoot(); } return elementNode; }
public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException { NodeInfo xml = (NodeInfo) arguments[0].head(); if (xml == null) { return EmptySequence.getInstance(); } boolean indent = false; if (getArity() > 1) { MapItem suppliedOptions = (MapItem) arguments[1].head(); Map<String, Sequence<?>> options = getDetails().optionDetails.processSuppliedOptions(suppliedOptions, context); indent = ((BooleanValue)options.get("indent").head()).getBooleanValue(); } PipelineConfiguration pipe = context.getController().makePipelineConfiguration(); pipe.setXPathContext(context); JsonReceiver receiver = new JsonReceiver(pipe); receiver.setIndenting(indent); Receiver r = receiver; if (xml.getNodeKind() == Type.DOCUMENT) { r = new DocumentValidator(r, "FOJS0006"); } StartTagBuffer stb = new StartTagBuffer(r); pipe.setComponent(StartTagBuffer.class.getName(), stb); stb.setPipelineConfiguration(pipe); stb.open(); xml.copy(stb, 0, ExplicitLocation.UNKNOWN_LOCATION); stb.close(); return new StringValue(receiver.getJsonString()); }
NamePool namePool = getNamePool(); int nscode = namePool.getNamespaceCode(nameCode); if (nscode == -1) { short existingURICode = getURICode((short)nsprefix); if (existingURICode == -1) { namespace(nscode, 0); return nameCode; } else { } else { String prefix = getSubstitutePrefix(nscode, seq); namePool.getURI(nameCode), namePool.getLocalName(nameCode)); namespace(namePool.allocateNamespaceCode(newCode), 0); return newCode;
/** * Notify an attribute. Attributes are notified after the startElement event, and before any * children. Namespaces and attributes may be intermingled. * * @param nameCode The name of the attribute, as held in the name pool * @param typeCode The type of the attribute, as held in the name pool * @param properties Bit significant value. The following bits are defined: * <dd>DISABLE_ESCAPING</dd> <dt>Disable escaping for this attribute</dt> * <dd>NO_SPECIAL_CHARACTERS</dd> <dt>Attribute value contains no special characters</dt> * @throws IllegalStateException: attempt to output an attribute when there is no open element * start tag */ public void attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties) throws XPathException { if (!acceptAttributes) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.ATTRIBUTE, getNamePool().getDisplayName(nameCode), getPipelineConfiguration().getHostLanguage(), inDocument, false); } // Perform namespace fixup for the attribute if (((properties & ReceiverOptions.NAMESPACE_OK) == 0) && NamePool.getPrefixIndex(nameCode) != 0) { // non-null prefix nameCode = checkProposedPrefix(nameCode, attCount++); } bufferedAttributes.addAttribute(nameCode, typeCode, value.toString(), locationId, properties); // Note: we're relying on the fact that AttributeCollection can hold two attributes of the same name // and maintain their order, because the check for duplicate attributes is not done until later in the // pipeline. We validate both the attributes (see Bugzilla #4600 which proposes to legitimize this.) }