1 package net.sourceforge.blogentis.utils;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.turbine.Turbine;
28 import org.apache.turbine.services.InitializationException;
29 import org.apache.turbine.services.TurbineBaseService;
30 import org.apache.turbine.services.TurbineServices;
31
32 public class LinkFactoryService
33 extends TurbineBaseService {
34 private static Log log = LogFactory.getLog(LinkFactoryService.class);
35
36 public static final String SERVICE_NAME = "LinkFactoryService";
37
38 protected String baseURI = null;
39
40 public LinkFactoryService() {
41 super();
42 if (log.isDebugEnabled())
43 log.debug("created self");
44 }
45
46 public static LinkFactoryService getInstance() {
47 return (LinkFactoryService)TurbineServices.getInstance()
48 .getService(SERVICE_NAME);
49 }
50
51 public static AbsoluteLinkURL getLink() {
52 LinkFactoryService service = getInstance();
53 if (!service.getInit())
54 return null;
55 return service.getLinkImpl();
56 }
57
58 protected String getBase() {
59 if (baseURI == null) {
60 StringBuffer buffer = new StringBuffer();
61 if (!getConfiguration().getBoolean("omitFullURI",false)) {
62 buffer.append(Turbine.getServerScheme());
63 buffer.append("://");
64 buffer.append(Turbine.getServerName());
65 if ((Turbine.getServerScheme() == "http" && Integer
66 .parseInt(Turbine.getServerPort()) != 80)) {
67 buffer.append(":");
68 buffer.append(Turbine.getServerPort());
69 }
70 }
71 buffer.append(Turbine.getContextPath());
72 if (buffer.lastIndexOf("/") < buffer.length() - 1)
73 buffer.append("/");
74 baseURI = buffer.toString();
75 if (log.isDebugEnabled())
76 log.debug("our URI is now: " + baseURI);
77 }
78 return baseURI;
79 }
80
81 public static String getBaseURI() {
82 return getInstance().getBase();
83 }
84
85 protected AbsoluteLinkURL getLinkImpl() {
86 return new AbsoluteLinkURL();
87 }
88
89 public void init(Object ignored)
90 throws InitializationException {
91 setInit(true);
92 }
93 }