1
2
3
4
5
6
7
8
9
10
11 package org.weda.page;
12
13 import java.io.IOException;
14 import java.io.InputStream;
15 import javax.servlet.ServletContext;
16 import org.apache.commons.io.IOUtils;
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.tapestry.IAsset;
19 import org.apache.tapestry.IRequestCycle;
20 import org.apache.tapestry.annotations.InjectObject;
21 import org.apache.tapestry.asset.ExternalAsset;
22 import org.apache.tapestry.contrib.link.PopupLinkRenderer;
23 import org.apache.tapestry.html.BasePage;
24 import org.apache.tapestry.link.ILinkRenderer;
25 import org.weda.store.ObjectStoreException;
26 import org.weda.domain.Company;
27 import org.weda.store.ObjectStore;
28
29 /**
30 *
31 * @author tim
32 */
33 public abstract class HomePage extends BasePage {
34 public Object obj;
35 public ILinkRenderer getLinkRenderer(){
36 return new PopupLinkRenderer(
37 "Просмотр фотографии",
38 "titlebar,resizable,scrollbars,width=700,height=600");
39 }
40
41 public abstract ObjectStore getPersistentService();
42
43 @InjectObject(value="service:tapestry.globals.ServletContext")
44 public abstract ServletContext getServletContext();
45
46 public String getCompanyInfo(int id) throws ObjectStoreException {
47 return getPersistentService().load(Company.class, id).toString();
48 }
49 public String getDir(){
50 ServletContext ctx = getServletContext();
51 String res="--";
52 if (ctx!=null){
53 InputStream is=ctx.getResourceAsStream("/WEB-INF/hibernate.properties");
54 if (is!=null){
55 res="resource found!!!\n";
56 try{
57 res+=IOUtils.toString(is);
58 }catch(IOException e){
59 res+="ERROR!!!\n"+e.getMessage();
60 }
61 }
62 }else
63 res="servlet context not injected :(";
64 return res;
65 }
66
67 public IAsset getImage(){
68 return new ExternalAsset("images/SANY0002.jpg", null);
69 }
70
71 public void performAction(IRequestCycle cycle){
72 throw new ApplicationRuntimeException("Generated error");
73 }
74 }