1 19 20 package org.apache.jasper.compiler; 21 22 import java.io.FileNotFoundException ; 23 import java.io.IOException ; 24 import java.lang.reflect.Field ; 25 import java.lang.reflect.InvocationTargetException ; 26 import java.lang.reflect.Method ; 27 import java.net.URL ; 28 import java.util.jar.JarFile ; 29 import org.apache.jasper.JasperException; 30 import org.apache.jasper.JspCompilationContext; 31 import org.apache.jasper.compiler.Compiler; 32 import org.openide.ErrorManager; 33 34 38 public class ParserControllerProxy { 39 40 private JspCompilationContext ctxt; 41 private Compiler compiler; 42 private ParserController pc; 43 44 boolean isXml; 45 String sourceEnc; 46 47 private static Method getJarFileM; 48 private static Method resolveFileNameM; 49 private static Method getJspConfigPageEncodingM; 50 private static Method determineSyntaxAndEncodingM; 51 private static Field isXmlF; 52 private static Field sourceEncF; 53 54 static { 55 initMethodsAndFields(); 56 } 57 58 59 public ParserControllerProxy(JspCompilationContext ctxt, Compiler compiler) { 60 this.ctxt = ctxt; 61 this.compiler = compiler; 62 pc = new ParserController(ctxt, compiler); 63 } 64 65 public static void initMethodsAndFields() { 66 try { 67 getJarFileM = ParserController.class.getDeclaredMethod("getJarFile", new Class [] {URL .class}); 69 getJarFileM.setAccessible(true); 70 resolveFileNameM = ParserController.class.getDeclaredMethod("resolveFileName", new Class [] {String .class}); 72 resolveFileNameM.setAccessible(true); 73 getJspConfigPageEncodingM = ParserController.class.getDeclaredMethod("getJspConfigPageEncoding", new Class [] {String .class}); 75 getJspConfigPageEncodingM.setAccessible(true); 76 determineSyntaxAndEncodingM = ParserController.class.getDeclaredMethod("determineSyntaxAndEncoding", new Class [] 78 {String .class, JarFile .class, String .class}); 79 determineSyntaxAndEncodingM.setAccessible(true); 80 isXmlF = ParserController.class.getDeclaredField("isXml"); 82 isXmlF.setAccessible(true); 83 sourceEncF = ParserController.class.getDeclaredField("sourceEnc"); 85 sourceEncF.setAccessible(true); 86 } 87 catch (NoSuchMethodException e) { 88 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 89 } 90 catch (NoSuchFieldException e) { 91 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 92 } 93 } 94 95 public void extractSyntaxAndEncoding(String inFileName) 96 throws FileNotFoundException , JasperException, IOException { 97 extractSyntaxAndEncoding(inFileName, ctxt.getTagFileJarUrl()); 102 } 103 104 private void extractSyntaxAndEncoding(String inFileName, URL jarFileUrl) 105 throws FileNotFoundException , JasperException, IOException { 106 try { 107 JarFile jarFile = (JarFile )getJarFileM.invoke(pc, new Object [] {jarFileUrl}); 108 String absFileName = (String )resolveFileNameM.invoke(pc, new Object [] {inFileName}); 109 String jspConfigPageEnc = (String )getJspConfigPageEncodingM.invoke(pc, new Object [] {absFileName}); 110 111 determineSyntaxAndEncodingM.invoke(pc, new Object [] {absFileName, jarFile, jspConfigPageEnc}); 114 115 isXml = ((Boolean )isXmlF.get(pc)).booleanValue(); 117 sourceEnc = (String )sourceEncF.get(pc); 118 } 119 catch (IllegalAccessException e) { 120 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 121 throw new JasperException(e); 122 } 123 catch (InvocationTargetException e) { 124 Throwable r = e.getTargetException(); 125 if (r instanceof RuntimeException ) { 126 throw (RuntimeException )r; 127 } 128 if (r instanceof FileNotFoundException ) { 129 throw (FileNotFoundException )r; 130 } 131 if (r instanceof JasperException) { 132 throw (JasperException)r; 133 } 134 if (r instanceof IOException ) { 135 throw (IOException )r; 136 } 137 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 138 throw new JasperException(e); 139 } 140 } 141 142 } 143 | Popular Tags |