1
22
23 package com.liferay.portlet.wiki.engines.jspwiki;
24
25 import com.ecyrd.jspwiki.QueryItem;
26 import com.ecyrd.jspwiki.WikiEngine;
27 import com.ecyrd.jspwiki.WikiPage;
28 import com.ecyrd.jspwiki.attachment.Attachment;
29 import com.ecyrd.jspwiki.providers.ProviderException;
30 import com.ecyrd.jspwiki.providers.WikiAttachmentProvider;
31
32 import com.liferay.portal.kernel.util.FileUtil;
33 import com.liferay.portal.kernel.util.GetterUtil;
34 import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
35
36 import java.io.ByteArrayInputStream;
37 import java.io.InputStream;
38
39 import java.util.ArrayList;
40 import java.util.Collection;
41 import java.util.Collections;
42 import java.util.Date;
43 import java.util.List;
44 import java.util.Properties;
45
46
51 public class LiferayAttachmentProvider implements WikiAttachmentProvider {
52
53 public void deleteAttachment(Attachment attachment) {
54 }
55
56 public void deleteVersion(Attachment attachment) {
57 }
58
59 public Collection<Attachment> findAttachments(QueryItem[] query) {
60 return Collections.emptyList();
61 }
62
63 public InputStream getAttachmentData(Attachment attachment) {
64 return _EMPTY_STREAM;
65 }
66
67 public Attachment getAttachmentInfo(WikiPage page, String name, int version)
68 throws ProviderException {
69
70 com.liferay.portlet.wiki.model.WikiPage wikiPage = null;
71
72 try {
73 wikiPage = WikiPageLocalServiceUtil.getPage(
74 _nodeId, page.getName());
75
76 String[] attachments = wikiPage.getAttachmentsFiles();
77
78 for (int i = 0; i < attachments.length; i++) {
79 String fileName = FileUtil.getShortFileName(attachments[i]);
80
81 if (fileName.equals(name)) {
82 return new Attachment(_engine, page.getName(), name);
83 }
84 }
85
86 return null;
87 }
88 catch (Exception e) {
89 throw new ProviderException(e.toString());
90 }
91 }
92
93 public String getProviderInfo() {
94 return LiferayAttachmentProvider.class.getName();
95 }
96
97 public List<Attachment> getVersionHistory(Attachment attachment) {
98 List<Attachment> history = new ArrayList<Attachment>();
99
100 history.add(attachment);
101
102 return history;
103 }
104
105 public void initialize(WikiEngine engine, Properties props) {
106 _engine = engine;
107 _nodeId = GetterUtil.getLong(props.getProperty("nodeId"));
108 }
109
110 public List<Attachment> listAllChanged(Date timestamp) {
111 return Collections.emptyList();
112 }
113
114 public Collection<Attachment> listAttachments(WikiPage page) {
115 return Collections.emptyList();
116 }
117
118 public void moveAttachmentsForPage(String oldParent, String newParent) {
119 }
120
121 public void putAttachmentData(Attachment attachment, InputStream data) {
122 }
123
124 private static final InputStream _EMPTY_STREAM =
125 new ByteArrayInputStream(new byte[0]);
126
127 private WikiEngine _engine;
128 private long _nodeId;
129
130 }