<commit_before>package org.wyona.yanel.core.source;

import javax.xml.transform.Source;
import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamSource;

import org.apache.log4j.Category;
import org.wyona.yanel.core.Resource;


/**
 * Resolves URIs with scheme "http".
 * 
 * Syntax:
 * http:{path}
 * 
 * e.g.
 * http://foo/bar.xml
 * 
 */
public class HttpResolver implements URIResolver {

    private static Category log = Category.getInstance(HttpResolver.class);

    private static final String HTTP_SCHEME = "http";
    private static final String HTTPS_SCHEME = "https";
    
    //private Resource resource;
    
    public HttpResolver(Resource resource) {
        //this.resource = resource;
    }

    /**
     * @see javax.xml.transform.URIResolver#resolve(String, String)
     */
    public Source resolve(String href, String base) throws SourceException {
        String httpPrefix = HTTP_SCHEME + ":";
        String httpsPrefix = HTTPS_SCHEME + ":";
        
        // INFO: Only accept URIs which start either with 'http:' or 'https:'
        if (href != null && (href.startsWith(httpPrefix) || href.startsWith(httpsPrefix))){
            // INFO: href seems to start with the correct scheme
        } else {
            log.error("Href '" + href + "' does neither start with prefix '" + httpPrefix + "' nor with '" + httpsPrefix + "'!");
            return null;
        }

        try {
            java.net.URL url = new java.net.URL(href);
            if (log.isDebugEnabled()) log.debug("Resolve: " + url.toString());
            return new StreamSource(url.openConnection().getInputStream());
        } catch (Exception e) {
            String errorMsg = "Could not resolve URI: " + href + ": " + e.toString();
            log.error(errorMsg, e);
            throw new SourceException(errorMsg, e);
        }
    }
}<commit_msg>TODO about SSL support added<commit_after>package org.wyona.yanel.core.source;

import javax.xml.transform.Source;
import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamSource;

import org.apache.log4j.Category;
import org.wyona.yanel.core.Resource;


/**
 * Resolves URIs with scheme "http".
 * 
 * Syntax:
 * http:{path}
 * 
 * e.g.
 * http://foo/bar.xml
 * 
 */
public class HttpResolver implements URIResolver {

    private static Category log = Category.getInstance(HttpResolver.class);

    private static final String HTTP_SCHEME = "http";
    private static final String HTTPS_SCHEME = "https";
    
    //private Resource resource;
    
    public HttpResolver(Resource resource) {
        //this.resource = resource;
    }

    /**
     * @see javax.xml.transform.URIResolver#resolve(String, String)
     */
    public Source resolve(String href, String base) throws SourceException {
        String httpPrefix = HTTP_SCHEME + ":";
        String httpsPrefix = HTTPS_SCHEME + ":";
        
        // INFO: Only accept URIs which start either with 'http:' or 'https:'
        if (href != null && (href.startsWith(httpPrefix) || href.startsWith(httpsPrefix))){
            // INFO: href seems to start with the correct scheme
        } else {
            log.error("Href '" + href + "' does neither start with prefix '" + httpPrefix + "' nor with '" + httpsPrefix + "'!");
            return null;
        }

        try {
            java.net.URL url = new java.net.URL(href);
            if (log.isDebugEnabled()) log.debug("Resolve: " + url.toString());
            // TODO: Support SSL ...
            return new StreamSource(url.openConnection().getInputStream());
        } catch (Exception e) {
            String errorMsg = "Could not resolve URI: " + href + ": " + e.toString();
            log.error(errorMsg, e);
            throw new SourceException(errorMsg, e);
        }
    }
}
{'fraction_non_alphanumeric': 0.1255911718339464, 'fraction_numerical': 0.0005254860746190226, 'mean_word_length': 2.4958677685950414, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6645264', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1060, 'n_words': 279}