gpt4 book ai didi

com.googlecode.htmlcompressor.compressor.YuiCssCompressor类的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 20:03:31 29 4
gpt4 key购买 nike

本文整理了Java中com.googlecode.htmlcompressor.compressor.YuiCssCompressor类的一些代码示例,展示了YuiCssCompressor类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YuiCssCompressor类的具体详情如下:
包路径:com.googlecode.htmlcompressor.compressor.YuiCssCompressor
类名称:YuiCssCompressor

YuiCssCompressor介绍

[英]Basic CSS compressor implementation using Yahoo YUI Compressor that could be used by HtmlCompressor for inline CSS compression.
[中]基本的CSS压缩器实现,使用Yahoo YUI Compressor,HtmlCompressor可以使用它进行内联CSS压缩。

代码示例

代码示例来源:origin: com.github.hazendaz/htmlcompressor

@Override
public boolean render(InternalContextAdapter context, Writer writer, Node node)
    throws IOException, MethodInvocationException {
  // render content
  StringWriter content = new StringWriter();
  node.jjtGetChild(0).render(context, content);
  // compress
  if (enabled) {
    try {
      YuiCssCompressor compressor = new YuiCssCompressor();
      compressor.setLineBreak(yuiCssLineBreak);
      String result = compressor.compress(content.toString());
      writer.write(result);
    } catch (Exception e) {
      writer.write(content.toString());
      String msg = "Failed to compress content: " + content.toString();
      log.error(msg, e);
      throw new RuntimeException(msg, e);
    }
  } else {
    writer.write(content.toString());
  }
  return true;
}

代码示例来源:origin: com.googlecode.htmlcompressor/htmlcompressor

protected String compressCssStyles(String source) {
  
  //set default css compressor
  if(cssCompressor == null) {
    YuiCssCompressor yuiCssCompressor = new YuiCssCompressor();
    yuiCssCompressor.setLineBreak(yuiCssLineBreak);
    
    cssCompressor = yuiCssCompressor;
  }
  
  //detect CDATA wrapper
  boolean cdataWrapper = false;
  Matcher matcher = cdataPattern.matcher(source);
  if(matcher.matches()) {
    cdataWrapper = true;
    source = matcher.group(1);
  }
  
  String result = cssCompressor.compress(source);
  
  if(cdataWrapper) {
    result = "<![CDATA[" + result + "]]>";
  } 
  return result;
  
}

代码示例来源:origin: com.github.hazendaz/htmlcompressor

/**
 * Compress css styles.
 *
 * @param source
 *            the source
 * @return the string
 */
protected String compressCssStyles(String source) {
  // set default css compressor
  if (cssCompressor == null) {
    YuiCssCompressor yuiCssCompressor = new YuiCssCompressor();
    yuiCssCompressor.setLineBreak(yuiCssLineBreak);
    cssCompressor = yuiCssCompressor;
  }
  // detect CDATA wrapper
  boolean cdataWrapper = false;
  Matcher matcher = cdataPattern.matcher(source);
  if (matcher.matches()) {
    cdataWrapper = true;
    source = matcher.group(1);
  }
  String result = cssCompressor.compress(source);
  if (cdataWrapper) {
    result = "<![CDATA[" + result + "]]>";
  }
  return result;
}

代码示例来源:origin: com.googlecode.htmlcompressor/htmlcompressor

public boolean render(InternalContextAdapter context, Writer writer, Node node) 
    throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
  
  //render content
  StringWriter content = new StringWriter();
  node.jjtGetChild(0).render(context, content);
  
  //compress
  if(enabled) {
    try {
      
      YuiCssCompressor compressor = new YuiCssCompressor();
      compressor.setLineBreak(yuiCssLineBreak);
      String result = compressor.compress(content.toString());
      
      writer.write(result);
    } catch (Exception e) {
      writer.write(content.toString());
      String msg = "Failed to compress content: "+content.toString();
      log.error(msg, e);
      throw new RuntimeException(msg, e);
      
    }
  } else {
    writer.write(content.toString());
  }
  
  return true;
  
}

代码示例来源:origin: com.googlecode.htmlcompressor/htmlcompressor

@Override
public int doEndTag() throws JspException {
  
  BodyContent bodyContent = getBodyContent();
  String content = bodyContent.getString();

  try {
    if(enabled) {
      //call YUICompressor
      YuiCssCompressor compressor = new YuiCssCompressor();
      compressor.setLineBreak(yuiCssLineBreak);
      String result = compressor.compress(content);
      bodyContent.clear();
      bodyContent.append(result);
      bodyContent.writeOut(pageContext.getOut());
    } else {
      bodyContent.clear();
      bodyContent.append(content);
      bodyContent.writeOut(pageContext.getOut());
    }
  } catch (IOException e) {
    e.printStackTrace();
  } catch (Exception e) {
    e.printStackTrace();
  }
  
  return super.doEndTag();
}

代码示例来源:origin: com.github.hazendaz/htmlcompressor

@Override
public int doEndTag() throws JspException {
  BodyContent bodyContent = getBodyContent();
  String content = bodyContent.getString();
  try {
    if (enabled) {
      // call YUICompressor
      YuiCssCompressor compressor = new YuiCssCompressor();
      compressor.setLineBreak(yuiCssLineBreak);
      String result = compressor.compress(content);
      bodyContent.clear();
      bodyContent.append(result);
      bodyContent.writeOut(pageContext.getOut());
    } else {
      bodyContent.clear();
      bodyContent.append(content);
      bodyContent.writeOut(pageContext.getOut());
    }
  } catch (IOException e) {
    logger.error("", e);
  }
  return super.doEndTag();
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com