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