jspcompilerinstance.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 756 行 · 第 1/2 页

JAVA
756
字号
    /*    for (int i = 0; i < _preludeList.size(); i++)      _parser.addPrelude(_preludeList.get(i));    for (int i = 0; i < _codaList.size(); i++)      _parser.addCoda(_codaList.get(i));    */  }  public Page compile()    throws Exception  {    LineMap lineMap = null;    if (_page != null)      throw new IllegalStateException("JspCompilerInstance cannot be reused");    try {      JspGenerator generator = generate();      lineMap = generator.getLineMap();      String encoding = _parseState.getCharEncoding();      _jspCompiler.compilePending();      boolean isAutoCompile = true;      if (_jspPropertyGroup != null)	isAutoCompile = _jspPropertyGroup.isAutoCompile();      Page page;      if (! generator.isStatic()) {        compileJava(_jspPath, _className, lineMap, encoding);        page = _jspCompiler.loadPage(_className, isAutoCompile);      }      else {        page = _jspCompiler.loadStatic(_className,                                       _parseState.isOptionalSession());        page._caucho_addDepend(generator.getDependList());        page._caucho_setContentType(_parseState.getContentType());      }      return page;    } catch (JspParseException e) {      e.setLineMap(lineMap);      e.setErrorPage(_parseState.getErrorPage());      throw e;    } catch (SAXException e) {      if (e.getCause() instanceof JspParseException) {	JspParseException subE = (JspParseException) e.getCause();	subE.setLineMap(lineMap);	subE.setErrorPage(_parseState.getErrorPage());	throw subE;      }      else {	JspParseException exn = new JspParseException(e);	exn.setErrorPage(_parseState.getErrorPage());	exn.setLineMap(lineMap);	throw exn;      }    } catch (FileNotFoundException e) {      throw e;    } catch (IOException e) {      JspParseException exn = new JspParseException(e);      exn.setLineMap(lineMap);      exn.setErrorPage(_parseState.getErrorPage());      throw exn;    } catch (Throwable e) {      JspParseException exn = new JspParseException(e);      exn.setLineMap(lineMap);      exn.setErrorPage(_parseState.getErrorPage());      throw exn;    }  }  public JspGenerator generate()    throws Exception  {    if (_page != null)      throw new IllegalStateException("JspCompilerInstance cannot be reused");    parse();    try {      JspGenerator generator = _jspBuilder.getGenerator();      generator.setJspCompilerInstance(this);      for (int i = 0; i < _dependList.size(); i++)	generator.addDepend(_dependList.get(i));      generator.validate();      generator.generate(_jspPath, _className);      return generator;    } catch (IOException e) {      JspParseException exn = new JspParseException(e);      exn.setErrorPage(_parseState.getErrorPage());      throw exn;    }  }    public void parse()    throws Exception  {    boolean isXml = _parseState.isXml();    boolean isForbidXml = _parseState.isForbidXml();    ParseState parseState = _parser.getParseState();        try {      _parser.getParseState().setBuilder(_jspBuilder);      for (String prelude : _preludeList) {	parseState.setXml(false);	parseState.setForbidXml(false);	_parser.parse(parseState.getResourceManager().resolvePath(prelude),		      prelude);      }            _parser.getParseState().setXml(isXml);      _parser.getParseState().setForbidXml(isForbidXml);      if (isXml) {	_parseState.setELIgnoredDefault(false);		Xml xml = new Xml();	xml.setContentHandler(new JspContentHandler(_jspBuilder));	_jspPath.setUserPath(_uri);	xml.setNamespaceAware(true);	xml.parse(_jspPath);      }      else {	WebApp app = _jspCompiler.getWebApp();	// jsp/0135	/*	if (_jspPropertyGroup == null && app != null && app.has23Config())   	  _parseState.setELIgnored(true);	*/		_parser.parse(_jspPath, _uri);      }      for (String coda : _codaList) {	parseState.setXml(false);	parseState.setForbidXml(false);	_parser.parse(parseState.getResourceManager().resolvePath(coda),		      coda);      }    } catch (JspParseException e) {      e.setErrorPage(_parseState.getErrorPage());      throw e;    } catch (SAXException e) {      if (e.getCause() instanceof JspParseException) {	JspParseException subE = (JspParseException) e.getCause();	subE.setErrorPage(_parseState.getErrorPage());	throw subE;      }      else {	JspParseException exn = new JspParseException(e);	exn.setErrorPage(_parseState.getErrorPage());	throw exn;      }    } catch (FileNotFoundException e) {      throw e;    } catch (IOException e) {      JspParseException exn = new JspParseException(e);      exn.setErrorPage(_parseState.getErrorPage());      throw exn;    }  }  public TagInfo compileTag(TagLibraryInfo taglib)    throws Exception  {    TagInfo preloadTag = preloadTag(taglib);    if (preloadTag != null)      return preloadTag;    return generateTag(taglib );  }  private TagInfo preloadTag(TagLibraryInfo taglib)  {    try {      JspTagSupport tag = (JspTagSupport) _jspCompiler.loadClass(_className, true);      if (tag == null)	return null;      tag.init(_jspCompiler.getAppDir());      if (tag._caucho_isModified())	return null;      return tag._caucho_getTagInfo(taglib);    } catch (Throwable e) {      return null;    }  }  private TagInfo generateTag(TagLibraryInfo taglib)    throws Exception  {    LineMap lineMap = null;    if (_page != null)      throw new IllegalStateException("JspCompilerInstance cannot be reused");    try {      boolean isXml = _isXml;            if (_jspPropertyGroup != null && ! isXml	  && _jspPropertyGroup.isXml() != null)	isXml = Boolean.TRUE.equals(_jspPropertyGroup.isXml());      if (_jspPropertyGroup != null	  && Boolean.FALSE.equals(_jspPropertyGroup.isXml()))	_parseState.setForbidXml(true);      _parseState.setXml(isXml);      if (_jspCompiler.addTag(_className)) {	_isPrototype = true;	_jspBuilder.setPrototype(true);      }      _parseState.setTag(true);      _isXml = isXml;            if (isXml) {	_parseState.setELIgnoredDefault(false);		Xml xml = new Xml();	xml.setContentHandler(new JspContentHandler(_jspBuilder));	_jspPath.setUserPath(_uri);	xml.setNamespaceAware(true);	xml.parse(_jspPath);      }      else	_parser.parseTag(_jspPath, _uri);      _generator = _jspBuilder.getGenerator();      if (_isPrototype) {	return _generator.generateTagInfo(_className, taglib);      }      _generator.validate();            _generator.generate(_jspPath, _className);      if (_jspCompiler.hasRecursiveCompile()) {	_jspCompiler.addPending(this);	return _generator.generateTagInfo(_className, taglib);      }      return completeTag(taglib);    } catch (JspParseException e) {      e.setLineMap(lineMap);      e.setErrorPage(_parseState.getErrorPage());      throw e;    } catch (FileNotFoundException e) {      throw e;    } catch (IOException e) {      JspParseException exn = new JspParseException(e);      exn.setErrorPage(_parseState.getErrorPage());      exn.setLineMap(lineMap);      throw exn;    }  }  TagInfo completeTag()    throws Exception  {    return completeTag(new TagTaglib("x", "uri"));  }  TagInfo completeTag(TagLibraryInfo taglib)    throws Exception  {    LineMap lineMap = null;    try {      lineMap = _generator.getLineMap();      String encoding = _parseState.getCharEncoding();      compileJava(_jspPath, _className, lineMap, encoding);      JspTagSupport tag = (JspTagSupport) _jspCompiler.loadClass(_className, true);      tag.init(_jspCompiler.getAppDir());      return tag._caucho_getTagInfo(taglib);      // Page page = _jspCompiler.loadClass(_className);    } catch (JspParseException e) {      e.setLineMap(lineMap);      e.setErrorPage(_parseState.getErrorPage());      throw e;    } catch (FileNotFoundException e) {      throw e;    } catch (IOException e) {      JspParseException exn = new JspParseException(e);      exn.setErrorPage(_parseState.getErrorPage());      exn.setLineMap(lineMap);      throw exn;    } catch (Throwable e) {      JspParseException exn = new JspParseException(e);      exn.setErrorPage(_parseState.getErrorPage());      exn.setLineMap(lineMap);      throw exn;    }  }  private void compileJava(Path path, String className,                           LineMap lineMap, String charEncoding)    throws Exception  {    JavaCompiler compiler = JavaCompiler.create(null);    compiler.setClassDir(_jspCompiler.getClassDir());    // compiler.setEncoding(charEncoding);    String fileName = className.replace('.', '/') + ".java";    compiler.compile(fileName, lineMap);    /*    boolean remove = true;    try {      compiler.compile(fileName, lineMap);      remove = false;    } finally {      if (remove)        Vfs.lookup(fileName).remove();    }    */    Path classDir = _jspCompiler.getClassDir();    Path classPath = classDir.lookup(className.replace('.', '/') + ".class");    Path smapPath =  classDir.lookup(fileName + ".smap");    // jsp/18p1    // compiler.mergeSmap(classPath, smapPath);  }  private void readSmap(ClassLoader loader, String className)  {    if (loader == null)      return;    String smapName = className.replace('.', '/') + ".java.smap";    InputStream is = null;    try {      is = loader.getResourceAsStream(smapName);    } catch (Exception e) {      log.log(Level.FINE, e.toString(), e);    } finally {      if (is != null) {        try {          is.close();        } catch (IOException e) {        }      }    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?