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
52 public class LiferayAttachmentProvider implements WikiAttachmentProvider {
53
54 public void deleteAttachment(Attachment attachment) {
55 }
56
57 public void deleteVersion(Attachment attachment) {
58 }
59
60 public Collection<Attachment> findAttachments(QueryItem[] query) {
61 return Collections.emptyList();
62 }
63
64 public InputStream getAttachmentData(Attachment attachment) {
65 return _EMPTY_STREAM;
66 }
67
68 public Attachment getAttachmentInfo(WikiPage page, String name, int version)
69 throws ProviderException {
70
71 com.liferay.portlet.wiki.model.WikiPage wikiPage = null;
72
73 try {
74 wikiPage = WikiPageLocalServiceUtil.getPage(
75 _nodeId, page.getName());
76
77 String[] attachments = wikiPage.getAttachmentsFiles();
78
79 for (int i = 0; i < attachments.length; i++) {
80 String fileName = FileUtil.getShortFileName(attachments[i]);
81
82 if (fileName.equals(name)) {
83 return new Attachment(_engine, page.getName(), name);
84 }
85 }
86
87 return null;
88 }
89 catch (Exception e) {
90 throw new ProviderException(e.toString());
91 }
92 }
93
94 public String getProviderInfo() {
95 return LiferayAttachmentProvider.class.getName();
96 }
97
98 public List<Attachment> getVersionHistory(Attachment attachment) {
99 List<Attachment> history = new ArrayList<Attachment>();
100
101 history.add(attachment);
102
103 return history;
104 }
105
106 public void initialize(WikiEngine engine, Properties props) {
107 _engine = engine;
108 _nodeId = GetterUtil.getLong(props.getProperty("nodeId"));
109 }
110
111 public List<Attachment> listAllChanged(Date timestamp) {
112 return Collections.emptyList();
113 }
114
115 public Collection<Attachment> listAttachments(WikiPage page) {
116 return Collections.emptyList();
117 }
118
119 public void moveAttachmentsForPage(String oldParent, String newParent) {
120 }
121
122 public void putAttachmentData(Attachment attachment, InputStream data) {
123 }
124
125 private static final InputStream _EMPTY_STREAM =
126 new ByteArrayInputStream(new byte[0]);
127
128 private WikiEngine _engine;
129 private long _nodeId;
130
131 }