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