深入浅出 jackrabbit 三 创建 document
2009-09-17 00:00:00 来源:WEB开发网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;
}
Tags:深入浅出 jackrabbit 创建
编辑录入:爽爽 [复制链接] [打 印]- ››创建SQL2005自动备份,定期删除的维护计划
- ››创建动态表单 javascript
- ››深入浅出实战攻防恶意PDF文档
- ››创建基于PPTP的站点到站点VPN连接:ISA2006系列之...
- ››创建基于L2TP的站点到站点的VPN连接:ISA2006系列...
- ››创建一个Twisted Reactor TCP服务器
- ››创建Windows Mobile上兼容性好的UI 程序
- ››创建android的Service
- ››创建远古部落环境与原住民角色
- ››创建并扩展Apache Wicket Web应用
- ››创建不在任务条中显示窗口按钮的应用
- ››创建 Android 文件系统(Root file system)
更多精彩
赞助商链接