1 package net.sf.cantina.system;
2
3 import net.sf.cantina.*;
4 import net.sf.cantina.exceptions.ForbiddenOperationException;
5 import net.sf.cantina.util.XmlHelper;
6
7 import java.util.Locale;
8
9
10 /***
11 * @author Stephane JAIS
12 */
13 public class ChangeDocumentTransaction
14 implements Transaction
15 {
16
17 private Document document;
18 private User user;
19 private byte[] content;
20 private Locale locale;
21
22 public ChangeDocumentTransaction (String documentId,
23 User user,
24 byte[] content,
25 Locale locale)
26 throws Exception
27 {
28 this.document = DataSource.getInstance().loadDocument(documentId);
29 this.user = user;
30 this.content = content;
31 this.locale = locale;
32 }
33
34 public void execute()
35 throws Exception
36 {
37 Realm realm = document.getRealm();
38 if (!(realm.accepts(user)))
39 throw new ForbiddenOperationException();
40 document.setContent(locale,content);
41 if (document.getContentType().equals("text/xml"))
42 XmlHelper.checkXml(new String(content), false);
43 DataSource.getInstance().saveDocument(document);
44 SearchEngine.getInstance().updateDocument(document);
45 }
46 }