电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

如何自由组织Tapestry页面规范文件


发布日期:2021/6/14
 

问题的提出

默认Tapestry的页面模板文件l)及其对应的规范文件(page)可以放在web根目录或其下的WEBINF/目录中Tapestry可以不用任何配置(在以前的版本中需要在application文件中定义一下页面)就能正确运行如果你需要在这些根目录下以文件系统的目录形式组织你的页面则Tapestry是不会自动搜索这些子目录的你必须在application文件中定义这些不在默认位置的页面这样一来每加一个页面都需要定义一下如果页面数目众多定义起来就会比较麻烦如何才能避免这些配置呢?本文的目的就是尝试解决这个问题

问题的解决

本文是在参考文档()源代码的基础上稍作修改而成主要是为了解决不能在Tomcat中使用的问题为了更好的了解朋友们最好能阅读一下原文和原来的代码主要修改的地方是给RecursiveFileLocator传递一个真实路径地址以便能够列出目录下面的子目录从而实现层次查找

解决的途径就是定义一个ISpecificationResolverDelegate以便Tapestry在常规路径下找不到文件时进行处理

CustomSpecificationResolverjava:

// CustomSpecificationResolverjava

//

// Copyright Michael J Henderson & Associates LLC

//

// Licensed under the Apache License Version (the License);

// you may not use this file except in compliance with the License

// You may obtain a copy of the License at

//

//

//

// 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 commjhendersonuserstapestry;

import monsloggingLog;

import monsloggingLogFactory;

import orgapachetapestryINamespace;

import orgapachetapestryIRequestCycle;

import orgapachetapestryIResourceLocation;

import orgapachetapestryTapestry;

import orgapachetapestryengineISpecificationSource;

import orgapachetapestryresolverISpecificationResolverDelegate;

import orgapachetapestryspecIComponentSpecification;

/**

* @author <a mailto:mich?subject=commjhendersonuserstapestryCustomSpecificationResolver>Mike Henderson</a>

*

*/

public class CustomSpecificationResolver implements

ISpecificationResolverDelegate {

private static final Log LOG = LogFactorygetLog(RecursiveFileLocatorclass);

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 = TapestrygetApplicationRootLocation(cycle)getRelativeLocation(/WEBINF/);

IResourceLocation rootLocation = TapestrygetApplicationRootLocation(cycle)getRelativeLocation(/);

//_applicationIsExplodedWAR = rootLocationgetResourceURL()toString()startsWith(file:);

//if (_applicationIsExplodedWAR) {

_realRootFolder = cyclegetRequestContext()getServlet()getServletContext()getRealPath(/);

_locator = new RecursiveFileLocator(rootLocation_realRootFolder);

_specificationSource = cyclegetEngine()getSpecificationSource();

//}

_initialized = true;

}

//private boolean checkLocationIsFileLocation(IResourceLocation location) {

//String url = locationgetResourceURL()toString();

//Systemoutprintln(url = +url);

//return urlstartsWith(file:);

//}

/**

* @see orgapachetapestryresolverISpecificationResolverDelegate#findPageSpecification(orgapachetapestryIRequestCycle orgapachetapestryINamespace javalangString)

*/

public IComponentSpecification findPageSpecification(IRequestCycle cycle

INamespace namespace String name) {

if (!_initialized) {

_init(cycle);

}

//if (!_applicationIsExplodedWAR) {

//return null;

//}

IResourceLocation location = _locatorresolveLocation(name+page);

if (location != null) {

return _specificationSourcegetPageSpecification(location);

}

return null;

}

/**

* @see orgapachetapestryresolverISpecificationResolverDelegate#findComponentSpecification(orgapachetapestryIRequestCycle orgapachetapestryINamespace javalangString)

*/

public IComponentSpecification findComponentSpecification(

IRequestCycle cycle INamespace namespace String type) {

if (!_initialized) {

_init(cycle);

}

//if (!_applicationIsExplodedWAR) {

//return null;

//}

IResourceLocation location = _locatorresolveLocation(type+jwc);

if (location != null) {

return _specificationSourcegetComponentSpecification(location);

}

return null;

}

}

RecursiveFileLocatorjava:

// RecursiveFileLocatorjava

//

// Copyright Michael J Henderson & Associates LLC

//

// Licensed under the Apache License Version (the License);

// you may not use this file except in compliance with the License

// You may obtain a copy of the License at

//

//

//

// 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 commjhendersonuserstapestry;

import javaioFile;

import URL;

import javautilArrayList;

import javautilHashMap;

import javautilIterator;

import javautilList;

import javautilMap;

import monsloggingLog;

import monsloggingLogFactory;

import orgapachetapestryIResourceLocation;

/**

* @author <a mailto:mich?subject=commjhendersonuserstapestryRecursiveFileLocator>Mike Henderson</a>

*

*/

public class RecursiveFileLocator {

private static final Log LOG = LogFactorygetLog(RecursiveFileLocatorclass);

private IResourceLocation_location;

private File realRoot ;

private Map _locations= new HashMap();

public RecursiveFileLocator(IResourceLocation locationString _realRootFolder) {

realRoot = new

上一篇:阳光在线电子商务解决方案

下一篇:网页制作中表单相关特效整理