*/
package com.vaadin.server;
-import java.io.File;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
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.
package com.vaadin.server;
+import java.io.File;
import java.io.Serializable;
import java.util.Iterator;
* @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();
}
*/
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;
private final Map<String, String> sharedParameterActionNameMap = new HashMap<String, String>();
private final Map<String, String> sharedParameterActionValueMap = new HashMap<String, String>();
- @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
"Portlet mode can only be changed from a portlet request");
}
}
-
- private Logger getLogger() {
- return Logger.getLogger(PortletApplicationContext2.class.getName());
- }
}
package com.vaadin.server;
-import java.io.File;
import java.util.Enumeration;
import java.util.HashMap;
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.
*
package com.vaadin.server;
import java.io.BufferedWriter;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
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;
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
package com.vaadin.server;
import java.io.BufferedWriter;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
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 {
import java.io.File;
import com.vaadin.server.FileResource;
+import com.vaadin.server.WrappedRequest;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.util.CurrentInstance;
public class NonExistingFileResource extends TestBase {
@Override
public void buttonClick(ClickEvent event) {
- FileResource res = new FileResource(new File(getContext()
- .getBaseDirectory() + "/" + filename));
+ FileResource res = new FileResource(new File(CurrentInstance
+ .get(WrappedRequest.class).getDeploymentConfiguration()
+ .getBaseDirectory()
+ + "/" + filename));
getMainWindow().open(res);
}
import java.io.FileInputStream;
import com.vaadin.Application;
-import com.vaadin.server.ServletApplicationContext;
+import com.vaadin.server.WrappedRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CustomLayout;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.UI.LegacyWindow;
+import com.vaadin.util.CurrentInstance;
public class Ticket1975 extends Application.LegacyApplication {
try {
cl1 = new CustomLayout(new ByteArrayInputStream(s.getBytes()));
layout.addComponent(cl1);
- ServletApplicationContext wc = ((ServletApplicationContext) getContext());
layout.addComponent(new Button("Disable/Enable",
new ClickListener() {
}
}));
- File f = new File(wc.getBaseDirectory().getAbsoluteFile()
- + "/VAADIN/themes/" + getTheme()
+ File baseDir = CurrentInstance.get(WrappedRequest.class)
+ .getDeploymentConfiguration().getBaseDirectory()
+ .getAbsoluteFile();
+ File f = new File(baseDir + "/VAADIN/themes/" + getTheme()
+ "/layouts/Ticket1975.html");
cl2 = new CustomLayout(new FileInputStream(f));
import com.vaadin.Application;
import com.vaadin.server.SystemError;
+import com.vaadin.server.WrappedRequest;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI;
+import com.vaadin.util.CurrentInstance;
/**
* Provides sample directory based on application directory. If this fails then
+ "context base directory failed, "
+ "possible security constraint with Application "
+ "Server or Servlet Container.<br />";
- File file = application.getContext().getBaseDirectory();
+ File file = CurrentInstance.get(WrappedRequest.class)
+ .getDeploymentConfiguration().getBaseDirectory();
if ((file == null) || (!file.canRead())
|| (file.getAbsolutePath() == null)) {
// cannot access example directory, possible security issue with