001
014
015 package com.liferay.portlet.wiki.engines.jspwiki;
016
017 import com.ecyrd.jspwiki.QueryItem;
018 import com.ecyrd.jspwiki.WikiEngine;
019 import com.ecyrd.jspwiki.WikiPage;
020 import com.ecyrd.jspwiki.attachment.Attachment;
021 import com.ecyrd.jspwiki.providers.ProviderException;
022 import com.ecyrd.jspwiki.providers.WikiAttachmentProvider;
023
024 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream;
025 import com.liferay.portal.kernel.util.FileUtil;
026 import com.liferay.portal.kernel.util.GetterUtil;
027 import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
028
029 import java.io.InputStream;
030
031 import java.util.ArrayList;
032 import java.util.Collection;
033 import java.util.Collections;
034 import java.util.Date;
035 import java.util.List;
036 import java.util.Properties;
037
038
041 public class LiferayAttachmentProvider implements WikiAttachmentProvider {
042
043 public void deleteAttachment(Attachment attachment) {
044 }
045
046 public void deleteVersion(Attachment attachment) {
047 }
048
049 public Collection<Attachment> findAttachments(QueryItem[] query) {
050 return Collections.emptyList();
051 }
052
053 public InputStream getAttachmentData(Attachment attachment) {
054 return _EMPTY_STREAM;
055 }
056
057 public Attachment getAttachmentInfo(WikiPage page, String name, int version)
058 throws ProviderException {
059
060 com.liferay.portlet.wiki.model.WikiPage wikiPage = null;
061
062 try {
063 wikiPage = WikiPageLocalServiceUtil.getPage(
064 _nodeId, page.getName());
065
066 String[] attachments = wikiPage.getAttachmentsFiles();
067
068 for (int i = 0; i < attachments.length; i++) {
069 String fileName = FileUtil.getShortFileName(attachments[i]);
070
071 if (fileName.equals(name)) {
072 return new Attachment(_engine, page.getName(), name);
073 }
074 }
075
076 return null;
077 }
078 catch (Exception e) {
079 throw new ProviderException(e.toString());
080 }
081 }
082
083 public String getProviderInfo() {
084 return LiferayAttachmentProvider.class.getName();
085 }
086
087 public List<Attachment> getVersionHistory(Attachment attachment) {
088 List<Attachment> history = new ArrayList<Attachment>();
089
090 history.add(attachment);
091
092 return history;
093 }
094
095 public void initialize(WikiEngine engine, Properties props) {
096 _engine = engine;
097 _nodeId = GetterUtil.getLong(props.getProperty("nodeId"));
098 }
099
100 public List<Attachment> listAllChanged(Date timestamp) {
101 return Collections.emptyList();
102 }
103
104 public Collection<Attachment> listAttachments(WikiPage page) {
105 return Collections.emptyList();
106 }
107
108 public void moveAttachmentsForPage(String oldParent, String newParent) {
109 }
110
111 public void putAttachmentData(Attachment attachment, InputStream data) {
112 }
113
114 private static final InputStream _EMPTY_STREAM =
115 new UnsyncByteArrayInputStream(new byte[0]);
116
117 private WikiEngine _engine;
118 private long _nodeId;
119
120 }