Yasser Zamani
2019-04-20 12:28:07 +04:30
parent 47a8a21da2
commit 517c2d690b
2 changed files with 4 additions and 57 deletions
@@ -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();
}
}
@@ -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));
}
}