📄 xwikircsfilestore.java
字号:
public Version[] getXWikiDocVersions(XWikiDocument doc, XWikiContext context) throws XWikiException {
try {
doc.setStore(this);
File vfile = getVersionedFilePath(doc, context);
String path = vfile.toString();
synchronized (path) {
Archive archive;
try {
archive= new Archive(path);
} catch (Exception e) {
File file = getFilePath(doc, context);
if (file.exists()) {
Version[] versions = new Version[1];
versions[0] = new Version("1.1");
return versions;
}
else {
Object[] args = { doc.getFullName() };
throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_FILENOTFOUND,
"File {0} does not exist", e, args);
}
}
Node[] nodes = archive.changeLog();
Version[] versions = new Version[nodes.length];
for (int i=0;i<nodes.length;i++) {
versions[i] = nodes[i].getVersion();
}
return versions;
}
} catch (Exception e) {
Object[] args = { doc.getFullName() };
throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_RCS_READING_REVISIONS,
"Exception while reading document {0} revisions", e, args);
}
}
public String getFullContent(XWikiDocument doc, XWikiContext context) {
return doc.toXML(context);
}
public String getMetaFullContent(XWikiDocument doc) {
StringBuffer buf = new StringBuffer();
getMetaFullContent(doc, buf);
return buf.toString();
}
public void getMetaFullContent(XWikiDocument doc, StringBuffer buf) {
getMetaData(doc, buf);
getContent(doc, buf);
}
public void getContent(XWikiDocument doc, StringBuffer buf) {
buf.append(doc.getContent());
}
public void getMetaData(XWikiDocument doc, StringBuffer buf) {
buf.append("%META:TOPICINFO{");
addField(buf, "author", doc.getAuthor());
addField(buf, "date", "" + doc.getDate().getTime());
addField(buf, "version", doc.getVersion().toString());
addField(buf, "format", doc.getFormat());
buf.append("}%\n");
buf.append("%META:TOPICPARENT{");
addField(buf, "name", doc.getParent());
buf.append("}%\n");
String meta = doc.getMeta();
if (meta!=null)
buf.append(doc.getMeta());
}
public void addField(StringBuffer buf,String name, String value) {
buf.append(name);
buf.append("=\"");
value = (value==null) ? "" : value;
buf.append(Util.cleanValue(value));
buf.append("\" ");
}
public static boolean parseMetaData(XWikiDocument doc, String line) throws IOException {
if (!line.startsWith("%META:"))
return false;
if (line.startsWith("%META:TOPICINFO{")) {
String line2 = line.substring(16, line.length() - 2);
Hashtable params = Util.keyValueToHashtable(line2);
Object author = params.get("author");
if (author!=null)
doc.setAuthor((String)author);
Object format = params.get("format");
if (format!=null)
doc.setFormat((String)format);
Object version = params.get("version");
if (version!=null)
doc.setVersion((String) version);
Object language = params.get("language");
if (language!=null)
doc.setLanguage((String) language);
Object defaultLanguage = params.get("defaultLanguage");
if (defaultLanguage!=null)
doc.setDefaultLanguage((String) defaultLanguage);
Object date = params.get("creationDate");
if (date!=null) {
long l = Long.parseLong((String)date);
doc.setCreationDate(new Date(l));
}
date = params.get("date");
if (date!=null) {
long l = Long.parseLong((String)date);
doc.setDate(new Date(l));
}
} else if (line.startsWith("%META:TOPICPARENT{")) {
String line2 = line.substring(18, line.length() - 2);
Hashtable params = Util.keyValueToHashtable(line2);
Object parent = params.get("name");
if (parent!=null)
doc.setParent((String)parent);
} else {
doc.appendMeta(line);
}
return true;
}
public List getClassList(XWikiContext context) throws XWikiException {
throw new XWikiException( XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_NOT_IMPLEMENTED,
"Not implemented");
}
public List searchDocumentsNames(String wheresql, int nb, int start, String selectColumns, XWikiContext context) throws XWikiException {
throw new XWikiException( XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_NOT_IMPLEMENTED,
"Not implemented");
}
public List searchDocuments(String wheresql, boolean distinctbylanguage, int nb, int start, XWikiContext context) throws XWikiException {
throw new XWikiException( XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_NOT_IMPLEMENTED,
"Not implemented");
}
public void deleteXWikiAttachment(XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException {
try {
File file = getAttachmentPath(attachment, context);
if (file.exists())
file.delete();
file = getVersionedAttachmentPath(attachment, context);
if (file.exists())
file.delete();
if (bTransaction) {
List list = attachment.getDoc().getAttachmentList();
for (int i=0;i<list.size();i++) {
XWikiAttachment attach = (XWikiAttachment) list.get(i);
if (attachment.getFilename().equals(attach.getFilename())) {
list.remove(i);
break;
}
}
saveXWikiDoc(attachment.getDoc(), context, false);
}
} catch (Exception e) {
Object[] args = { attachment.getFilename(), attachment };
throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_RCS_DELETING_ATTACHMENT,
"Exception while deleting attachment {0} from document {1}", e, args);
}
}
public XWikiLock loadLock(long docId, XWikiContext context, boolean bTransaction) throws XWikiException {
throw new XWikiException( XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_NOT_IMPLEMENTED,
"Not implemented");
}
public void saveLock(XWikiLock lock, XWikiContext context, boolean bTransaction) throws XWikiException {
throw new XWikiException( XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_NOT_IMPLEMENTED,
"Not implemented");
}
public void deleteLock(XWikiLock lock, XWikiContext context, boolean bTransaction) throws XWikiException {
throw new XWikiException( XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_NOT_IMPLEMENTED,
"Not implemented");
}
public void saveAttachmentContent(XWikiAttachment attachment, boolean bParentUpdate, XWikiContext context, boolean bTransaction) throws XWikiException {
try {
File file = getAttachmentPath(attachment, context);
FileOutputStream os = new FileOutputStream(file);
os.write(attachment.getContent(context));
os.flush();
os.close();
// Now handle the versioned file
if (attachment.isContentDirty()) {
File vfile = getVersionedAttachmentPath(attachment, context);
attachment.updateContentArchive(context);
Archive archive = attachment.getArchive();
archive.save(vfile.toString());
}
// We need to save the attachment info
if (bParentUpdate)
saveXWikiDoc(attachment.getDoc(), context, false);
} catch (Exception e) {
Object[] args = { attachment.getFilename(), attachment };
throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_RCS_SAVING_ATTACHMENT,
"Exception while saving attachment {0} from document {1}", e, args);
}
}
public void saveAttachmentContent(XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException {
saveAttachmentContent(attachment, true, context, bTransaction);
}
public void loadAttachmentContent(XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException {
try {
byte[] content = new byte[attachment.getFilesize()];
File file = getAttachmentPath(attachment, context);
FileInputStream is = new FileInputStream(file);
is.read(content);
attachment.setContent(content);
} catch (Exception e) {
Object[] args = { attachment.getFilename(), attachment };
throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_RCS_LOADING_ATTACHMENT,
"Exception while reading document {0} version {1}", e, args);
}
}
public void loadAttachmentArchive(XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException {
try {
Archive archive = attachment.getArchive();
if (archive==null) {
File file = getVersionedAttachmentPath(attachment, context);
String path = file.toString();
try {
synchronized (path) {
archive = new Archive(path);
attachment.setArchive(archive);
}
} catch (FileNotFoundException e) {
}
}
} catch (Exception e) {
Object[] args = { attachment.getFilename(), attachment };
throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_RCS_LOADING_ATTACHMENT,
"Exception while reading document {0} version {1}", e, args);
}
}
public List search(String sql, int nb, int start, XWikiContext context) throws XWikiException {
throw new XWikiException( XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_NOT_IMPLEMENTED,
"Not implemented");
}
public List search(String sql, int nb, int start, Object[][] whereParams, XWikiContext context) throws XWikiException {
throw new XWikiException( XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_NOT_IMPLEMENTED,
"Not implemented") ;
}
public void cleanUp(XWikiContext context) {
}
public void createWiki(String wikiName, XWikiContext context) throws XWikiException {
// Nothing to do
}
public boolean exists(XWikiDocument doc, XWikiContext context) {
doc.setStore(this);
File file = getFilePath(doc, context);
return file.exists();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -