1.二进制文件的存储
Node root = session.getRootNode();
Node smartnote = root.getNode("smartnote");
note = smartnote.addNode("note");
filenode = note.addNode("file", "nt:file");
note.setProperty("utccreatetime", CommonUtils
.parseString(new Date(), 5));
resnode = filenode
.addNode("jcr:content", "nt:resource");
MimeTable mt = MimeTable.getDefaultTable();
String mimeType = mt.getContentTypeFor(file.getName());
//注意默认mimetype不好用,需要自己写,mimetype必须正确,否则全文检索不能用
if (mimeType == null) {
mimeType = SmartUtils.getFileMimeType(filename);
}
System.out.println(mimeType);
resnode.setProperty("jcr:mimeType", mimeType);
resnode.setProperty("jcr:encoding", "");
ote.setProperty("title", input.getName());
Calendar lastModified = Calendar.getInstance();
lastModified.setTimeInMillis(file.lastModified());
resnode.setProperty("jcr:lastModified", lastModified);
resnode.setProperty("jcr:data", new FileInputStream(file));
note.setProperty("utcupdatetime", CommonUtils.parseString(
new Date(), 5));
note.addMixin("mix:referenceable");
note.addMixin("mix:versionable");
session.save();
2.全文检索
QueryManager qm = session.getWorkspace().getQueryManager();
String path2 = "//smartnote/note/element(*, nt:file)[(jcr:contains(jcr:content, '"+key+"'))]";
Query query = qm.createQuery(path1, Query.XPATH);
QueryResult result = query.execute();
NodeIterator ir = result.getNodes();
3.内容读取
Node node = session.getNodeByUUID(input.getUuid());
Node filenode = node.getNode("file");
InputStream in = filenode.getNode("jcr:content")
.getProperty("jcr:data").getStream();
String filename = SmartUtils.getTempPath() + "/"
+ this.getEditorInput().getName() + ".doc";
File file = new File(filename);
OutputStream os = new FileOutputStream(file);
byte buf[] = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
os.write(buf, 0, len);
}
os.close();
in.close();
Node root = session.getRootNode();
Node smartnote = root.getNode("smartnote");
note = smartnote.addNode("note");
filenode = note.addNode("file", "nt:file");
note.setProperty("utccreatetime", CommonUtils
.parseString(new Date(), 5));
resnode = filenode
.addNode("jcr:content", "nt:resource");
MimeTable mt = MimeTable.getDefaultTable();
String mimeType = mt.getContentTypeFor(file.getName());
//注意默认mimetype不好用,需要自己写,mimetype必须正确,否则全文检索不能用
if (mimeType == null) {
mimeType = SmartUtils.getFileMimeType(filename);
}
System.out.println(mimeType);
resnode.setProperty("jcr:mimeType", mimeType);
resnode.setProperty("jcr:encoding", "");
ote.setProperty("title", input.getName());
Calendar lastModified = Calendar.getInstance();
lastModified.setTimeInMillis(file.lastModified());
resnode.setProperty("jcr:lastModified", lastModified);
resnode.setProperty("jcr:data", new FileInputStream(file));
note.setProperty("utcupdatetime", CommonUtils.parseString(
new Date(), 5));
note.addMixin("mix:referenceable");
note.addMixin("mix:versionable");
session.save();
2.全文检索
QueryManager qm = session.getWorkspace().getQueryManager();
String path2 = "//smartnote/note/element(*, nt:file)[(jcr:contains(jcr:content, '"+key+"'))]";
Query query = qm.createQuery(path1, Query.XPATH);
QueryResult result = query.execute();
NodeIterator ir = result.getNodes();
3.内容读取
Node node = session.getNodeByUUID(input.getUuid());
Node filenode = node.getNode("file");
InputStream in = filenode.getNode("jcr:content")
.getProperty("jcr:data").getStream();
String filename = SmartUtils.getTempPath() + "/"
+ this.getEditorInput().getName() + ".doc";
File file = new File(filename);
OutputStream os = new FileOutputStream(file);
byte buf[] = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
os.write(buf, 0, len);
}
os.close();
in.close();