国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

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

如何自由組織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:michaelh@mjhenderson.com?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:michaelh@mjhenderson.com?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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高邮市| 房山区| 海林市| 原阳县| 大石桥市| 裕民县| 灯塔市| 岑巩县| 云南省| 双流县| 濉溪县| 福贡县| 女性| 山东| 金沙县| 聂拉木县| 海晏县| 积石山| 山阴县| 萝北县| 庆安县| 澎湖县| 旺苍县| 股票| 分宜县| 北川| 阜新市| 昌图县| 大城县| 海林市| 佳木斯市| 肃北| 油尖旺区| 井冈山市| 化州市| 天台县| 武胜县| 西乡县| 行唐县| 江津市| 吴桥县|