Method from org.apache.tiles.definition.dao.BaseLocaleUrlDefinitionDAO Detail: |
public void addSourceURL(URL sourceURL) {
if (sourceURLs == null) {
sourceURLs = new ArrayList< URL >();
}
sourceURLs.add(sourceURL);
}
|
protected String[] getResourceNames(String resourceString) {
return resourceString.split(",");
}
Parse the resourceString into a list of resource paths which can be
loaded by the application context. |
protected String getResourceString(Map<String, String> parms) {
String resourceStr = parms.get(DefinitionsFactory.DEFINITIONS_CONFIG);
if (resourceStr == null) {
resourceStr = parms.get(BasicTilesContainer.DEFINITIONS_CONFIG);
}
if (resourceStr == null) {
resourceStr = parms.get(LEGACY_DEFINITIONS_CONFIG);
}
if (resourceStr == null) {
resourceStr = "/WEB-INF/tiles.xml";
}
return resourceStr;
}
Derive the resource string from the initialization parameters. If no
parameter DefinitionsFactory#DEFINITIONS_CONFIG is available,
attempts to retrieve the deprecated
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
parameter and #LEGACY_DEFINITIONS_CONFIG . If neither are
available, returns "/WEB-INF/tiles.xml". |
protected void identifySources(Map<String, String> initParameters) {
if (applicationContext == null) {
throw new IllegalStateException(
"The TilesApplicationContext cannot be null");
}
String resourceString = getResourceString(initParameters);
String[] resources = getResourceNames(resourceString);
try {
for (int i = 0; i < resources.length; i++) {
Set< URL > urls = applicationContext.getResources(resources[i]);
if (urls != null && !urls.isEmpty()) {
for (URL resourceUrl : urls) {
if (resourceUrl != null) {
if (log.isDebugEnabled()) {
log.debug("Adding resource '" + resourceUrl
+ "' to definitions factory.");
}
String externalForm = resourceUrl.toExternalForm();
if (externalForm.indexOf('_', externalForm
.lastIndexOf("/")) < 0) {
sourceURLs.add(resourceUrl);
} else if (log.isDebugEnabled()) {
log.debug("Not adding resource '" + resourceUrl
+ "' to definitions factory because it is "
+ "supposed to be an internationalization.");
}
} else {
log.warn("Unable to find configured definition '"
+ resources[i] + "'");
}
}
} else {
log.warn("Unable to find resources under the name '"
+ resources[i] + "'");
}
}
} catch (IOException e) {
throw new DefinitionsFactoryException(
"Unable to parse definitions from " + resourceString, e);
}
}
Detects the sources to load. |
public void init(Map<String, String> params) {
identifySources(params);
String readerClassName = params
.get(DefinitionsFactory.READER_IMPL_PROPERTY);
if (readerClassName != null) {
reader = (DefinitionsReader) ClassUtil.instantiate(readerClassName);
} else {
reader = new DigesterDefinitionsReader();
}
reader.init(params);
}
|
protected Map<String, Definition> loadDefinitionsFromURL(URL url) {
Map< String, Definition > defsMap = null;
try {
URLConnection connection = url.openConnection();
connection.connect();
lastModifiedDates.put(url.toExternalForm(), connection
.getLastModified());
// Definition must be collected, starting from the base
// source up to the last localized file.
defsMap = reader.read(connection.getInputStream());
} catch (FileNotFoundException e) {
// File not found. continue.
if (log.isDebugEnabled()) {
log.debug("File " + null + " not found, continue");
}
} catch (IOException e) {
throw new DefinitionsFactoryException(
"I/O error processing configuration.", e);
}
return defsMap;
}
Loads definitions from an URL without loading from "parent" URLs. |
public boolean refreshRequired() {
boolean status = false;
Set< String > urls = lastModifiedDates.keySet();
try {
for (String urlPath : urls) {
Long lastModifiedDate = lastModifiedDates.get(urlPath);
URL url = new URL(urlPath);
URLConnection connection = url.openConnection();
connection.connect();
long newModDate = connection.getLastModified();
if (newModDate != lastModifiedDate) {
status = true;
break;
}
}
} catch (Exception e) {
log.warn("Exception while monitoring update times.", e);
return true;
}
return status;
}
|
public void setApplicationContext(TilesApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
|
public void setReader(DefinitionsReader reader) {
this.reader = reader;
}
|
public void setSourceURLs(List<URL> sourceURLs) {
this.sourceURLs = sourceURLs;
}
|