<commit_before>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2001-06 The eXist Project
 *  http://exist-db.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  $Id$
 */

package org.exist.validation.resolver;

import java.io.IOException;

import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;

import org.apache.log4j.Logger;
import org.apache.xml.resolver.Catalog;
import org.apache.xml.resolver.CatalogManager;
import org.apache.xml.resolver.tools.CatalogResolver;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
 *   Shared CatalogResolver to be used by the eXist database and the eXist
 * Cocoon web interface. The configuration must be initialized once, typically
 * performed by the database (Configuration class). Consequently the Cocoon
 * interface can reuse the resolver.
 *
 * This resolver guarantees that only one apache.org catalog resolver is being
 * initialized. At this moment the class is just a thin wrapper. To be changed
 * in the near future: Grammar and catalog files can all be stored in the
 * database itself.
 *
 * @see <a href="http://xml.apache.org/commons/components/resolver/"
 *                                                      >Apache.org resolver</a>
 * @see <a href="http://xml.apache.org/commons/components/resolver/resolver-article.html"
 *                                             >XML Entity and URI Resolvers</a>
 *
 * @author <NAME>
 */
public class eXistCatalogResolver implements org.xml.sax.EntityResolver,
        javax.xml.transform.URIResolver {
    
    private final static Logger logger = Logger.getLogger(eXistCatalogResolver.class);
    private static CatalogResolver catalogResolver = null;
    
    
    /** Constructor. */
    public eXistCatalogResolver() {
        logger.debug("Initializing eXistCatalogResolver");
        System.out.println("Initializing eXistCatalogResolver");
        if(catalogResolver==null){
            catalogResolver = new CatalogResolver();
        }
    }
    
    /**
     * Constructor.
     *
     * @param privateCatalog  TRUE for private catalog, FALSE if not.
     */
    public eXistCatalogResolver(boolean privateCatalog) {
        logger.debug("Initializing eXistCatalogResolver, privateCatalog="+privateCatalog);
        System.out.println("Initializing eXistCatalogResolver, privateCatalog="+privateCatalog);
        if(catalogResolver==null){
            catalogResolver = new CatalogResolver();
        }
    }
    
    /**
     * Constructor.
     *
     * @param manager Specific catalogmanager to use.
     */
    public eXistCatalogResolver(CatalogManager manager) {
        logger.debug("Initializing eXistCatalogResolver, with manager.");
        System.out.println("Initializing eXistCatalogResolver, with manager.");
        if(catalogResolver==null){
            catalogResolver = new CatalogResolver(manager);
        }
    }
    
    
    /**
     *  Return the underlying catalog
     * @return catalog object.
     */
    public Catalog getCatalog() {
        logger.debug("Getting catalog from eXistCatalogResolver.");
        System.out.println("Getting catalog from eXistCatalogResolver.");
        
        Catalog catalog = catalogResolver.getCatalog();
        return catalog;
    }
    
    /**
     *  Resolve grammar specified by publicId and/or systemId.
     *
     * @see  org.xml.sax.EntityResolver#resolveEntity  resolveEntity
     *
     * @param  publicId  The public identifier of the external entity being
     *                   referenced, or null if none was supplied.
     * @param  systemId  The system identifier of the external entity being
     *                   referenced.
     * @throws SAXException     Any SAX exception, possibly wrapping another
     *                          exception.
     * @throws IOException      A Java-specific IO exception, possibly the
     *                          result of creating a new InputStream or Reader
     *                          for the InputSource.
     * @return An InputSource object describing the new input source, or null
     *         to request that the parser open a regular URI connection to the
     *         system identifier.
     */
    public InputSource resolveEntity(String publicId, String systemId)  
                                              throws SAXException, IOException {
        
        logger.debug("resolveEntity( publicId='" +publicId + "', systemId='"+systemId+"').");
        InputSource inputsource =catalogResolver.resolveEntity(publicId, systemId);
        
        logger.debug("resolved publicId='"+inputsource.getPublicId()
        + "' systemId='"+inputsource.getSystemId()+"'.");
        return inputsource;
    }
    
    
    /**
     *  An object that implements this interface that can be called by the
     * processor to turn a URI used in document(), xsl:import, or xsl:include
     * into a Source object.
     *
     * @see javax.xml.transform.URIResolver#resolve resolve
     *
     * @param  href  An href attribute, which may be relative or absolute.
     * @param  base  The base URI in effect when the href attribute was
     *               encountered.
     * @throws TransformerException  if an error occurs when trying to resolve
     *                               the URI.
     * @return A Source object, or null if the href cannot be resolved, and the
     *         processor should try to resolve the URI itself.
     */
    public Source resolve(String href, String base) throws TransformerException {
        logger.debug("resolve( href='" +href + "', base='"+base+"').");
        Source source= catalogResolver.resolve(href, base);
        
        logger.debug("systemId="+source.getSystemId());
        
        return source;
    }
}
<commit_msg>second try, right address ?<commit_after>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2001-06 The eXist Project
 *  http://exist-db.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software Foundation, Inc.
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 *  $Id$
 */

package org.exist.validation.resolver;

import java.io.IOException;

import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;

import org.apache.log4j.Logger;
import org.apache.xml.resolver.Catalog;
import org.apache.xml.resolver.CatalogManager;
import org.apache.xml.resolver.tools.CatalogResolver;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
 *   Shared CatalogResolver to be used by the eXist database and the eXist
 * Cocoon web interface. The configuration must be initialized once, typically
 * performed by the database (Configuration class). Consequently the Cocoon
 * interface can reuse the resolver.
 *
 * This resolver guarantees that only one apache.org catalog resolver is being
 * initialized. At this moment the class is just a thin wrapper. To be changed
 * in the near future: Grammar and catalog files can all be stored in the
 * database itself.
 *
 * @see <a href="http://xml.apache.org/commons/components/resolver/"
 *                                                      >Apache.org resolver</a>
 * @see <a href="http://xml.apache.org/commons/components/resolver/resolver-article.html"
 *                                             >XML Entity and URI Resolvers</a>
 *
 * @author Dannes Wessels
 */
public class eXistCatalogResolver implements org.xml.sax.EntityResolver,
        javax.xml.transform.URIResolver {
    
    private final static Logger logger = Logger.getLogger(eXistCatalogResolver.class);
    private static CatalogResolver catalogResolver = null;
    
    
    /** Constructor. */
    public eXistCatalogResolver() {
        logger.debug("Initializing eXistCatalogResolver");
        System.out.println("Initializing eXistCatalogResolver");
        if(catalogResolver==null){
            catalogResolver = new CatalogResolver();
        }
    }
    
    /**
     * Constructor.
     *
     * @param privateCatalog  TRUE for private catalog, FALSE if not.
     */
    public eXistCatalogResolver(boolean privateCatalog) {
        logger.debug("Initializing eXistCatalogResolver, privateCatalog="+privateCatalog);
        System.out.println("Initializing eXistCatalogResolver, privateCatalog="+privateCatalog);
        if(catalogResolver==null){
            catalogResolver = new CatalogResolver();
        }
    }
    
    /**
     * Constructor.
     *
     * @param manager Specific catalogmanager to use.
     */
    public eXistCatalogResolver(CatalogManager manager) {
        logger.debug("Initializing eXistCatalogResolver, with manager.");
        System.out.println("Initializing eXistCatalogResolver, with manager.");
        if(catalogResolver==null){
            catalogResolver = new CatalogResolver(manager);
        }
    }
    
    
    /**
     *  Return the underlying catalog
     * @return catalog object.
     */
    public Catalog getCatalog() {
        logger.debug("Getting catalog from eXistCatalogResolver.");
        System.out.println("Getting catalog from eXistCatalogResolver.");
        
        Catalog catalog = catalogResolver.getCatalog();
        return catalog;
    }
    
    /**
     *  Resolve grammar specified by publicId and/or systemId.
     *
     * @see  org.xml.sax.EntityResolver#resolveEntity  resolveEntity
     *
     * @param  publicId  The public identifier of the external entity being
     *                   referenced, or null if none was supplied.
     * @param  systemId  The system identifier of the external entity being
     *                   referenced.
     * @throws SAXException     Any SAX exception, possibly wrapping another
     *                          exception.
     * @throws IOException      A Java-specific IO exception, possibly the
     *                          result of creating a new InputStream or Reader
     *                          for the InputSource.
     * @return An InputSource object describing the new input source, or null
     *         to request that the parser open a regular URI connection to the
     *         system identifier.
     */
    public InputSource resolveEntity(String publicId, String systemId)  
                                              throws SAXException, IOException {
        
        logger.debug("resolveEntity( publicId='" +publicId + "', systemId='"+systemId+"').");
        InputSource inputsource =catalogResolver.resolveEntity(publicId, systemId);
        
        logger.debug("resolved publicId='"+inputsource.getPublicId()
        + "' systemId='"+inputsource.getSystemId()+"'.");
        return inputsource;
    }
    
    
    /**
     *  An object that implements this interface that can be called by the
     * processor to turn a URI used in document(), xsl:import, or xsl:include
     * into a Source object.
     *
     * @see javax.xml.transform.URIResolver#resolve resolve
     *
     * @param  href  An href attribute, which may be relative or absolute.
     * @param  base  The base URI in effect when the href attribute was
     *               encountered.
     * @throws TransformerException  if an error occurs when trying to resolve
     *                               the URI.
     * @return A Source object, or null if the href cannot be resolved, and the
     *         processor should try to resolve the URI itself.
     */
    public Source resolve(String href, String base) throws TransformerException {
        logger.debug("resolve( href='" +href + "', base='"+base+"').");
        Source source= catalogResolver.resolve(href, base);
        
        logger.debug("systemId="+source.getSystemId());
        
        return source;
    }
}

{'fraction_non_alphanumeric': 0.08297677261613692, 'fraction_numerical': 0.0026742053789731053, 'mean_word_length': 2.4978621058257615, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '529844', 'n_tokens_mistral': 3321, 'n_tokens_neox': 3318, 'n_words': 1127}