如何使用Spring应用程序中的OpenCMIS在Alfresco中查找模板?

如何使用Spring应用程序中的OpenCMIS在Alfresco中查找模板?,spring,templates,alfresco,opencmis,Spring,Templates,Alfresco,Opencmis,我在Spring3.1应用程序中工作,需要在Alfresco的存储库中找到一个字符串模板文档。我已经可以用OpenCMIS在alfresco中创建一个文件,但是我不知道如何找到模板,所以如果有人知道如何做或者给我举个例子,请让我知道,提前谢谢 您可以使用许多选项。首先,您需要有一个唯一标识文档的标准。下面我将展示一些,希望你的案例属于其中之一,或者它们将激励你找到一个合适的解决方案。下面使用的是伪代码,请查看用于使用Java客户端API的 按ID分类 通过CMIS创建文档后,您将获得文档的唯一I

我在Spring3.1应用程序中工作,需要在Alfresco的存储库中找到一个字符串模板文档。我已经可以用OpenCMIS在alfresco中创建一个文件,但是我不知道如何找到模板,所以如果有人知道如何做或者给我举个例子,请让我知道,提前谢谢

您可以使用许多选项。首先,您需要有一个唯一标识文档的标准。下面我将展示一些,希望你的案例属于其中之一,或者它们将激励你找到一个合适的解决方案。下面使用的是伪代码,请查看用于使用Java客户端API的

按ID分类

通过CMIS创建文档后,您将获得文档的唯一ID,可以将其存储在应用程序中供以后检索

Map<String, Object> templateProperties = createDocumentProperties();
Folder folder = getTemplatesFolder();
ObjectId templateId = createTemplateIn(folder);
storeTemplateId(templateId.getId(), templateProperties); // persist the ID
...
// later on
...
String id = getTemplateId(); // retrieve the ID
Session session = openCMISSession();
Document template = (Document)session.getObject(id);
按属性值划分

比方说,您可以在模板文档上使用特定的元数据字段,以便在以后轻松检索它(例如,您为您的用例创建了一些特定的元数据字段)

String meta=TemplateProperties.TEMPLATE_ID;//e、 g.my:templateId
字符串类型=TemplateProperties.TEMPLATE_type;//e、 g.我的:模板
字符串templateMeta=“TEMPLATE1”;
Map templateProperties=createDocumentProperties();
put(meta,templateMeta);
templateProperties.put(PropertyIds.OBJECT\u TYPE\u ID,TYPE);
createTemplate(templateProperties);
...
//后来
...
字符串类型=TemplateProperties.TEMPLATE_type;//e、 g.我的:模板
字符串meta=TemplateProperties.TEMPLATE\u ID;
字符串tplId=“TEMPLATE1”;
字符串查询=String.format(“从%WHERE%='%'中选择*,类型,元,tplId”);
ItemIterable i=session.query(query,false);
QueryResult qr=i.iterator().next();//假设我们只有一场比赛
String templateId=qr.getPropertyQueryName(“cmis:objectId”).getFirstValue()
文档模板=(文档)会话.getObject(templateId);
按查询


前面的方法实际上与按属性名称搜索无关,可以轻松地扩展到使用任何类型的查询来标识模板。查看Alfresco页面的实现细节,了解更多查询存储库的方法。

感谢dude的解释,这就是我要做的。。现在我已经有了文档,您知道我应该使用会话对象的什么方法吗?这样我就可以以字符串模板可以理解的格式检索文档了?您的意思是?这可能值得一个单独的问题,因为这更多的是关于查找资料的主题。好的,我将打开另一个问题,感谢您的回答,干杯!希望有帮助!如果您觉得答案有用,请接受;-)
String path = getTemplatePath(); // either recover it from DB or construct a path
Document template = (Document)session.getObjectByPath(path);
String meta = TemplateProperties.TEMPLATE_ID; // e.g. my:templateId
String type = TemplateProperties.TEMPLATE_TYPE; // e.g. my:template
String templateMeta = "TEMPLATE1";
Map<String, Object> templateProperties = createDocumentProperties();
templateProperties.put(meta, templateMeta);
templateProperties.put(PropertyIds.OBJECT_TYPE_ID, type);
createTemplate(templateProperties);
...
// later on
...
String type = TemplateProperties.TEMPLATE_TYPE; // e.g. my:template
String meta = TemplateProperties.TEMPLATE_ID;
String tplId = "TEMPLATE1";
String query = String.format("SELECT * FROM % WHERE % = '%'", type, meta, tplId);
ItemIterable<QueryResult> i = session.query(query, false);
QueryResult qr = i.iterator().next(); // let's assume we have one single match
String templateId = qr.getPropertyByQueryName("cmis:objectId").getFirstValue()
Document template = (Document)session.getObject(templateId);