<commit_before>/* -*- mode: Java; c-basic-offset: 2; -*- */

/**
 * Library output
 *
 * @author <EMAIL>
 *
 * Outputs schema and script for a library
 */

package org.openlaszlo.compiler;

import java.io.*;
import java.net.*;
import java.util.*;

import org.jdom.Element;

import org.openlaszlo.sc.ScriptCompiler;
import org.openlaszlo.sc.JavascriptCompressor;
import org.openlaszlo.utils.*;

import org.openlaszlo.iv.flash.util.FontsCollector;

/** Accumulates code, XML, and assets to a Library object file.
 *
 * Properties documented in Compiler.getProperties.
 */
class LibraryWriter extends SWFWriter {

  PrintStream out;
  protected PrintWriter scriptWriter = null;
  protected StringWriter scriptBuffer = null;
  Element root;

  LibraryWriter(Properties props, OutputStream stream,
                CompilerMediaCache cache,
                boolean importLibrary,
                CompilationEnvironment env) {
    super(props, stream, cache, importLibrary, env);
    this.scriptBuffer = new StringWriter();
    this.scriptWriter= new PrintWriter(scriptBuffer);
    try {
      this.out = new PrintStream(new java.util.zip.GZIPOutputStream(mStream));
    } catch (Exception e) {
      throw new ChainedException(e);
    }
  }


  /**
   * Sets the canvas for the app
   *
   * @param canvas
   *
   */
  // TODO: [[2007-01-30 ptw] This should become an error
  void setCanvas(Canvas canvas, String canvasConstructor) {
  }

  void setRoot(Element root) {
    this.root = root;
  }

  // TODO: [[2007-01-30 ptw] This should become an error
  void setCanvasDefaults(Canvas canvas, CompilerMediaCache mc) { };

  public int addScript(String script) {
    scriptWriter.println(script);
    return script.length();
  }

  private Map resourceMap = new LinkedHashMap();

    public void importResource(String fileName, String name)
        throws ImportResourceError
    {
        importResource(fileName, name, -1);
    }

    public void importResource(String fileName, String name, int frameNum)
        throws CompilationError
    {
        importResource(fileName, name, frameNum, null);
    }

    public String importResource(File file)
    {
      System.err.println("importResource: " + file.toString());
      String clipName = createName();
      importResource(file.getPath(), clipName);
      return clipName;
    }

    public String importClickResource(File file) throws ImportResourceError
    {
      System.err.println("importClickResource: " + file.toString());
      return importResource(file);
    }


  public void importResource(String fileName, String name, int frameNum, FontsCollector fontsCollector)
    throws ImportResourceError
    {
      resourceMap.put(name, fileName);
    }

    public void importResource(List sources, String name, File parent)
    {
        importResource(sources, name, parent, -1);
    }

    public void importResource(List sources, String name, File parent, int frameNum)
    {
        importResource(sources, name, parent, frameNum, null);
    }

  public void importResource(List sources, String name, File parent, int frameNum, FontsCollector fontsCollector)
    {
     resourceMap.put(name, sources);
    }

  private String adjustResourcePath(String src) {
    try {
      return new URL(src).toString();
    } catch (MalformedURLException e) {
      try {
        String outdir = mEnv.getObjectFile().getCanonicalFile().getParent();
        File file = new File(src).getCanonicalFile();
        return FileUtils.adjustRelativePath(file.getName(), outdir, file.getParent());
      } catch (IOException f) {<commit_msg>Change 20070223-ptw-9 by <EMAIL> on 2007-02-23 11:53:48 PST     in /Users/ptw/OpenLaszlo/3.4.1<commit_after>/* -*- mode: Java; c-basic-offset: 2; -*- */

/**
 * Library output
 *
 * @author <EMAIL>
 *
 * Outputs schema and script for a library
 */

package org.openlaszlo.compiler;

import java.io.*;
import java.net.*;
import java.util.*;

import org.jdom.Element;

import org.openlaszlo.sc.ScriptCompiler;
import org.openlaszlo.sc.JavascriptCompressor;
import org.openlaszlo.utils.*;

import org.openlaszlo.iv.flash.util.FontsCollector;

/** Accumulates code, XML, and assets to a Library object file.
 *
 * Properties documented in Compiler.getProperties.
 */
class LibraryWriter extends SWFWriter {

  PrintStream out;
  protected PrintWriter scriptWriter = null;
  protected StringWriter scriptBuffer = null;
  Element root;

  LibraryWriter(Properties props, OutputStream stream,
                CompilerMediaCache cache,
                boolean importLibrary,
                CompilationEnvironment env) {
    super(props, stream, cache, importLibrary, env);
    this.scriptBuffer = new StringWriter();
    this.scriptWriter= new PrintWriter(scriptBuffer);
    try {
      this.out = new PrintStream(new java.util.zip.GZIPOutputStream(mStream));
    } catch (Exception e) {
      throw new ChainedException(e);
    }
  }


  /**
   * Sets the canvas for the app
   *
   * @param canvas
   *
   */
  // TODO: [[2007-01-30 ptw] This should become an error
  void setCanvas(Canvas canvas, String canvasConstructor) {
  }

  void setRoot(Element root) {
    this.root = root;
  }

  // TODO: [[2007-01-30 ptw] This should become an error
  void setCanvasDefaults(Canvas canvas, CompilerMediaCache mc) { };

  public int addScript(String script) {
    scriptWriter.println(script);
    return script.length();
  }

  private Map resourceMap = new LinkedHashMap();

    public void importResource(String fileName, String name)
        throws ImportResourceError
    {
        importResource(fileName, name, -1);
    }

    public void importResource(String fileName, String name, int frameNum)
        throws CompilationError
    {
        importResource(fileName, name, frameNum, null);
    }

    public String importResource(File file)
    {
      System.err.println("importResource: " + file.toString());
      String clipName = createName();
      importResource(file.getPath(), clipName);
      return clipName;
    }

    public String importClickResource(File file) throws ImportResourceError
    {
      System.err.println("importClickResource: " + file.toString());
      return importResource(file);
    }


  public void importResource(String fileName, String name, int frameNum, FontsCollector fontsCollector)
    throws ImportResourceError
    {
      resourceMap.put(name, fileName);
    }

    public void importResource(List sources, String name, File parent)
    {
        importResource(sources, name, parent, -1);
    }

    public void importResource(List sources, String name, File parent, int frameNum)
    {
        importResource(sources, name, parent, frameNum, null);
    }

  public void importResource(List sources, String name, File parent, int frameNum, FontsCollector fontsCollector)
    {
     resourceMap.put(name, sources);
    }

  private String adjustResourcePath(String src) {
    try {
      return new URL(src).toString();
    } catch (MalformedURLException e) {
      try {
        String outdir = FileUtils.toURLPath(mEnv.getObjectFile().getCanonicalFile().getParentFile());
        File file = new File(src).getCanonicalFile();
        String fileURL = FileUtils.toURLPath(file);
        return FileUtils.adjustRelativePath(fileURL,
                                            outdir,
                                            FileUtils.toURLPath(file.getParentFile()));
      } catch (IOException f) {
{'fraction_non_alphanumeric': 0.10061877858488028, 'fraction_numerical': 0.008609093354856066, 'mean_word_length': 3.0851648351648353, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4823436', 'n_tokens_mistral': 2149, 'n_tokens_neox': 2069, 'n_words': 564}