jackrabbit注入到spring中的基本操作

1、获取JCR操作会话对象
 public Session createJCRSession(){
  Session sion = null;
  try {
   sion = template.getSessionFactory().getSession();
  } catch (RepositoryException e) {
   _log.error("获取JCR操作会话对象失败:", e);
  }
  return sion;
 }

2、判断节点是否存在
 public boolean existsNode(Session sion, String nodePath){
  boolean ret = false;
  try {
   ret = sion.nodeExists(nodePath);
  } catch (RepositoryException e) {
   _log.error("判断节点【" + nodePath + "】是否存在失败:", e);
  }
  _log.debug("节点【" + nodePath + "】是否存在:【" + ret + "】。");
  return ret;
 }

3、保存JCR操作结果

public void saveJCRSession(Session sion){
  try {
   sion.save();
  } catch (Exception e) {
   _log.error("保存JCR操作会话对象失败:", e);
  }
 }

4、关闭JCR操作会话对象

public void closeJCRSession(Session sion){
  if(null != sion)
   sion.logout();
 }

5、按照路径存储文件

public void writerBinProperty(Node inode, String filePath){
  String inodeName = "";
  try {
   ValueFactory vfactory = template.getValueFactory();
   inodeName = inode.getName();
   File file = new File(filePath);
   MimeTable mt = MimeTable.getDefaultTable();
   String mimeType = mt.getContentTypeFor(file.getName());
   if(mimeType==null)
    mimeType = "application/octet-stream";
   inode.setProperty("jcr:mimeType", mimeType);
   inode.setProperty("jcr:data", vfactory.createBinary(new FileInputStream(file))); 
  } catch (Exception e) {
   _log.error("在节点【" + inodeName + "】上增加文件【" + filePath + "】失败:", e);
  }
 }

6、使用节点读取文件

public byte[] readBinProperty(Node inode){
  String inodeName = "";
  byte[] retby = null;
  try{
   inodeName = inode.getName();
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   Binary bin = inode.getProperty("jcr:data").getBinary();
   byte[] buf = new byte[0x1000];
   for (int cnt, pos = 0; (cnt = bin.read(buf, pos)) > 0; pos += cnt) {
     out.write(buf, 0, cnt);
   }
   retby = out.toByteArray();
  } catch (Exception ex) {
   _log.error("在节点【" + inodeName + "】上获取文件信息时失败:", ex);
  }
  return retby;
 }

7、获取节点上的自定义信息

public String readProperty(Node inode) {
  StringBuffer propStr = new StringBuffer();
  try {
   PropertyIterator itor = inode.getProperties();
   while(itor.hasNext()){
    Property porp = itor.nextProperty();
    if(porp.getName().startsWith("test"))
     propStr.append(porp.getName);
   }
  } catch (RepositoryException e) {
   try {
    _log.error("获取节点【" + inode.getName() + "】上的属性失败:", e);
   } catch (RepositoryException e1) {
    _log.error("获取节点信息异常:", e1);
   }
  }
  return propStr.toString();
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提示错误[ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] Unresolveable build extension: Plugin org.apache.maven.wagon:wagon-webdav-jackrabbit:1.0-beta-6 or one of its dependencies could not be resolved: The following artifacts could not be resolved: commons-httpclient:commons-httpclient:jar:3.1 (absent): Could not transfer artifact commons-httpclient:commons-httpclient:jar:3.1 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/146.75.112.215] failed: connect timed out @ @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project org.drools:droolsjbpm-integration:7.74.0-SNAPSHOT (D:\droolsjbpm-integration-main\droolsjbpm-integration-main\pom.xml) has 1 error [ERROR] Unresolveable build extension: Plugin org.apache.maven.wagon:wagon-webdav-jackrabbit:1.0-beta-6 or one of its dependencies could not be resolved: The following artifacts could not be resolved: commons-httpclient:commons-httpclient:jar:3.1 (absent): Could not transfer artifact commons-httpclient:commons-httpclient:jar:3.1 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/146.75.112.215] failed: connect timed out -> [Help 2] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/PluginManagerException
06-09

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值