WEB开发网
开发学院软件开发Java 深入浅出 jackrabbit 三 创建 document 阅读

深入浅出 jackrabbit 三 创建 document

 2009-09-17 00:00:00 来源:WEB开发网   
核心提示: Java代码protectedDocumentcreateDoc()throwsRepositoryException{Documentdoc=newDocument();doc.setBoost(getNodeBoost());//specialfields//UUID//代码第一段,负责添加

Java代码   

protected Document createDoc() throws RepositoryException { 
    Document doc = new Document(); 
 
    doc.setBoost(getNodeBoost()); 
 
    // special fields 
    // UUID 
//代码第一段,负责添加一些固定的field到document中,uuid,parent,label 
    doc.add(new Field(FieldNames.UUID, node.getNodeId().getUUID().toString(), Field.Store.YES, Field.Index.NO_NORMS, Field.TermVector.NO)); 
    try { 
      // parent UUID 
      if (node.getParentId() == null) { 
        // root node 
        doc.add(new Field(FieldNames.PARENT, "", Field.Store.YES, Field.Index.NO_NORMS, Field.TermVector.NO)); 
        doc.add(new Field(FieldNames.LABEL, "", Field.Store.NO, Field.Index.NO_NORMS, Field.TermVector.NO)); 
      } else { 
        doc.add(new Field(FieldNames.PARENT, node.getParentId().toString(), Field.Store.YES, Field.Index.NO_NORMS, Field.TermVector.NO)); 
        NodeState parent = (NodeState) stateProvider.getItemState(node.getParentId()); 
        NodeState.ChildNodeEntry child = parent.getChildNodeEntry(node.getNodeId()); 
        if (child == null) { 
          // this can only happen when jackrabbit 
          // is running in a cluster. 
          throw new RepositoryException("Missing child node entry " + 
              "for node with id: " + node.getNodeId()); 
        } 
        String name = resolver.getJCRName(child.getName()); 
        doc.add(new Field(FieldNames.LABEL, name, Field.Store.NO, Field.Index.NO_NORMS, Field.TermVector.NO)); 
      } 
    } catch (NoSuchItemStateException e) { 
      throwRepositoryException(e); 
    } catch (ItemStateException e) { 
      throwRepositoryException(e); 
    } catch (NamespaceException e) { 
      // will never happen, because this.mappings will dynamically add 
      // unknown uri<->prefix mappings 
    } 
/////////////////////////代码第二段,负责添加一个node的property到document中。 
    Set props = node.getPropertyNames(); 
    for (Iterator it = props.iterator(); it.hasNext();) { 
      Name propName = (Name) it.next(); 
      PropertyId id = new PropertyId(node.getNodeId(), propName); 
//遍历node的property并一一创建field 
      try { 
        PropertyState propState = (PropertyState) stateProvider.getItemState(id); 
         
        // add each property to the _PROPERTIES_SET for searching 
        // beginning with V2 
        if (indexFormatVersion.getVersion() 
            >= IndexFormatVersion.V2.getVersion()) {   
  //添加field:_:PROPERTIES_SET 
          addPropertyName(doc, propState.getName()); 
        } 
        //得到property的values,准备一个个value做field 
        InternalValue[] values = propState.getValues(); 
        for (int i = 0; i < values.length; i++) { 
   //一个尤其需要注意的方法,该方法中会根据value的类型//创建不同的filed。 
          addValue(doc, values[i], propState.getName()); 
        } 
        if (values.length > 1) { 
          // real multi-valued 
          addMVPName(doc, propState.getName()); 
        } 
      } catch (NoSuchItemStateException e) { 
        throwRepositoryException(e); 
      } catch (ItemStateException e) { 
        throwRepositoryException(e); 
      } 
    } 
    return doc; 
  }

上一页  1 2 3 4 5 6 7  下一页

Tags:深入浅出 jackrabbit 创建

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接