From b0b1a13247bf931eb7f33ff6d0a88fc1833144e9 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 4 Sep 2012 16:59:24 +0300 Subject: Move getBaseDirectory() to DeploymentConfiguration (#9402) --- .../src/com/vaadin/server/ApplicationContext.java | 15 ----------- .../com/vaadin/server/DeploymentConfiguration.java | 15 +++++++++++ .../vaadin/server/PortletApplicationContext2.java | 30 ---------------------- .../vaadin/server/ServletApplicationContext.java | 16 ------------ server/src/com/vaadin/server/VaadinPortlet.java | 26 +++++++++++++++++++ server/src/com/vaadin/server/VaadinServlet.java | 11 ++++++++ 6 files changed, 52 insertions(+), 61 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/ApplicationContext.java b/server/src/com/vaadin/server/ApplicationContext.java index 2c09ed3857..85a77241d9 100644 --- a/server/src/com/vaadin/server/ApplicationContext.java +++ b/server/src/com/vaadin/server/ApplicationContext.java @@ -15,7 +15,6 @@ */ package com.vaadin.server; -import java.io.File; import java.io.Serializable; import java.util.Collection; import java.util.Collections; @@ -148,20 +147,6 @@ public abstract class ApplicationContext implements HttpSessionBindingListener, return Logger.getLogger(ApplicationContext.class.getName()); } - /** - * Returns application context base directory. - * - * Typically an application is deployed in a such way that is has an - * application directory. For web applications this directory is the root - * directory of the web applications. In some cases applications might not - * have an application directory (for example web applications running - * inside a war). - * - * @return The application base directory or null if the application has no - * base directory. - */ - public abstract File getBaseDirectory(); - /** * Gets the session to which this application context is currently * associated. diff --git a/server/src/com/vaadin/server/DeploymentConfiguration.java b/server/src/com/vaadin/server/DeploymentConfiguration.java index 1f202eb923..0a70ef09b3 100644 --- a/server/src/com/vaadin/server/DeploymentConfiguration.java +++ b/server/src/com/vaadin/server/DeploymentConfiguration.java @@ -16,6 +16,7 @@ package com.vaadin.server; +import java.io.File; import java.io.Serializable; import java.util.Iterator; @@ -123,4 +124,18 @@ public interface DeploymentConfiguration extends Serializable { * @return the system messages object */ public SystemMessages getSystemMessages(); + + /** + * Returns application context base directory. + * + * Typically an application is deployed in a such way that is has an + * application directory. For web applications this directory is the root + * directory of the web applications. In some cases applications might not + * have an application directory (for example web applications running + * inside a war). + * + * @return The application base directory or null if the application has no + * base directory. + */ + public File getBaseDirectory(); } diff --git a/server/src/com/vaadin/server/PortletApplicationContext2.java b/server/src/com/vaadin/server/PortletApplicationContext2.java index 6a12eafc47..f157dc9ae6 100644 --- a/server/src/com/vaadin/server/PortletApplicationContext2.java +++ b/server/src/com/vaadin/server/PortletApplicationContext2.java @@ -15,15 +15,11 @@ */ package com.vaadin.server; -import java.io.File; import java.io.Serializable; -import java.net.URL; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; @@ -69,28 +65,6 @@ public class PortletApplicationContext2 extends ApplicationContext { private final Map sharedParameterActionNameMap = new HashMap(); private final Map sharedParameterActionValueMap = new HashMap(); - @Override - public File getBaseDirectory() { - PortletSession session = getPortletSession(); - String resultPath = session.getPortletContext().getRealPath("/"); - if (resultPath != null) { - return new File(resultPath); - } else { - try { - final URL url = session.getPortletContext().getResource("/"); - return new File(url.getFile()); - } catch (final Exception e) { - // FIXME: Handle exception - getLogger() - .log(Level.INFO, - "Cannot access base directory, possible security issue " - + "with Application Server or Servlet Container", - e); - } - } - return null; - } - protected PortletCommunicationManager getApplicationManager( Application application) { PortletCommunicationManager mgr = (PortletCommunicationManager) applicationToAjaxAppMgrMap @@ -403,8 +377,4 @@ public class PortletApplicationContext2 extends ApplicationContext { "Portlet mode can only be changed from a portlet request"); } } - - private Logger getLogger() { - return Logger.getLogger(PortletApplicationContext2.class.getName()); - } } diff --git a/server/src/com/vaadin/server/ServletApplicationContext.java b/server/src/com/vaadin/server/ServletApplicationContext.java index 4184b68de4..910051a26b 100644 --- a/server/src/com/vaadin/server/ServletApplicationContext.java +++ b/server/src/com/vaadin/server/ServletApplicationContext.java @@ -16,7 +16,6 @@ package com.vaadin.server; -import java.io.File; import java.util.Enumeration; import java.util.HashMap; @@ -98,21 +97,6 @@ public class ServletApplicationContext extends ApplicationContext { setSession(new WrappedHttpSession(newSession)); } - /** - * Gets the application context base directory. - * - * @see com.vaadin.server.ApplicationContext#getBaseDirectory() - */ - @Override - public File getBaseDirectory() { - final String realPath = VaadinServlet.getResourcePath(getHttpSession() - .getServletContext(), "/"); - if (realPath == null) { - return null; - } - return new File(realPath); - } - /** * Gets the http-session application is running in. * diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index 923fcd3b71..5fb2340bc8 100644 --- a/server/src/com/vaadin/server/VaadinPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -16,6 +16,7 @@ package com.vaadin.server; import java.io.BufferedWriter; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -24,11 +25,13 @@ import java.io.PrintWriter; import java.io.Serializable; import java.lang.reflect.Method; import java.net.MalformedURLException; +import java.net.URL; import java.security.GeneralSecurityException; import java.util.Enumeration; import java.util.Locale; import java.util.Map; import java.util.Properties; +import java.util.logging.Level; import java.util.logging.Logger; import javax.portlet.ActionRequest; @@ -154,6 +157,29 @@ public class VaadinPortlet extends GenericPortlet implements Constants { public SystemMessages getSystemMessages() { return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES; } + + @Override + public File getBaseDirectory() { + PortletContext context = getPortlet().getPortletContext(); + String resultPath = context.getRealPath("/"); + if (resultPath != null) { + return new File(resultPath); + } else { + try { + final URL url = context.getResource("/"); + return new File(url.getFile()); + } catch (final Exception e) { + // FIXME: Handle exception + getLogger() + .log(Level.INFO, + "Cannot access base directory, possible security issue " + + "with Application Server or Servlet Container", + e); + } + } + return null; + } + } public static class WrappedHttpAndPortletRequest extends diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 3cf2c645a0..62fb8ba71e 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -16,6 +16,7 @@ package com.vaadin.server; import java.io.BufferedWriter; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -140,6 +141,16 @@ public class VaadinServlet extends HttpServlet implements Constants { public SystemMessages getSystemMessages() { return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES; } + + @Override + public File getBaseDirectory() { + final String realPath = VaadinServlet.getResourcePath( + servlet.getServletContext(), "/"); + if (realPath == null) { + return null; + } + return new File(realPath); + } } private static class AbstractApplicationServletWrapper implements Callback { -- cgit v1.2.3