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