1 16 19 20 package com.sun.org.apache.xalan.internal.xsltc.compiler; 21 22 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen; 23 import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC; 24 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL; 25 import com.sun.org.apache.bcel.internal.generic.InstructionList; 26 import com.sun.org.apache.bcel.internal.generic.PUSH; 27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.StringType; 31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util; 34 35 38 final class TransletOutput extends Instruction { 39 40 private Expression _filename; 41 private boolean _append; 42 43 46 public void display(int indent) { 47 indent(indent); 48 Util.println("TransletOutput: " + _filename); 49 } 50 51 55 public void parseContents(Parser parser) { 56 String filename = getAttribute("file"); 58 59 String append = getAttribute("append"); 62 63 if ((filename == null) || (filename.equals(EMPTYSTRING))) { 65 reportError(this, parser, ErrorMsg.REQUIRED_ATTR_ERR, "file"); 66 } 67 68 _filename = AttributeValue.create(this, filename, parser); 70 71 if (append != null && (append.toLowerCase().equals("yes") || 72 append.toLowerCase().equals("true"))) { 73 _append = true; 74 } 75 else 76 _append = false; 77 78 parseChildren(parser); 79 } 80 81 84 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 85 final Type type = _filename.typeCheck(stable); 86 if (type instanceof StringType == false) { 87 _filename = new CastExpr(_filename, Type.String); 88 } 89 typeCheckContents(stable); 90 return Type.Void; 91 } 92 93 97 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 98 final ConstantPoolGen cpg = classGen.getConstantPool(); 99 final InstructionList il = methodGen.getInstructionList(); 100 final boolean isSecureProcessing = classGen.getParser().getXSLTC() 101 .isSecureProcessing(); 102 103 if (isSecureProcessing) { 104 int index = cpg.addMethodref(BASIS_LIBRARY_CLASS, 105 "unallowed_extension_elementF", 106 "(Ljava/lang/String;)V"); 107 il.append(new PUSH(cpg, "redirect")); 108 il.append(new INVOKESTATIC(index)); 109 return; 110 } 111 112 il.append(methodGen.loadHandler()); 114 115 final int open = cpg.addMethodref(TRANSLET_CLASS, 116 "openOutputHandler", 117 "(" + STRING_SIG + "Z)" + 118 TRANSLET_OUTPUT_SIG); 119 120 final int close = cpg.addMethodref(TRANSLET_CLASS, 121 "closeOutputHandler", 122 "("+TRANSLET_OUTPUT_SIG+")V"); 123 124 il.append(classGen.loadTranslet()); 126 _filename.translate(classGen, methodGen); 127 il.append(new PUSH(cpg, _append)); 128 il.append(new INVOKEVIRTUAL(open)); 129 130 il.append(methodGen.storeHandler()); 132 133 translateContents(classGen, methodGen); 135 136 il.append(classGen.loadTranslet()); 138 il.append(methodGen.loadHandler()); 139 il.append(new INVOKEVIRTUAL(close)); 140 141 il.append(methodGen.storeHandler()); 143 } 144 } 145 146 | Popular Tags |