1
19
20 package com.liferay.portal.velocity;
21
22 import com.liferay.portal.PortalException;
23 import com.liferay.portal.SystemException;
24 import com.liferay.portal.kernel.log.Log;
25 import com.liferay.portal.kernel.log.LogFactoryUtil;
26 import com.liferay.portal.kernel.util.GetterUtil;
27 import com.liferay.portal.kernel.util.StringPool;
28 import com.liferay.portlet.journal.model.JournalTemplate;
29 import com.liferay.portlet.journal.service.JournalTemplateLocalServiceUtil;
30
31 import java.io.ByteArrayInputStream;
32 import java.io.InputStream;
33
34 import org.apache.velocity.exception.ResourceNotFoundException;
35
36
43 public class JournalTemplateVelocityResourceListener
44 extends VelocityResourceListener {
45
46 public InputStream getResourceStream(String source)
47 throws ResourceNotFoundException {
48
49 InputStream is = null;
50
51 try {
52 int pos = source.indexOf(JOURNAL_SEPARATOR + StringPool.SLASH);
53
54 if (pos != -1) {
55 int x = source.indexOf(StringPool.SLASH, pos);
56 int y = source.indexOf(StringPool.SLASH, x + 1);
57 int z = source.indexOf(StringPool.SLASH, y + 1);
58
59 long companyId = GetterUtil.getLong(source.substring(x + 1, y));
60 long groupId = GetterUtil.getLong(source.substring(y + 1, z));
61 String templateId = source.substring(z + 1);
62
63 if (_log.isDebugEnabled()) {
64 _log.debug(
65 "Loading {companyId=" + companyId + ",groupId=" +
66 groupId + ",templateId=" + templateId + "}");
67 }
68
69 JournalTemplate template =
70 JournalTemplateLocalServiceUtil.getTemplate(
71 groupId, templateId);
72
73 String buffer = template.getXsl();
74
75 is = new ByteArrayInputStream(buffer.getBytes());
76 }
77 }
78 catch (PortalException pe) {
79 throw new ResourceNotFoundException(source);
80 }
81 catch (SystemException se) {
82 throw new ResourceNotFoundException(source);
83 }
84
85 return is;
86 }
87
88 private static Log _log =
89 LogFactoryUtil.getLog(JournalTemplateVelocityResourceListener.class);
90
91 }