简体   繁体   English

Scalate模板大小限制为64k?

[英]Is scalate template size limited to 64k?

Trying to include bunch of HTML is a SSP template, I've got the following exception: 试图包含一堆HTML是一个SSP模板,我有以下异常:

Caused by: java.lang.IllegalArgumentException: null
at scala.tools.asm.ByteVector.putUTF8(ByteVector.java:213)
at scala.tools.asm.ClassWriter.newUTF8(ClassWriter.java:1092)
at scala.tools.asm.ClassWriter.newString(ClassWriter.java:1525)
at scala.tools.asm.ClassWriter.newConstItem(ClassWriter.java:1042)
at scala.tools.asm.MethodWriter.visitLdcInsn(MethodWriter.java:1134)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genConstant(GenASM.scala:1582)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.scala$tools$nsc$backend$jvm$GenASM$JPlainBuilder$$genInstr$1(GenASM.scala:2296)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$$anonfun$genBlock$1$2.apply(GenASM.scala:2227)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$$anonfun$genBlock$1$2.apply(GenASM.scala:2213)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
at scala.tools.nsc.backend.icode.BasicBlocks$BasicBlock.foreach(BasicBlocks.scala:195)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genBlock$1(GenASM.scala:2213)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genBlocks$1(GenASM.scala:2151)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genCode(GenASM.scala:2746)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genMethod(GenASM.scala:1471)
at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder.genClass(GenASM.scala:1341)
at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.emitFor$1(GenASM.scala:198)
at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.run(GenASM.scala:204)
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1501)
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1486)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:1481)
at scala.tools.nsc.Global$Run.compile(Global.scala:1582)
at org.fusesource.scalate.support.ScalaCompiler.compile(ScalaCompiler.scala:100)
at org.fusesource.scalate.TemplateEngine.compileAndLoad(TemplateEngine.scala:757)

Looking at scala.tools.asm.ByteVector I've found the following: 看看scala.tools.asm.ByteVector我发现了以下内容:

    public ByteVector putUTF8(String s) {
    int charLength = s.length();
    if(charLength > '\uffff') {
        throw new IllegalArgumentException();
    } else { ....

If template size is more than 65536 bytes, it fails to compile this template. 如果模板大小超过65536字节,则无法编译此模板。 What one has to do to include large piece of plain HTML into a SSP template? 要将大量纯HTML包含在SSP模板中,需要做些什么? Include seems only to work with template files. Include似乎只适用于模板文件。 Should I manually load and output html files in templates? 我应该在模板中手动加载和输出html文件吗? Are there any better ways? 有没有更好的方法?

It seems that it is an inherent limitation. 这似乎是一个固有的限制。

Workaround: manually read the file and output it into the template (yes, it is ugly but works): 解决方法:手动读取文件并将其输出到模板中(是的,它很难看但有效):

<% include("header.ssp") %>

<%@ val book:Integer %>

<% val bookHtml = "./public/books/" + "book_" + book + ".html"%>
<% val source = scala.io.Source.fromFile(bookHtml)
val lines = try source.mkString finally source.close()
%>

${unescape(lines)}

<% include("footer.ssp") %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM