<commit_before>/* $Id$
 *
 * Copyright 2008 University of Edinburgh.
 * All Rights Reserved
 */
package uk.ac.ed.ph.snuggletex;

import uk.ac.ed.ph.snuggletex.definitions.Globals;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Properties;
import java.util.Map.Entry;

/**
 * Some handy utility methods for managing SnuggleTeX CSS.
 *
 * @author  <NAME>
 * @version $Revision$
 */
public class CSSUtilities {
    
    public static void writeStylesheet(DOMBuilderOptions options, OutputStream cssOutputStream) {
        /* First of all, see if custom CSS has been specified */
        Properties cssProperties = options.getInlineCSSProperties();
        if (cssProperties==null) {
            cssProperties = readBuiltinInlineCSSProperties();
        }
        writeStylesheet(cssProperties, cssOutputStream);
    }
    
    public static String writeDefaultStylesheet() {
        return writeStylesheet(readBuiltinInlineCSSProperties());
    }
    
    public static String writeStylesheet(Properties cssProperties) {
        StringWriter resultWriter = new StringWriter();
        writeStylesheet(cssProperties, resultWriter);
        return resultWriter.toString();
    }
    
    public static void writeDefaultStylesheet(OutputStream cssOutputStream) {
        writeStylesheet(readBuiltinInlineCSSProperties(), cssOutputStream);
    }
    
    public static void writeStylesheet(Properties cssProperties, OutputStream cssOutputStream) {
        writeStylesheet(cssProperties, new OutputStreamWriter(cssOutputStream));
    }
    
    public static void writeStylesheet(Properties cssProperties, Writer cssOutputWriter) {
        PrintWriter writer = new PrintWriter(new BufferedWriter(cssOutputWriter));
        writer.println("/* SnuggleTeX CSS File (autogenerated) */");
        String value;
        for (Entry<Object, Object> entry : cssProperties.entrySet()) {
            writer.print("\n");
            writer.print(entry.getKey()); /* element.class */
            writer.print(" {\n"); /* open '{' */
            value = ((String) entry.getValue()).trim();
            if (value.length()!=0) { /* CSS styles list */
                writer.print("  "); /* Opening tab */
                writer.print(value
                        .replaceFirst("(?!;)$", ";")         /* (Add trailing semi-colon for consistency) */
                        .replaceAll(";\\s*(?=.)", ";\n  ")); /* (Make multi-line) */
                writer.print("\n");
            }
            writer.print("}\n");
        }
        writer.close();
    }
    
    /**
     * Reads in the default CSS Properties file, which is packaged within SnuggleTeX itself.
     */
    public static Properties readBuiltinInlineCSSProperties() {
        Properties builtinInlineCSSProperties = new Properties();
        try {
            builtinInlineCSSProperties.load(CSSUtilities.class.getClassLoader().getResourceAsStream(Globals.CSS_PROPERTIES_NAME));
        }
        catch (IOException e) {
            throw new SnuggleRuntimeException("Could not load CSS properties file via ClassLoader " + Globals.CSS_PROPERTIES_NAME);
        }
        return builtinInlineCSSProperties;
    }
    
    public static Properties readInlineCSSProperties(DOMBuilderOptions options) {
        Properties properties = options.getInlineCSSProperties();
        if (properties==null) {
            properties = readBuiltinInlineCSSProperties();
        }
        return properties;
    }
    
    /**
     * Main method is used by the build process to write out the default CSS stylesheet.
     * 
     * @param args Array containing 1 argument: the File that the default CSS should be written to.
     * 
     * @throws FileNotFoundException 
     */
    public static void main(String[] args) throws IOException {
        if (args.length!=1) {
            System.err.println("Usage: specify a File that the default SnuggleTeX CSS will be written to");
        }
        writeDefaultStylesheet(new FileOutputStream(new File(args[0])));
    }
}<commit_msg>Fixed the main() method when insufficient arguments are passed<commit_after>/* $Id$
 *
 * Copyright 2008 University of Edinburgh.
 * All Rights Reserved
 */
package uk.ac.ed.ph.snuggletex;

import uk.ac.ed.ph.snuggletex.definitions.Globals;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Properties;
import java.util.Map.Entry;

/**
 * Some handy utility methods for managing SnuggleTeX CSS.
 *
 * @author  <NAME>
 * @version $Revision$
 */
public class CSSUtilities {
    
    public static void writeStylesheet(DOMBuilderOptions options, OutputStream cssOutputStream) {
        /* First of all, see if custom CSS has been specified */
        Properties cssProperties = options.getInlineCSSProperties();
        if (cssProperties==null) {
            cssProperties = readBuiltinInlineCSSProperties();
        }
        writeStylesheet(cssProperties, cssOutputStream);
    }
    
    public static String writeDefaultStylesheet() {
        return writeStylesheet(readBuiltinInlineCSSProperties());
    }
    
    public static String writeStylesheet(Properties cssProperties) {
        StringWriter resultWriter = new StringWriter();
        writeStylesheet(cssProperties, resultWriter);
        return resultWriter.toString();
    }
    
    public static void writeDefaultStylesheet(OutputStream cssOutputStream) {
        writeStylesheet(readBuiltinInlineCSSProperties(), cssOutputStream);
    }
    
    public static void writeStylesheet(Properties cssProperties, OutputStream cssOutputStream) {
        writeStylesheet(cssProperties, new OutputStreamWriter(cssOutputStream));
    }
    
    public static void writeStylesheet(Properties cssProperties, Writer cssOutputWriter) {
        PrintWriter writer = new PrintWriter(new BufferedWriter(cssOutputWriter));
        writer.println("/* SnuggleTeX CSS File (autogenerated) */");
        String value;
        for (Entry<Object, Object> entry : cssProperties.entrySet()) {
            writer.print("\n");
            writer.print(entry.getKey()); /* element.class */
            writer.print(" {\n"); /* open '{' */
            value = ((String) entry.getValue()).trim();
            if (value.length()!=0) { /* CSS styles list */
                writer.print("  "); /* Opening tab */
                writer.print(value
                        .replaceFirst("(?!;)$", ";")         /* (Add trailing semi-colon for consistency) */
                        .replaceAll(";\\s*(?=.)", ";\n  ")); /* (Make multi-line) */
                writer.print("\n");
            }
            writer.print("}\n");
        }
        writer.close();
    }
    
    /**
     * Reads in the default CSS Properties file, which is packaged within SnuggleTeX itself.
     */
    public static Properties readBuiltinInlineCSSProperties() {
        Properties builtinInlineCSSProperties = new Properties();
        try {
            builtinInlineCSSProperties.load(CSSUtilities.class.getClassLoader().getResourceAsStream(Globals.CSS_PROPERTIES_NAME));
        }
        catch (IOException e) {
            throw new SnuggleRuntimeException("Could not load CSS properties file via ClassLoader " + Globals.CSS_PROPERTIES_NAME);
        }
        return builtinInlineCSSProperties;
    }
    
    public static Properties readInlineCSSProperties(DOMBuilderOptions options) {
        Properties properties = options.getInlineCSSProperties();
        if (properties==null) {
            properties = readBuiltinInlineCSSProperties();
        }
        return properties;
    }
    
    /**
     * Main method is used by the build process to write out the default CSS stylesheet.
     * 
     * @param args Array containing 1 argument: the File that the default CSS should be written to.
     * 
     * @throws FileNotFoundException 
     */
    public static void main(String[] args) throws IOException {
        if (args.length!=1) {
            System.err.println("Usage: specify a File that the default SnuggleTeX CSS will be written to");
            System.exit(1);
        }
        writeDefaultStylesheet(new FileOutputStream(new File(args[0])));
    }
}
{'fraction_non_alphanumeric': 0.10198168965117627, 'fraction_numerical': 0.0019701008228068142, 'mean_word_length': 2.7538060026098305, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '665181', 'n_tokens_mistral': 2209, 'n_tokens_neox': 2216, 'n_words': 571}