mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
use Tiles already provided URLApplicationResource
fixes WW-5011 see also: https://github.com/joshlong/spring-framework/blob/910dd4146721a803cd9d246b91854e77ffe9272a/spring-webmvc-tiles3/src/main/java/org/springframework/web/servlet/view/tiles3/SpringWildcardServletTilesApplicationContext.java#L88
This commit is contained in:
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.struts2.tiles;
|
||||
|
||||
import org.apache.tiles.request.locale.PostfixedApplicationResource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
public class StrutsApplicationResource extends PostfixedApplicationResource {
|
||||
|
||||
private final URL url;
|
||||
|
||||
public StrutsApplicationResource(URL url) {
|
||||
super(url.getPath());
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return url.openStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastModified() throws IOException {
|
||||
File file = new File(url.getPath());
|
||||
if (file.exists()) {
|
||||
return file.lastModified();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Resource " + getLocalePath() + " at " + url.toString();
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -24,6 +24,7 @@ import com.opensymphony.xwork2.util.finder.ResourceFinder;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.tiles.request.ApplicationResource;
|
||||
import org.apache.tiles.request.locale.URLApplicationResource;
|
||||
import org.apache.tiles.request.servlet.ServletApplicationContext;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -101,7 +102,7 @@ public class StrutsWildcardServletApplicationContext extends ServletApplicationC
|
||||
File localFile = new File(localePath);
|
||||
if (localFile.exists()) {
|
||||
try {
|
||||
return new StrutsApplicationResource(localFile.toURI().toURL());
|
||||
return new URLApplicationResource(localePath, localFile.toURI().toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
LOG.warn("Cannot access [{}]", localePath, e);
|
||||
return null;
|
||||
@@ -120,7 +121,8 @@ public class StrutsWildcardServletApplicationContext extends ServletApplicationC
|
||||
|
||||
for (Map.Entry<String, URL> entry : matches.entrySet()) {
|
||||
if (pattern.matcher(entry.getKey()).matches()) {
|
||||
resources.add(new StrutsApplicationResource(entry.getValue()));
|
||||
URL url = entry.getValue();
|
||||
resources.add(new URLApplicationResource(url.toExternalForm(), url));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user