org.tizen.web.compressor.beautifier.core_2.0.0.201311011708

16:50:35.925 INFO  jd.cli.Main - Decompiling org.tizen.web.compressor.beautifier.core_2.0.0.201311011708.jar
package org.tizen.web.compressor.beautifier.core;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Set;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tizen.common.util.FileUtil;
import org.tizen.common.util.FilenameUtil;
import org.tizen.common.util.IOUtil;

public abstract class AbstractBeautifier
  implements IBeautifier
{
  protected final Logger logger = LoggerFactory.getLogger(getClass());
  protected final Set<String> extensions;
  protected final Context context;
  protected final Scriptable scope;
  protected final String executable;
  protected final String beautifier;
  
  public AbstractBeautifier(String[] extensions, String beautifier, String executable)
  {
    this.extensions = new HashSet();
    this.beautifier = beautifier;
    this.executable = executable;
    context = Context.enter();
    context.setLanguageVersion(160);
    scope = context.initStandardObjects();
    String[] arrayOfString;
    int j = (arrayOfString = extensions).length;
    for (int i = 0; i < j; i++)
    {
      String ext = arrayOfString[i];
      this.extensions.add(ext.toLowerCase());
    }
    context.evaluateString(scope, getBeautifier(), "beautifier", 1, null);
  }
  
  protected static String load(String name)
    throws IOException
  {
    ClassLoader cl = AbstractBeautifier.class.getClassLoader();
    String path = FilenameUtil.addTailingPath(AbstractBeautifier.class.getPackage().getName().replace('.', '/'), name);
    InputStream in = cl.getResourceAsStream(path);
    return IOUtil.getString(in, true);
  }
  
  protected Set<String> getExtensions()
  {
    return extensions;
  }
  
  protected String getBeautifier()
  {
    return beautifier;
  }
  
  protected String getExecutableCode()
  {
    return executable;
  }
  
  public boolean canHandle(String name)
  {
    logger.trace("Name: {}", name);
    String fileExt = FileUtil.getFileExtension(name);
    logger.trace("Extension: {}", fileExt);
    if (fileExt == null)
    {
      logger.debug("No extension");
      return false;
    }
    fileExt = fileExt.toLowerCase();
    
    Set<String> exts = getExtensions();
    logger.debug("Extension candidate: {}", exts);
    return exts.contains(fileExt);
  }
  
  public void decompress(InputStream source, OutputStream target)
    throws IOException
  {
    scope.put("contents", scope, IOUtil.getString(source));
    context.evaluateString(scope, getExecutableCode(), "beautifier", 1, null);
    
    Object result = scope.get("result", scope);
    if (result == null) {
      throw new IOException("Invalid result");
    }
    target.write(result.toString().getBytes());
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.compressor.beautifier.core.AbstractBeautifier
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.compressor.beautifier.core;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tizen.common.util.IOUtil;

public class Beautifier
{
  protected final Logger logger = LoggerFactory.getLogger(getClass());
  protected final Set<IBeautifier> beautifiers = new HashSet();
  
  public boolean canHandle(String name)
  {
    logger.debug("Name: {}, Beautifiers: {}", name, beautifiers);
    for (IBeautifier beautifier : beautifiers) {
      if (beautifier.canHandle(name)) {
        return true;
      }
    }
    return false;
  }
  
  public void addBeautifier(IBeautifier beautifier)
  {
    beautifiers.add(beautifier);
  }
  
  public void decompress(String name, InputStream in, OutputStream out)
    throws Exception
  {
    boolean bProcess = false;
    byte[] bytes = IOUtil.getBytes(in, true);
    logger.debug("Beautifiers: {}", beautifiers);
    for (IBeautifier beautifier : beautifiers)
    {
      logger.trace("Beautifier: {}", beautifier);
      if (beautifier.canHandle(name))
      {
        ByteArrayInputStream byteIn = new ByteArrayInputStream(bytes);
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        beautifier.decompress(byteIn, byteOut);
        bytes = byteOut.toByteArray();
        bProcess = true;
      }
    }
    if (!bProcess) {
      throw new Exception(name + " is not supported file.");
    }
    if (out != null) {
      out.write(bytes);
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.compressor.beautifier.core.Beautifier
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.compressor.beautifier.core;

import java.io.IOException;

public class CSSBeautifier
  extends AbstractBeautifier
{
  protected static final String CSS_BEAUTIFY_FILE = "beautify-css.js";
  protected static final String[] CSS_FILE_EXTENSIONS = { "css" };
  
  public CSSBeautifier()
    throws IOException
  {
    super(CSS_FILE_EXTENSIONS, load("beautify-css.js"), "result = _css_beautify(contents);");
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.compressor.beautifier.core.CSSBeautifier
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.compressor.beautifier.core;

import java.io.IOException;

public class HTMLBeautifier
  extends AbstractBeautifier
{
  protected static final String[] HTML_FILE_EXTENSIONS = { "html", "htm" };
  protected static final String HTML_BEAUTIFY_FILE = "beautify-html.js";
  
  public HTMLBeautifier()
    throws IOException
  {
    super(HTML_FILE_EXTENSIONS, load("beautify-html.js"), "result = _html_beautify(contents);");
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.compressor.beautifier.core.HTMLBeautifier
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.compressor.beautifier.core;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public abstract interface IBeautifier
{
  public abstract boolean canHandle(String paramString);
  
  public abstract void decompress(InputStream paramInputStream, OutputStream paramOutputStream)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.tizen.web.compressor.beautifier.core.IBeautifier
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.web.compressor.beautifier.core;

import java.io.IOException;

public class JavaScriptBeautifier
  extends AbstractBeautifier
{
  protected static final String JS_BEAUTIFY_FILE = "beautify.js";
  protected static final String[] JS_FILE_EXTENSIONS = { "js" };
  
  public JavaScriptBeautifier()
    throws IOException
  {
    super(JS_FILE_EXTENSIONS, load("beautify.js"), "result = _js_beautify(contents);");
  }
}

/* Location:
 * Qualified Name:     org.tizen.web.compressor.beautifier.core.JavaScriptBeautifier
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd