<commit_before>/*************************************************************************
 *
 *  $RCSfile: utils.java,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change:$Date: 2005-02-02 14:00:36 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

package util;

import java.lang.System;
import java.util.StringTokenizer;
import java.io.*;
import java.util.ArrayList;
import java.io.RandomAccessFile;
import java.net.Socket;
import java.net.ServerSocket;

import com.sun.star.container.XNameAccess;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.Property;
import com.sun.star.beans.PropertyAttribute;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.ucb.XSimpleFileAccess;
import com.sun.star.lang.XServiceInfo;

import com.sun.star.util.URL;
import com.sun.star.util.XURLTransformer;

import com.sun.star.uno.Any;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XMacroExpander;

import java.util.Collections;

public class utils {

    /**
     *
     * This method adds the DOCPTH to a given file
     *
     */
    public static String getFullTestDocName( String sDocName ) {
        String docpth = System.getProperty("DOCPTH");
        if (docpth.endsWith("\\") || docpth.endsWith("/"))
            docpth = docpth.substring(0, docpth.length() - 1) ;

        if (docpth.startsWith("http:")) {
            return docpth+"/"+sDocName;
        }
        String testdocPth = "";
        String pthSep = System.getProperty("file.separator");
        if (docpth == null ) {
            String objdscPth = System.getProperty("OBJDSCS");
            int i = objdscPth.indexOf("objdsc");
            String arcPth = objdscPth.substring(0,i-1);
            testdocPth = arcPth + pthSep + "doc" + pthSep + "java" +
                            pthSep + "testdocs" + pthSep + sDocName;
        }
        else {
            testdocPth = docpth + pthSep + sDocName;
        }
        return testdocPth;
    }

    /**
     *
     * This method adds the DOCPTH to a given file
     * and changes the format to an file URL
     *
     */

    public static String getFullTestURL( String sDocName ) {
        String fullDocPath = getFullTestDocName(sDocName);
        if (fullDocPath.startsWith("http:")) {
            return fullDocPath;
        }
        if (fullDocPath.startsWith("file:")) {
            return fullDocPath;
        }
        String prefix = null;

        //  Windows: \\\\margritte\\qaapi\\workspace\\qadev\\testdocs/emptyChart.sds
        if (fullDocPath.startsWith("\\\\"))
        prefix = "file:";

        fullDocPath = fullDocPath.replace('\\','/');
        if (prefix == null){
            if (fullDocPath.startsWith("//"))
                prefix="file:/";
            else if (fullDocPath.startsWith("/"))
                prefix="file://";
            else
                prefix="file:///";
        }
        if (!fullDocPath.endsWith("/")) {
            File aFile = new File(fullDocPath);
            if (aFile.isDirectory()) {
                fullDocPath +="/";
            }
        }
        String fulldocURL = prefix+fullDocPath;
        return fulldocURL;
   }

   /**
    *
    * This method changes a given URL to a valid file URL
    *
    */

   public static String getFullURL( String sDocName ) {
        String fullDocPath = sDocName;
//        System.out.println("##### getFullURL (in): "+sDocName);
        if (fullDocPath.startsWith("http:")) {
            return fullDocPath;
        }
        if (fullDocPath.startsWith("file:")) {
            return fullDocPath;
        }
        if (fullDocPath.startsWith("ftp:")) {
            return fullDocPath;
        }
        fullDocPath = fullDocPath.replace('\\','/');
        String prefix = "";
        if (fullDocPath.startsWith("//")) {
            prefix="file:";
        } else {
            if (fullDocPath.startsWith("/")) prefix="file://";
                                    else prefix="file:///";
        }

        if (!fullDocPath.endsWith("/")) {
            File aFile = new File(fullDocPath);
            if (aFile.isDirectory()) {
                fullDocPath +="/";
            }
        }
        String fulldocURL = prefix+fullDocPath;
//        System.out.println("##### getFullURL (out): "+fulldocURL);
        return fulldocURL;
    }

    /**
     *
     * This method creates folders needed
     *
     */


    public static void make_Directories(String first, String path) {
        String already_done = null;
        String fs = System.getProperty("file.separator");
        StringTokenizer path_tokenizer = new StringTokenizer(path,fs,false);
        already_done = first;
        while (path_tokenizer.hasMoreTokens()) {
            String part = path_tokenizer.nextToken();
            File new_dir = new File(already_done + File.separatorChar + part);
            already_done = new_dir.toString();
            //create the directory
            new_dir.mkdirs();
        }<commit_msg>INTEGRATION: CWS qadev21 (1.8.4); FILE MERGED 2005/01/11 16:39:07 cn 1.8.4.1: bugfix in getFullURL()<commit_after>/*************************************************************************
 *
 *  $RCSfile: utils.java,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change:$Date: 2005-02-24 17:23:20 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

package util;

import java.lang.System;
import java.util.StringTokenizer;
import java.io.*;
import java.util.ArrayList;
import java.io.RandomAccessFile;
import java.net.Socket;
import java.net.ServerSocket;

import com.sun.star.container.XNameAccess;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.Property;
import com.sun.star.beans.PropertyAttribute;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.ucb.XSimpleFileAccess;
import com.sun.star.lang.XServiceInfo;

import com.sun.star.util.URL;
import com.sun.star.util.XURLTransformer;

import com.sun.star.uno.Any;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XMacroExpander;

import java.util.Collections;

public class utils {

    /**
     *
     * This method adds the DOCPTH to a given file
     *
     */
    public static String getFullTestDocName( String sDocName ) {
        String docpth = System.getProperty("DOCPTH");
        if (docpth.endsWith("\\") || docpth.endsWith("/"))
            docpth = docpth.substring(0, docpth.length() - 1) ;

        if (docpth.startsWith("http:")) {
            return docpth+"/"+sDocName;
        }
        String testdocPth = "";
        String pthSep = System.getProperty("file.separator");
        if (docpth == null ) {
            String objdscPth = System.getProperty("OBJDSCS");
            int i = objdscPth.indexOf("objdsc");
            String arcPth = objdscPth.substring(0,i-1);
            testdocPth = arcPth + pthSep + "doc" + pthSep + "java" +
                            pthSep + "testdocs" + pthSep + sDocName;
        }
        else {
            testdocPth = docpth + pthSep + sDocName;
        }
        return testdocPth;
    }

    /**
     *
     * This method adds the DOCPTH to a given file
     * and changes the format to an file URL
     *
     */

    public static String getFullTestURL( String sDocName ) {
        String fullDocPath = getFullTestDocName(sDocName);
        if (fullDocPath.startsWith("http:")) {
            return fullDocPath;
        }
        if (fullDocPath.startsWith("file:")) {
            return fullDocPath;
        }
        String prefix = null;

        //  Windows: \\\\margritte\\qaapi\\workspace\\qadev\\testdocs/emptyChart.sds
        if (fullDocPath.startsWith("\\\\"))
        prefix = "file:";

        fullDocPath = fullDocPath.replace('\\','/');
        if (prefix == null){
            if (fullDocPath.startsWith("//"))
                prefix="file:/";
            else if (fullDocPath.startsWith("/"))
                prefix="file://";
            else
                prefix="file:///";
        }
        if (!fullDocPath.endsWith("/")) {
            File aFile = new File(fullDocPath);
            if (aFile.isDirectory()) {
                fullDocPath +="/";
            }
        }
        String fulldocURL = prefix+fullDocPath;
        return fulldocURL;
   }

   /**
    *
    * This method changes a given URL to a valid file URL
    *
    */

   public static String getFullURL( String sDocName ) {
        String fullDocPath = sDocName;
        fullDocPath = fullDocPath.replace('\\','/');

        if (fullDocPath.startsWith("http:")) {
            return fullDocPath;
        }
        if (fullDocPath.startsWith("ftp:")) {
            return fullDocPath;
        }
        String prefix = "";
        if (! fullDocPath.startsWith("file:///")){
            if (fullDocPath.startsWith("//")) {
                prefix="file:";
            } else {
                if (fullDocPath.startsWith("/")) prefix="file://";
                                        else prefix="file:///";
            }
        }
        if (!fullDocPath.endsWith("/")) {
            File aFile = new File(fullDocPath);
            if (aFile.isDirectory()) {
                fullDocPath +="/";
            }
        }
        String fulldocURL = prefix+fullDocPath;

        return fulldocURL;
    }

    /**
     *
     * This method creates folders needed
     *
     */


    public static void make_Directories(String first, String path) {
        String already_done = null;
        String fs = System.getProperty("file.separator");
        StringTokenizer path_tokenizer = new StringTokenizer(path,fs,false);
        already_done = first;
        while (path_tokenizer.hasMoreTokens()) {
            String part = path_tokenizer.nextToken();
            File new_dir = new File(already_done + File.separatorChar + part);
            already_done = new_dir.toString();
            //create the directory
            new_dir.mkdirs();
        }
{'fraction_non_alphanumeric': 0.13833310335311164, 'fraction_numerical': 0.010763074375603698, 'mean_word_length': 2.4009854528390426, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3807147', 'n_tokens_mistral': 4273, 'n_tokens_neox': 4090, 'n_words': 1180}