Source code: com/xpn/xwiki/doc/XWikiAttachmentContent.java
1 /**
2 * ===================================================================
3 *
4 * Copyright (c) 2003 Ludovic Dubost, All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details, published at
15 * http://www.gnu.org/copyleft/gpl.html or in gpl.txt in the
16 * root folder of this distribution.
17
18 * Created by
19 * User: Ludovic Dubost
20 * Date: 30 janv. 2004
21 * Time: 23:05:10
22 */
23 package com.xpn.xwiki.doc;
24
25
26
27 public class XWikiAttachmentContent {
28
29 private XWikiAttachment attachment;
30 private byte[] content;
31
32 private boolean isContentDirty = false;
33
34 public XWikiAttachmentContent(XWikiAttachment attachment) {
35 this();
36 setAttachment(attachment);
37 }
38
39 public XWikiAttachmentContent() {
40 content = new byte[0];
41 }
42
43 public long getId() {
44 return attachment.getId();
45 }
46
47 public void setId(long id) {
48 }
49
50 public Object clone() {
51 XWikiAttachmentContent attachmentcontent = null;
52 try {
53 attachmentcontent = (XWikiAttachmentContent) getClass().newInstance();
54 } catch (Exception e) {
55 // This should not happen
56 }
57
58 attachmentcontent.setAttachment(getAttachment());
59 attachmentcontent.setContent(getContent());
60 return attachmentcontent;
61 }
62
63 public byte[] getContent() {
64 if (content==null)
65 return new byte[0];
66 else
67 return content;
68 }
69
70 public void setContent(byte[] content) {
71 if (content==null)
72 content = null;
73 else {
74 if (!content.equals(this.content))
75 setContentDirty(true);
76 this.content = content;
77 attachment.setFilesize(content.length);
78 }
79 }
80
81 public XWikiAttachment getAttachment() {
82 return attachment;
83 }
84
85 public void setAttachment(XWikiAttachment attachment) {
86 this.attachment = attachment;
87 }
88
89 public boolean isContentDirty() {
90 return isContentDirty;
91 }
92
93 public void setContentDirty(boolean contentDirty) {
94 isContentDirty = contentDirty;
95 }
96 }