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