|
Java example source code file (ReferenceSubTreeData.java)
The ReferenceSubTreeData.java Java example source code/* * reserved comment block * DO NOT REMOVE OR ALTER! */ /** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /* * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. */ /* * $Id$ */ package com.sun.org.apache.xml.internal.security.signature.reference; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; /** * A representation of a <code>ReferenceNodeSetData type containing a node-set. * This is a subtype of NodeSetData that represents a dereferenced * same-document URI as the root of a subdocument. The main reason is * for efficiency and performance, as some transforms can operate * directly on the subdocument and there is no need to convert it * first to an XPath node-set. */ public class ReferenceSubTreeData implements ReferenceNodeSetData { private boolean excludeComments; private Node root; public ReferenceSubTreeData(Node root, boolean excludeComments) { this.root = root; this.excludeComments = excludeComments; } public Iterator<Node> iterator() { return new DelayedNodeIterator(root, excludeComments); } public Node getRoot() { return root; } public boolean excludeComments() { return excludeComments; } /** * This is an Iterator that contains a backing node-set that is * not populated until the caller first attempts to advance the iterator. */ static class DelayedNodeIterator implements Iterator<Node> { private Node root; private List<Node> nodeSet; private ListIterator<Node> li; private boolean withComments; DelayedNodeIterator(Node root, boolean excludeComments) { this.root = root; this.withComments = !excludeComments; } public boolean hasNext() { if (nodeSet == null) { nodeSet = dereferenceSameDocumentURI(root); li = nodeSet.listIterator(); } return li.hasNext(); } public Node next() { if (nodeSet == null) { nodeSet = dereferenceSameDocumentURI(root); li = nodeSet.listIterator(); } if (li.hasNext()) { return li.next(); } else { throw new NoSuchElementException(); } } public void remove() { throw new UnsupportedOperationException(); } /** * Dereferences a same-document URI fragment. * * @param node the node (document or element) referenced by the * URI fragment. If null, returns an empty set. * @return a set of nodes (minus any comment nodes) */ private List<Node> dereferenceSameDocumentURI(Node node) { List<Node> nodeSet = new ArrayList Other Java examples (source code examples)Here is a short list of links related to this Java ReferenceSubTreeData.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.