麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

如何自由組織Tapestry頁面規范文件

2019-11-18 13:12:40
字體:
來源:轉載
供稿:網友

  問題的提出:
  默認Tapestry的頁面模板文件(.Html)及其對應的規范文件(.page),可以放在web根目錄或其下的WEB-INF/目錄中,Tapestry可以不用任何配置(在以前的版本中需要在.application文件中定義一下頁面)就能正確運行,假如你需要在這些根目錄下以文件系統的目錄形式組織你的頁面,則Tapestry是不會自動搜索這些子目錄的,你必須在.application文件中定義這些不在默認位置的頁面。這樣一來,每加一個頁面都需要定義一下,假如頁面數目眾多,定義起來就會比較麻煩,如何才能避免這些配置呢?本文的目的就是嘗試解決這個問題。
  
  問題的解決:
  本文是在參考文檔(http://www.behindthesite.com/blog/C1931765677/E381917869/index.html)源代碼的基礎上稍作修改而成,主要是為了解決不能在Tomcat中使用的問題。為了更好的了解,朋友們最好能閱讀一下原文和原來的代碼。主要修改的地方是給RecursiveFileLocator傳遞一個真實路徑地址,以便能夠列出目錄下面的子目錄,從而實現層次查找。
  
  解決的途徑就是定義一個ISpecificationResolverDelegate,以便Tapestry在常規路徑下找不到文件時進行處理。
    CustomSpecificationResolver.java:
  
  // CustomSpecificationResolver.java
  //
  // Copyright 2004 Michael J. Henderson & Associates LLC
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may oBTain a copy of the License at
  //
  //   http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either eXPRess or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package com.mjhenderson.users.tapestry;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.tapestry.INamespace;
  import org.apache.tapestry.IRequestCycle;
  import org.apache.tapestry.IResourceLocation;
  import org.apache.tapestry.Tapestry;
  import org.apache.tapestry.engine.ISpecificationSource;
  import org.apache.tapestry.resolver.ISpecificationResolverDelegate;
  import org.apache.tapestry.spec.IComponentSpecification;
  
  /**
   * @author <a href="mailto:[email protected]?subject=com.mjhenderson.users.tapestry.CustomSpecificationResolver">Mike Henderson</a>
   *
   */
  public class CustomSpecificationResolver implements
      ISpecificationResolverDelegate {
    
  
    private static final Log LOG = LogFactory.getLog(RecursiveFileLocator.class);
  
    private ISpecificationSource _specificationSource;
  
    private RecursiveFileLocator _locator;
    //private boolean _applicationIsExplodedWAR;
    private boolean _initialized;
    private String _folder;
    private String _realRootFolder;
    
    public CustomSpecificationResolver() {;
    }
    
    public void setFolder(String value) {
      _folder = value;
    }
    
    public String getFolder() {
      return _folder;
    }
    
    private void _init(IRequestCycle cycle) {
        //IResourceLocation rootLocation = Tapestry.getApplicationRootLocation(cycle).getRelativeLocation("/WEB-INF/");
      IResourceLocation rootLocation = Tapestry.getApplicationRootLocation(cycle).getRelativeLocation("/");
      //_applicationIsExplodedWAR = rootLocation.getResourceURL().toString().startsWith("file:");
      //if (_applicationIsExplodedWAR) {
      _realRootFolder = cycle.getRequestContext().getServlet().getServletContext().getRealPath("/");
      _locator = new RecursiveFileLocator(rootLocation,_realRootFolder);
      _specificationSource = cycle.getEngine().getSpecificationSource();
      //}
      _initialized = true;
    }
    
  //  private boolean checkLocationIsFileLocation(IResourceLocation location) {
  //    String url = location.getResourceURL().toString();
  //    System.out.println("url = "+url);
  //    return url.startsWith("file:");
  //  }
    
    /**
     * @see org.apache.tapestry.resolver.ISpecificationResolverDelegate#findPageSpecification(org.apache.tapestry.IRequestCycle, org.apache.tapestry.INamespace, java.lang.String)
     */
    public IComponentSpecification findPageSpecification(IRequestCycle cycle,
        INamespace namespace, String name) {
  
      if (!_initialized) {
        _init(cycle);
      }
      //if (!_applicationIsExplodedWAR) {
      //  return null;
      //}
      IResourceLocation location = _locator.resolveLocation(name+".page");
      if (location != null) {
        return _specificationSource.getPageSpecification(location);
      }
      return null;
    }
  
    /**
     * @see org.apache.tapestry.resolver.ISpecificationResolverDelegate#findComponentSpecification(org.apache.tapestry.IRequestCycle, org.apache.tapestry.INamespace, java.lang.String)
     */
    public IComponentSpecification findComponentSpecification(
        IRequestCycle cycle, INamespace namespace, String type) {
      
      if (!_initialized) {
        _init(cycle);
      }
      //if (!_applicationIsExplodedWAR) {
      //  return null;
      //}
      IResourceLocation location = _locator.resolveLocation(type+".jwc");
      if (location != null) {
        return _specificationSource.getComponentSpecification(location);
      }
      return null;
    }
  
  }
  RecursiveFileLocator.java:
  
  // RecursiveFileLocator.java
  //
  // Copyright 2004 Michael J. Henderson & Associates LLC
  //
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //   http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  package com.mjhenderson.users.tapestry;
  
  import java.io.File;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.tapestry.IResourceLocation;
  
  /**
   * @author <a href="mailto:[email protected]?subject=com.mjhenderson.users.tapestry.RecursiveFileLocator">Mike Henderson</a>
   *
   */
  public class RecursiveFileLocator {
    
    private static final Log LOG = LogFactory.getLog(RecursiveFileLocator.class);
  
    private IResourceLocation  _location;
    
    private File realRoot ;
    
    private Map _locations   = new HashMap();
    
    public RecursiveFileLocator(IResourceLocation location,String _realRootFolder) {
      realRoot = new

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永久免费在线观看av | 日本在线免费观看 | 最新中文字幕日本 | 久久国产综合视频 | 久久99久久98精品免观看软件 | 特级毛片a级毛片100免费 | 精精国产xxxx视频在线播放7 | 一级毛片在线看 | 姑娘第四集免费看视频 | 特一级黄色毛片 | 成人福利视频导航 | 中国女警察一级毛片视频 | 欧美精品一区二区三区在线 | 羞羞的视频在线观看 | 久久久久久久久久久影视 | 成人精品一区二区 | 色婷婷久久久 | 国产羞羞视频在线观看 | 一级做受大片免费视频 | 国产成人精品无人区一区 | 国产寡妇xxxxxxxx性开放 | 在线成人精品视频 | 亚洲一区二区三区日本久久九 | 操操日日| 国产精品刺激对白麻豆99 | 国产精品久久久久一区二区 | 黄色毛片免费看 | 午夜亚洲影院 | 国产亚洲精品网站 | 欧美视频一级 | 色淫视频 | 国产无区一区二区三麻豆 | 少妇一级淫片免费放正片 | 亚洲婷婷日日综合婷婷噜噜噜 | 成人h精品动漫一区二区三区 | 亚洲一区二区中文字幕在线观看 | 国产区二区 | 精品国产高清一区二区三区 | 特级毛片全部免费播放器 | 久久中文免费 | 毛片一区二区三区四区 |