/** * This provides an <code>EventReader</code> that will read from * the specified source. When reading from a source the character * encoding should be the same as the source XML document. * * @param source this is the source to read the document with * * @return this is used to return the event reader implementation */ private EventReader provide(InputSource source) throws Exception { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(source); return new DocumentReader(document); } }
/** * This is used to read the next node from the document. This will * scan through the document, ignoring any comments to find the * next relevant XML event to acquire. Typically events will be * the start and end of an element, as well as any text nodes. * * @return this returns the next event taken from the document */ private EventNode read() throws Exception { Node node = queue.peek(); if(node == null) { return end(); } return read(node); }
/** * This is used to peek at the node from the document. This will * scan through the document, ignoring any comments to find the * next relevant XML event to acquire. Typically events will be * the start and end of an element, as well as any text nodes. * * @return this returns the next event taken from the document */ public EventNode peek() throws Exception { if(peek == null) { peek = next(); } return peek; }
/** * This is used to convert the provided node in to an event. The * conversion process ensures the node can be digested by the core * reader and used to provide an <code>InputNode</code> that can * be used to represent the XML elements or attributes. If the * provided node is not an element then it is considered text. * * @param node the node that is to be converted to an event * * @return this returns an event created from the given node */ private EventNode convert(Node node) throws Exception{ short type = node.getNodeType(); if(type == ELEMENT_NODE) { if(node != null) { stack.push(node); } return start(node); } return text(node); }
/** * This is used to read the next node from the document. This will * scan through the document, ignoring any comments to find the * next relevant XML event to acquire. Typically events will be * the start and end of an element, as well as any text nodes. * * @param node this is the XML node that has been read * * @return this returns the next event taken from the document */ private EventNode read(Node node) throws Exception { Node parent = node.getParentNode(); Node top = stack.top(); if(parent != top) { if(top != null) { stack.pop(); } return end(); } if(node != null) { queue.poll(); } return convert(node); }
/** * This is used to take the next node from the document. This will * scan through the document, ignoring any comments to find the * next relevant XML event to acquire. Typically events will be * the start and end of an element, as well as any text nodes. * * @return this returns the next event taken from the document */ public EventNode next() throws Exception { EventNode next = peek; if(next == null) { next = read(); } else { peek = null; } return next; }
/** * This is used to convert the provided node to a start event. The * conversion process ensures the node can be digested by the core * reader and used to provide an <code>InputNode</code> that can * be used to represent an XML elements within the source document. * * @param node the node that is to be converted to a start event * * @return this returns a start event created from the given node */ private Start start(Node node) { Start event = new Start(node); if(event.isEmpty()) { return build(event); } return event; }
/** * This is used to build the attributes that are to be used to * populate the start event. Populating the start event with the * attributes it contains is required so that each element will * contain its associated attributes. Only attributes that are * not reserved will be added to the start event. * * @param event this is the start event that is to be populated * * @return this returns a start event with its attributes */ private Start build(Start event) { NamedNodeMap list = event.getAttributes(); int length = list.getLength(); for (int i = 0; i < length; i++) { Node node = list.item(i); Attribute value = attribute(node); if(!value.isReserved()) { event.add(value); } } return event; }
/** * This is used to convert the provided node in to an event. The * conversion process ensures the node can be digested by the core * reader and used to provide an <code>InputNode</code> that can * be used to represent the XML elements or attributes. If the * provided node is not an element then it is considered text. * * @param node the node that is to be converted to an event * * @return this returns an event created from the given node */ private EventNode convert(Node node) throws Exception{ short type = node.getNodeType(); if(type == ELEMENT_NODE) { if(node != null) { stack.push(node); } return start(node); } return text(node); }
/** * This is used to read the next node from the document. This will * scan through the document, ignoring any comments to find the * next relevant XML event to acquire. Typically events will be * the start and end of an element, as well as any text nodes. * * @param node this is the XML node that has been read * * @return this returns the next event taken from the document */ private EventNode read(Node node) throws Exception { Node parent = node.getParentNode(); Node top = stack.top(); if(parent != top) { if(top != null) { stack.pop(); } return end(); } if(node != null) { queue.poll(); } return convert(node); }
/** * This is used to take the next node from the document. This will * scan through the document, ignoring any comments to find the * next relevant XML event to acquire. Typically events will be * the start and end of an element, as well as any text nodes. * * @return this returns the next event taken from the document */ public EventNode next() throws Exception { EventNode next = peek; if(next == null) { next = read(); } else { peek = null; } return next; }
/** * This is used to convert the provided node to a start event. The * conversion process ensures the node can be digested by the core * reader and used to provide an <code>InputNode</code> that can * be used to represent an XML elements within the source document. * * @param node the node that is to be converted to a start event * * @return this returns a start event created from the given node */ private Start start(Node node) { Start event = new Start(node); if(event.isEmpty()) { return build(event); } return event; }
/** * This is used to build the attributes that are to be used to * populate the start event. Populating the start event with the * attributes it contains is required so that each element will * contain its associated attributes. Only attributes that are * not reserved will be added to the start event. * * @param event this is the start event that is to be populated * * @return this returns a start event with its attributes */ private Start build(Start event) { NamedNodeMap list = event.getAttributes(); int length = list.getLength(); for (int i = 0; i < length; i++) { Node node = list.item(i); Attribute value = attribute(node); if(!value.isReserved()) { event.add(value); } } return event; }
/** * This is used to read the next node from the document. This will * scan through the document, ignoring any comments to find the * next relevant XML event to acquire. Typically events will be * the start and end of an element, as well as any text nodes. * * @return this returns the next event taken from the document */ private EventNode read() throws Exception { Node node = queue.peek(); if(node == null) { return end(); } return read(node); }
/** * This is used to convert the provided node in to an event. The * conversion process ensures the node can be digested by the core * reader and used to provide an <code>InputNode</code> that can * be used to represent the XML elements or attributes. If the * provided node is not an element then it is considered text. * * @param node the node that is to be converted to an event * * @return this returns an event created from the given node */ private EventNode convert(Node node) throws Exception{ short type = node.getNodeType(); if(type == ELEMENT_NODE) { if(node != null) { stack.push(node); } return start(node); } return text(node); }
/** * This is used to read the next node from the document. This will * scan through the document, ignoring any comments to find the * next relevant XML event to acquire. Typically events will be * the start and end of an element, as well as any text nodes. * * @param node this is the XML node that has been read * * @return this returns the next event taken from the document */ private EventNode read(Node node) throws Exception { Node parent = node.getParentNode(); Node top = stack.top(); if(parent != top) { if(top != null) { stack.pop(); } return end(); } if(node != null) { queue.poll(); } return convert(node); }
/** * This is used to peek at the node from the document. This will * scan through the document, ignoring any comments to find the * next relevant XML event to acquire. Typically events will be * the start and end of an element, as well as any text nodes. * * @return this returns the next event taken from the document */ public EventNode peek() throws Exception { if(peek == null) { peek = next(); } return peek; }
/** * This provides an <code>EventReader</code> that will read from * the specified source. When reading from a source the character * encoding should be the same as the source XML document. * * @param source this is the source to read the document with * * @return this is used to return the event reader implementation */ private EventReader provide(InputSource source) throws Exception { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(source); return new DocumentReader(document); } }
/** * This is used to take the next node from the document. This will * scan through the document, ignoring any comments to find the * next relevant XML event to acquire. Typically events will be * the start and end of an element, as well as any text nodes. * * @return this returns the next event taken from the document */ public EventNode next() throws Exception { EventNode next = peek; if(next == null) { next = read(); } else { peek = null; } return next; }
/** * This is used to convert the provided node to a start event. The * conversion process ensures the node can be digested by the core * reader and used to provide an <code>InputNode</code> that can * be used to represent an XML elements within the source document. * * @param node the node that is to be converted to a start event * * @return this returns a start event created from the given node */ private Start start(Node node) { Start event = new Start(node); if(event.isEmpty()) { return build(event); } return event; }