問題的提出
默認Tapestry的頁面模板文件l)及其對應的規范文件(
問題的解決
本文是在參考文檔()源代碼的基礎上稍作修改而成
解決的途徑就是定義一個ISpecificationResolverDelegate
CustomSpecificationResolver
// CustomSpecificationResolver
//
// Copyright
//
// Licensed under the Apache 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
// distributed under the License is distributed on an
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND
// See the License for the specific language governing permissions and
// limitations under the License
package com
import mons
import mons
import org
import org
import org
import org
import org
import org
import org
/**
* @author <a mailto:mich?subject=com
*
*/
public class CustomSpecificationResolver implements
ISpecificationResolverDelegate {
private static final Log LOG = LogFactory
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
IResourceLocation rootLocation = Tapestry
//_applicationIsExplodedWAR = rootLocation
//if (_applicationIsExplodedWAR) {
_realRootFolder = cycle
_locator = new RecursiveFileLocator(rootLocation
_specificationSource = cycle
//}
_initialized = true;
}
// private boolean checkLocationIsFileLocation(IResourceLocation location) {
// String url = location
// System
// return url
// }
/**
* @see org
*/
public IComponentSpecification findPageSpecification(IRequestCycle cycle
INamespace namespace
if (!_initialized) {
_init(cycle);
}
//if (!_applicationIsExplodedWAR) {
// return null;
//}
IResourceLocation location = _locator
if (location != null) {
return _specificationSource
}
return null;
}
/**
* @see org
*/
public IComponentSpecification findComponentSpecification(
IRequestCycle cycle
if (!_initialized) {
_init(cycle);
}
//if (!_applicationIsExplodedWAR) {
// return null;
//}
IResourceLocation location = _locator
if (location != null) {
return _specificationSource
}
return null;
}
}
RecursiveFileLocator
// RecursiveFileLocator
//
// Copyright
//
// Licensed under the Apache 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
// distributed under the License is distributed on an
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND
// See the License for the specific language governing permissions and
// limitations under the License
package com
import java
import
import java
import java
import java
import java
import java
import mons
import mons
import org
/**
* @author <a mailto:mich?subject=com
*
*/
public class RecursiveFileLocator {
private static final Log LOG = LogFactory
private IResourceLocation _location;
private File realRoot ;
private Map _locations = new HashMap();
public RecursiveFileLocator(IResourceLocation location
realRoot = new
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19198.html