All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibm.commons.xml.drivers.XercesDriverL3 Maven / Gradle / Ivy

The newest version!
/*
 * © Copyright IBM Corp. 2012
 * 
 * Licensed 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.
 */

package com.ibm.commons.xml.drivers;

import java.io.InputStream;
import java.io.Reader;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSParser;
import org.w3c.dom.ls.LSParserFilter;
import org.w3c.dom.traversal.NodeFilter;

import com.ibm.commons.util.ObjectPool;
import com.ibm.commons.xml.XMLException;



/**
 * XERCES driver feturing DOM level 3.
 */
public class XercesDriverL3 extends AbstractXercesDriver {

    private DOMImplementationLS domImplementationLS;
    private ParserPool parserPool;

    private static class ParserPool extends ObjectPool {
        private DOMImplementationLS domImplementationLS;
        ParserPool(DOMImplementationLS domImplementationLS) {
            super(8); // Use a parameter here?
            this.domImplementationLS = domImplementationLS;
        }
        protected Object createObject() throws Exception {
            LSParser parser = domImplementationLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
            return parser;
        }
    }
    
    // Filter to ignore blanks
    private static class BlankFilter implements LSParserFilter {
        public short acceptNode(Node node) {
            if( node instanceof Text ) {
                Text t = (Text)node;
                String data = t.getData();
                int length = data.length();
                int first=0;
                for( ; first




© 2015 - 2025 Weber Informatics LLC | Privacy Policy