<commit_before>//$HeadURL: svn+ssh://lbuesching@svn.wald.intevation.de/deegree/base/trunk/resources/eclipse/files_template.xml $
/*----------------------------------------------------------------------------
 This file is part of deegree, http://deegree.org/
 Copyright (C) 2001-2010 by:
 - Department of Geography, University of Bonn -
 and
 - lat/lon GmbH -

 This library 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.1 of the License, or (at your option)
 any later version.
 This library 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 library; if not, write to the Free Software Foundation, Inc.,
 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

 Contact information:

 lat/lon GmbH
 Aennchenstr. 19, 53177 Bonn
 Germany
 http://lat-lon.de/

 Department of Geography, University of Bonn
 Prof. Dr. Klaus Greve
 Postfach 1147, 53001 Bonn
 Germany
 http://www.geographie.uni-bonn.de/deegree/

 e-mail: <EMAIL>
 ----------------------------------------------------------------------------*/
package org.deegree.client.core.utils;

import static org.slf4j.LoggerFactory.getLogger;

import java.net.MalformedURLException;
import java.net.URL;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import org.slf4j.Logger;

/**
 * TODO add class documentation here
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author last edited by: $Author: lyn $
 * 
 * @version $Revision: $, $Date: $
 */
public class FacesUtils {

    private static final Logger LOG = getLogger( FacesUtils.class );

    /**
     * @param target
     * @param fileName
     * @return
     */
    public static String getAbsolutePath( String target, String fileName ) {
        if ( target == null ) {
            target = "";
        }
        if ( !target.endsWith( "/" ) ) {
            target += "/";
        }
        return FacesContext.getCurrentInstance().getExternalContext().getRealPath( target + fileName );
    }

    /**
     * @param target
     *            the name of an existing directory in the webapps directory, if null the webapps directory will is the
     *            target
     * @param fileName
     *            the name of the file
     * @return the current URL extended with the target and fileName, or null if an error occurred. Example:
     *         http://localhost:8080/context/target/fileName
     */
    public static URL getWebAccessibleUrl( String target, String fileName )
                            throws MalformedURLException {
        try {
            if ( target == null ) {
                target = "";
            }
            if ( !target.endsWith( "/" ) ) {
                target += "/";
            }
            return new URL( getServerURL() + target + fileName );
        } catch ( MalformedURLException e ) {
            LOG.debug( "Constructing the url was a problem..." );
            LOG.trace( "Stack trace:", e );
        }
        return null;
    }

    /**
     * @return the current URL, or null if an error occurred. Example: http://localhost:8080/context/
     */
    public static String getServerURL() {
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        URL url;
        try {<commit_msg>avoid duplicated slash<commit_after>//$HeadURL: svn+ssh://lbuesching@svn.wald.intevation.de/deegree/base/trunk/resources/eclipse/files_template.xml $
/*----------------------------------------------------------------------------
 This file is part of deegree, http://deegree.org/
 Copyright (C) 2001-2010 by:
 - Department of Geography, University of Bonn -
 and
 - lat/lon GmbH -

 This library 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.1 of the License, or (at your option)
 any later version.
 This library 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 library; if not, write to the Free Software Foundation, Inc.,
 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

 Contact information:

 lat/lon GmbH
 Aennchenstr. 19, 53177 Bonn
 Germany
 http://lat-lon.de/

 Department of Geography, University of Bonn
 Prof. Dr. <NAME>
 Postfach 1147, 53001 Bonn
 Germany
 http://www.geographie.uni-bonn.de/deegree/

 e-mail: <EMAIL>
 ----------------------------------------------------------------------------*/
package org.deegree.client.core.utils;

import static org.slf4j.LoggerFactory.getLogger;

import java.net.MalformedURLException;
import java.net.URL;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import org.slf4j.Logger;

/**
 * TODO add class documentation here
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author last edited by: $Author: lyn $
 * 
 * @version $Revision: $, $Date: $
 */
public class FacesUtils {

    private static final Logger LOG = getLogger( FacesUtils.class );

    /**
     * @param target
     * @param fileName
     * @return
     */
    public static String getAbsolutePath( String target, String fileName ) {
        if ( target == null ) {
            target = "";
        }
        if ( !target.endsWith( "/" ) ) {
            target += "/";
        }
        return FacesContext.getCurrentInstance().getExternalContext().getRealPath( target + fileName );
    }

    /**
     * @param target
     *            the name of an existing directory in the webapps directory, if null the webapps directory will is the
     *            target
     * @param fileName
     *            the name of the file
     * @return the current URL extended with the target and fileName, or null if an error occurred. Example:
     *         http://localhost:8080/context/target/fileName
     */
    public static URL getWebAccessibleUrl( String target, String fileName )
                            throws MalformedURLException {
        try {
            if ( target == null ) {
                target = "";
            } else if ( !target.endsWith( "/" ) ) {
                target += "/";
            }
            return new URL( getServerURL() + target + fileName );
        } catch ( MalformedURLException e ) {
            LOG.debug( "Constructing the url was a problem..." );
            LOG.trace( "Stack trace:", e );
        }
        return null;
    }

    /**
     * @return the current URL, or null if an error occurred. Example: http://localhost:8080/context/
     */
    public static String getServerURL() {
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        URL url;
        try {
{'fraction_non_alphanumeric': 0.13379215416379903, 'fraction_numerical': 0.013764624913971095, 'mean_word_length': 2.1715408118725446, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 2, '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': '5048411', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1878, 'n_words': 682}