ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 通过单击操作创建 IBM Lotus Web Content Management 站点结构

通过单击操作创建 IBM Lotus Web Content Management 站点结构

原创 Linux操作系统 作者:genusBIT 时间:2009-12-30 10:39:31 0 删除 编辑
转自:http://www.ibm.com/developerworks/cn/lotus/wcm-structure/index.html

简介

如果您使用 IBM Lotus Web Content Management 的话,一个经常出现的任务就是定义站点结构。这个任务本身是重复的并且十分耗时;您必须采取 10 多个不同的步骤来创建一个站点或站点区域。而且,站点结构被有意设计为不可移植;您无法将站点结构从一个服务器上的某个库导出到另一个服务器上的不同库。 相反,您需要手动重新创建整个站点结构。

由于构成单一站点结构的站点和站点区域数可能会达到数千个,因此您需要一种方法来自动化完成站点结构的定义并使它易于迁移、导出和导入。在本文中,您将学习一种简单的方法来将站点结构定义为一个 XML 文件并进行相应的部署。

先决条件

您应当熟悉以下这些技术:

  • IBM WebSphere® Portal V6.0 和更高版本,以及它的管理和组件
  • IBM Lotus Web Content Management
  • XML

为 了演示如何在 Lotus Web Content Management 中创建站点结构且无需手动创建所有站点和站点区域,本文使用 Lotus Web Content Management API 和一个包含站点结构的 XML 文件。您可以通过针对本文下载部分提供的 XML 模式对包含站点结构的 XML 文件进行验证来创建它。XML 模式将验证结构和必要字段来预防运行时错误。

您可以定义许多站点、站点区域和默认内容来在包含完整站点结构的 XML 文档中创建站点结构。首先,创建下面这些必要部件:

  • Lotus Web Content Management 库
  • 将在站点结构中使用的编写模板
  • 将在站点结构中使用的演示模板
  • 将在安全设置部分中使用的用户
  • 将在编写模板中使用的工作流、工作流操作和工作流阶段

然 后,以 XML 文件的形式定义站点结构,指定库、站点、站点区域等等。为了确保提供的信息足够用于在 Lotus Web Content Management 中创建站点,XML 文件根据本文下载部分提供的 XSD 文件中定义的模式进行构建。XSD 文件包含创建完整站点结构所需的所有验证,以及包含某些字段的默认内容。

您可以创建一个 JSP 组件来解析 XML 文件并创建其中定义的站点区域。

实现

在这个小节中,我们将描述实现解决方案所需的步骤。我们首先将讨论如何创建 XML 文件和 XSD 文件,随后讨论用于解析文件的 JSP 组件。

XML 创建

XML 文件包含创建站点结构的所有信息。它包含库名、站点结构、站点区域结构和默认内容。需要在与您的需求相对应的结构中创建一个 XML 文件。参见清单 1 中的 XML 示例,它与图 1 所示的站点结构相对应。



站点结构

站点结构由一个站点区域组成;这个站点区域反过来又由另一个站点区域组成。



xsi:noNamespaceSchemaLocation="SiteCreation.xsd">




auth_news
pt_newsDetail



[all authenticated portal users]
anonymous portal user




Default_News
Default_News
auth_news

txt_headline
Headline for default Content


rtf_body
Body for the default Content




Default_News
Default_News
auth_news

txt_headline
Headline for default Content


rtf_body
Body for the default Content





Default_News




auth_news
pt_newsDetail



[all authenticated portal users]
anonymous portal user




文档选项

未显示需要 JavaScript. 的文档选项

<!-- document.write(''); //--> <!-- document.write(''); //-->
将打印机的版面设置成横向打印模式

打印本页

将打印机的版面设置成横向打印模式

打印本页

将此页作为电子邮件发送

将此页作为电子邮件发送

将此页作为电子邮件发送

将此页作为电子邮件发送

讨论

样例代码

英文原文

英文原文


级别: 中级

Hebba Soliman, 高级软件工程师, IBM
Ahmed Khairy, IT 专家, IBM

2009 年 12 月 29 日

了解一种使您能够以自动化方式在 IBM® Lotus® Web Content Management 中定义站点结构的简单解决方案。这个解决方案使您能够节省花在既耗时又沉闷的任务上面的时间。

编辑注:您很精通这个主题吗?希望分享您的经验吗?请马上加入到 IBM Lotus 软件 wiki 项目。

Lotus Web Content Management wiki

简介

如 果您使用 IBM Lotus Web Content Management 的话,一个经常出现的任务就是定义站点结构。这个任务本身是重复的并且十分耗时;您必须采取 10 多个不同的步骤来创建一个站点或站点区域。而且,站点结构被有意设计为不可移植;您无法将站点结构从一个服务器上的某个库导出到另一个服务器上的不同库。 相反,您需要手动重新创建整个站点结构。

由于构成单一站点结构的站点和站点区域数可能会达到数千个,因此您需要一种方法来自动化完成站点结构的定义并使它易于迁移、导出和导入。在本文中,您将学习一种简单的方法来将站点结构定义为一个 XML 文件并进行相应的部署。





回页首


先决条件

您应当熟悉以下这些技术:

  • IBM WebSphere® Portal V6.0 和更高版本,以及它的管理和组件
  • IBM Lotus Web Content Management
  • XML

为 了演示如何在 Lotus Web Content Management 中创建站点结构且无需手动创建所有站点和站点区域,本文使用 Lotus Web Content Management API 和一个包含站点结构的 XML 文件。您可以通过针对本文下载部分提供的 XML 模式对包含站点结构的 XML 文件进行验证来创建它。XML 模式将验证结构和必要字段来预防运行时错误。

您可以定义许多站点、站点区域和默认内容来在包含完整站点结构的 XML 文档中创建站点结构。首先,创建下面这些必要部件:

  • Lotus Web Content Management 库
  • 将在站点结构中使用的编写模板
  • 将在站点结构中使用的演示模板
  • 将在安全设置部分中使用的用户
  • 将在编写模板中使用的工作流、工作流操作和工作流阶段

然 后,以 XML 文件的形式定义站点结构,指定库、站点、站点区域等等。为了确保提供的信息足够用于在 Lotus Web Content Management 中创建站点,XML 文件根据本文下载部分提供的 XSD 文件中定义的模式进行构建。XSD 文件包含创建完整站点结构所需的所有验证,以及包含某些字段的默认内容。

您可以创建一个 JSP 组件来解析 XML 文件并创建其中定义的站点区域。





回页首


实现

在这个小节中,我们将描述实现解决方案所需的步骤。我们首先将讨论如何创建 XML 文件和 XSD 文件,随后讨论用于解析文件的 JSP 组件。

XML 创建

XML 文件包含创建站点结构的所有信息。它包含库名、站点结构、站点区域结构和默认内容。需要在与您的需求相对应的结构中创建一个 XML 文件。参见清单 1 中的 XML 示例,它与图 1 所示的站点结构相对应。



站点结构

站点结构由一个站点区域组成;这个站点区域反过来又由另一个站点区域组成。



xsi:noNamespaceSchemaLocation="SiteCreation.xsd">




auth_news
pt_newsDetail



[all authenticated portal users]
anonymous portal user




Default_News
Default_News
auth_news

txt_headline
Headline for default Content


rtf_body
Body for the default Content




Default_News
Default_News
auth_news

txt_headline
Headline for default Content


rtf_body
Body for the default Content





Default_News




auth_news
pt_newsDetail



[all authenticated portal users]
anonymous portal user






图 2 展示了 XML 元素和实现解决方案后生成的输出之间的样例映射。


图 2. XML 与 Lotus Web Content Management 对象和区段之间的映射
XML 与 Lotus Web Content Management 对象和区段之间的映射

如您所见,实际站点结构与 XML 文件之间的映射非常简单,具有一个表示库的根元素。这个根元素随后包含另一个与站点对应的元素,定义它的名称并显示名称。站点区域以嵌套方式在 XML 文件中定义,用于获得必需的站点结构。

每个站点和站点区域都包含一个设置区段,其中包含安全设置和模板映射区段。下面是必须加以考虑的限制因素:安全设置和模板映射可以在各自的元素或树中的最高级别的站点或站点区域中针对每个站点或站点区域创建,并且其子元素将从父元素中继承。

内容安全设置和工作流被添加到编写模板组件中,而不是 XML 文件中的默认内容区段中。

模板映射和默认内容创建中使用的编写模板和演示模板必须提前创建。

通过定义默认内容的名称,默认内容可以在多个站点区域中重用。当您在 XML 文件中定义了完整的默认内容元素后,您可以通过定义一个只包含名称元素的默认内容标记来使用它。如果默认内容已经存在于库中,也可以使用在多个不同位置重用默认内容这一特性。





回页首


XML 模式验证

如前所述,为了避免丢失 Lotus Web Content Management 用于站点创建的数据,您需要使 XML 文件遵从一个 XSD 文件。这种遵从性可以保证表 1 中列出的验证是有效的。


表 1. XML 模式元素/属性验证
元素元素/属性类型有效范围值
LibrarySites 元素0..nNA
LibraryName属性必要字符串
SiteSiteArea元素0..nNA
SiteName属性必要字符串
SiteDisplayName属性可选字符串
SiteSettings元素可选NA
SiteAreaSiteArea元素0..nNA
SiteAreaName属性必要字符串
SiteAreaDisplayName属性可选字符串
SiteAreaSettings元素可选NA
SiteAreaDefaultContent元素可选NA
DefaultContentName元素必要NA
DefaultContentDisplayName元素可选NA
DefaultContentAuthoringTemp元素可选(如果已定义了项的话)NA
DefaultContentTextComponent元素0..nNA
DefaultContentRichTextComponent元素可选NA
TextComponentFieldName元素必要(像在编写模板中一样引用 Lotus Web Content Management TextComponent 字段名)NA
TextComponentTextComponent元素必要NA
TextComponentFieldName元素必要(像在编写模板中一样引用 Lotus Web Content Management RichTextComponent 字段名)NA
TextComponentTextComponent元素必要NA
SettingsTemplateMapping元素0..nNA
SettingsSecuritySettings元素可选NA
TemplateMappingAuthoringTemp元素必要(引用 Lotus Web Content Management 编写模板名)NA
TemplateMappingPresentationTemp元素必要(引用 Lotus Web Content Management 演示模板)NA
SecuritySettingsAccessRight元素0..nNA
AccessRightType属性必要addReadAccessMembers/
addEditAccessMembers
or
addDeleteAccessMembers
AccessRightAccess元素1..nNA

JSP 组件

您 已经在一个遵循 XSD 的 XML 文件中定义了您的站点结构,现在需要创建一个 JSP 组件来处理对 XML 文件的解析,并使用 Lotus Web Content Management API 将站点结构导入到 Lotus Web Content Management 库来执行实际的 Lotus Web Content Management 站点创建工作。

选择 New - JSP 组件。使用名称 jsp_createSiteStructure 创建 JSP 组件,然后将其指向路径为 /jsp/html/createSiteStructure.jsp 的 JSP 文件。将您的 JSP 组件存储在本地 Rendering portlet 中。这个 JSP 文件的物理路径位于一个目录中,类似清单 2 中的代码。



\installedApps\
WCM_Local_ng_Portlet_PA_dvme0nk.ear\PA_dvme0nk.war\jsp\html\
createSiteStructure.jsp

JSP 文件创建了一个称为 Create Site Structure 的按钮,单击此按钮时将开始解析 XML 文件,首先将解析每一个站点。XML 文件的路径现在可以进行编辑。清单 3 中的文件被认为位于与 JSP 文件相同的位置。代码将进入工作空间并连接到文件中的定义的库。参见清单 3 中的代码。



<%@page language="java" contentType="text/html; 
charset=UTF-8" pageEncoding="UTF-8"%>
.
.
.
<%@ include file="wcmUtil.jsp"%>






<%

try {

//if button clicked
if( request.getParameter("buttonName") !=
null && request.getParameter("buttonName").equals("CreateSiteStructure")) {

//path to the XML file containing the site structure
File file = newFile("/opt/app/WebSphere/PortalServer/installedApps/WCM_Local_ng_
Portlet_PA_dm010y1.ear/dm010y1.war/jsp/html/NewsSiteStructure.xml");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);

doc.getDocumentElement().normalize();

Element docEle = doc.getDocumentElement();
String libraryName = docEle.getAttribute("Name");

System.out.println("libraryName = " +libraryName);
workspace = openWorkspaceLibrary(request, libraryName);

//retrieve all site elements
NodeList nl = docEle.getElementsByTagName("Site");

//loop over site elements
if(nl != null) {
for(int i = 0 ; i < nl.getLength();i++) {

Element el = (Element)nl.item(i);
Site site = createSite(el);

DocumentId siteId = site.getId();
System.out.println("site = "+ site.getName());

//for every site element, retrieve site area child elements
NodeList SiteAreaNodeList = el.getChildNodes();
for (Node node = el.getFirstChild(); node != null;
node = node.getNextSibling()) {
if (node.getNodeType() == Node.ELEMENT_NODE &&
node.getNodeName().equals("SiteArea")) {
Element siteAreaEL = (Element)node;

SiteArea sa = createSiteArea(siteAreaEL, siteId);
if (sa != null){
System.out.println("site area = " + sa.getName());
}
else{
out.println("Error in creation of site area tree,
check logs for more information about the error");
}
}
}
}
}
closeWorkspace();
out.println("Cretion Completed");
}
}catch(FileNotFoundException e){
out.println("XML File not found!");
}catch (org.xml.sax.SAXParseException saxEx){
out.println("Exception In parsing document: "+ saxEx.getMessage());
}
catch (Exception e) {
System.out.println("Exception: "+ e.getClass());
e.printStackTrace();
}
%>

这里使用了一个实用类,它包含了 JSP 代码中用来创建站点结构的所有 helper 方法。基于本文的目的,可以创建一个名为 wcmUtil.jsp 的 JSP 组件来包含所有这些方法。这个 JSP 组件被包含在 createSiteStructure.jsp 中,如清单 3 所示,使用其中的 <%@ include file="wcmUtil.jsp"%>。

清单 4 - 20 展示了在 helper 类中用于创建站点结构的方法。



private Workspace workspace;
/*
*Connect to Lotus Web Content Management workspace with current user if
*logged in or anonymous if user is not logged in
*
*Set the Lotus Web Content Management document library to aLibraryName
*/
public Workspace openWorkspaceLibrary(HttpServletRequest request, String aLibraryName)
throws ServiceNotAvailableException, OperationFailedException {
// Connect to WCM Workspace
if (request.getUserPrincipal() != null)
{
workspace = WCM_API.getRepository().getWorkspace
(request.getUserPrincipal());
} else
{
workspace = WCM_API.getRepository().getAnonymousWorkspace();
}

//set library to the passed library name
if (workspace != null) {
DocumentLibrary docLib = workspace.getDocumentLibrary
(aLibraryName);
if(docLib != null){
workspace.setCurrentDocumentLibrary(docLib);
}
}

return workspace;
}



/*
*Parse site element
*If site already available, retrieve the site object, edit the site
*If site not already created, create a new site and set the name and
*display name and its settings
*Save the site to the workspace
*/
public Site createSite(Element aSiteElement){

String siteName = aSiteElement.getAttribute("Name");
String siteDisplayName = aSiteElement.getAttribute("DisplayName");
Site site = null;
try{

DocumentId siteId = getWCMDocumentByName(siteName, DocumentTypes.Site);
if (siteId != null){
site = (Site)workspace.getById(siteId);
}
else{
site = workspace.createSite();
site.setName(siteName);
}
site.setTitle(siteDisplayName);
site = (Site)retrieveAddSettings(site, aSiteElement, false);

workspace.save(site);

}catch(Exception e){
System.out.println("Exception = "+e);
e.printStackTrace();

}
return site;
}



/*
*Parse site area element
*If site area already available, retrieve the site area object, edit the site area
*If site area not already created, create a new site area and set the name
*and display name and its settings
*Add a default content to the site area if available
*Save the site area to the workspace
*/
public SiteArea createSiteArea(Element aSiteAreaElement, DocumentId parentId){
String siteAreaName = aSiteAreaElement.getAttribute("Name");
String siteAreaDisplayName = aSiteAreaElement.getAttribute("DisplayName");

SiteArea sa = null;
try{
String parentPath = workspace.getPathById(parentId, true, true);
String siteAreaPath = parentPath+ "/"+ siteAreaName;
DocumentId siteAreaId = getWCMDocumentByPath(siteAreaPath,
Workspace.WORKFLOWSTATUS_ALL);

if (siteAreaId != null){
sa = (SiteArea)workspace.getById(siteAreaId);
}else{
sa = workspace.createSiteArea(parentId, null, 1);
}

sa = (SiteArea)retrieveAddSettings(sa, aSiteAreaElement, true);
if (sa != null){
sa.setTitle(siteAreaDisplayName);

sa.setName(siteAreaName);
workspace.save(sa);
sa = addDefaultContentToSiteArea(sa, aSiteAreaElement);

if (sa != null){

boolean saved = saveToWorkspace(sa);
System.out.println("site area = " + sa.getName());

if (!saved){
return null;
}

//checking if site area contains any other site area children
NodeList SiteAreaNodeList = aSiteAreaElement.getChildNodes();

for (Node node = aSiteAreaElement.getFirstChild(); node != null;
node = node.getNextSibling()) {
if (node.getNodeType() == Node.ELEMENT_NODE &&
node.getNodeName().equals("SiteArea")) {
Element siteAreaEL = (Element)node;

SiteArea childSA = createSiteArea(siteAreaEL, sa.getId());
if (childSA != null){
System.out.println("childSA for = " +sa.getName()+ " =
" + childSA.getName());
}
else{
return null;
}
}
}
}
else{
return null;
}
}
return sa;
}catch(Exception e){
System.out.println("Exception = "+e);
e.printStackTrace();

}
return null;
}



/*
*Parse the default content element
*If content already available, retrieve the content object, and edit it
*If content not already created, create a new content object and set the
*name and display name and its settings
*If authoring template provided, overwrite if already set
*Add text components and rich text components to the content
*Save the default content to the site area
*/
public SiteArea addDefaultContentToSiteArea(SiteArea aSiteArea,
Element aSiteAreaElement){

DocumentId defaultContentId = null;

Element defaultel = getChildByName(aSiteAreaElement, "DefaultContent");
String contentName = getElementValueByTagName("Name", defaultel);

defaultContentId = getWCMDocumentByName(contentName, DocumentTypes.Content);

Content content = null;

String contentDisplayName = getElementValueByTagName("DisplayName", defaultel);

String authoringTempName = getElementValueByTagName("AuthoringTemp", defaultel);

DocumentId defaultAuthId = null;

if (! authoringTempName.equals("")){
defaultAuthId = getWCMDocumentByName(authoringTempName,
DocumentTypes.AuthoringTemplate);

}
System.out.println("defaultAuthId = "+ defaultAuthId);
try{

//if content already existing in the library, re-use it
if (defaultContentId != null){
content = (Content)workspace.getById(defaultContentId);

//if authoring template provided in the file, overwrite the existing one
if (defaultAuthId != null){
content.setAuthoringTemplateID(defaultAuthId);
}
}
else if (defaultAuthId != null){
//if content not available, create a new one
content = workspace.createContent(defaultAuthId, aSiteArea.getId(),null,
ChildPosition.START);
defaultContentId = content.getId();
content.setName(contentName);
}
else{
System.out.println("Exception = Authoring Template for default content "+
contentName + " is missing");
return null;
}

if (! contentDisplayName.equals("")){
content.setTitle(contentDisplayName);
}

content = retrieveAddTextComponentToContent(content, defaultel);

if (content == null){
return null;
}
content = retrieveAddRichTextComponentToContent(content, defaultel);

if (content == null){
return null;
}

while(!content.isPublished()){
content.nextWorkflowStage();
}
workspace.save(content);

}catch(Exception e){
System.out.println("Exception = "+e);
e.printStackTrace();
}

System.out.println("defaultContent for = " +aSiteArea.getName()+ " = " +
defaultContentId.getName());
aSiteArea.setDefaultContent(defaultContentId);
return aSiteArea;
}



/*
*Parse DefaultContent element
*Search for text component elements
*Looping over all text component child elements
*Calling method addTextComponent to add the
*text component to the content
*/
public Content retriveAddTextComponentToContent(Content aContent,
Element aContentElement){

NodeList texttnl = aContentElement.getChildNodes();

for (Node node = aContentElement.getFirstChild();
node != null;
node = node.getNextSibling()) {
if (node.getNodeType() ==
Node.ELEMENT_NODE &&
node.getNodeName().equals("TextComponent")) {
Element textCompel = (Element)node;

String textField =
getElementValueByTagName("FieldName", textCompel);
String text =
getElementValueByTagName("Value", textCompel);
aContent =
addTextComponent(aContent, textField, text);

if (aContent != null){
System.out.println("adding textField =
"+ textField+" to content "
+aContent.getName());
}
}
}
if (aContent == null){
return null;
}
else{

return aContent;
}

}



/*
*Parse DefaultContent element
*Search for rich text component elements
*Looping over all rich text component child elements
*Calling method addRichTextComponent to add the rich text
*component to the content
*/
public Content retrieveAddRichTextComponentToContent
(Content aContent, Element aContentElement){
NodeList richTexttnl = aContentElement.getChildNodes();
for (Node node = aContentElement.getFirstChild(); node != null;
node = node.getNextSibling()) {
if (node.getNodeType() == Node.ELEMENT_NODE &&
node.getNodeName().equals("RichTextComponent")) {
Element richtextCompel = (Element)node;

String textField =
getElementValueByTagName("FieldName",
richtextCompel);
String text =
getElementValueByTagName("Value",
richtextCompel);

aContent =
addRichTextComponent(aContent, textField, text);

if (aContent != null){
System.out.println("adding richtextField =
"+ textField+" to content "+
aContent.getName());
}
}
}
if (aContent == null){
return null;
}
else{
return aContent;
}
}



/*
* Get text component from the content according to
*the text component name
* Set the text component with the value sent
* Add the text component to the content
*/
public Content addTextComponent
(Content aContent, String aTextField, String aValue){

try{
TextComponent txtComp =
(TextComponent) aContent.getComponent(aTextField);
txtComp.setText(aValue);
aContent.setComponent(aTextField, txtComp);
}catch(ComponentNotFoundException ex){
System.out.println
("Exception: "+aTextField+" is not a valid TextComponent");
return null;
}catch(Exception e){
System.out.println("Exception = "+e);
return null;
}

return aContent;
}



/*
* Get rich text component from the content according to the RTF name
* Set the rich text component with the value sent
* Add the rich text component to the content
*/
public Content addRichTextComponent(Content aContent,
String aTextField, String aValue){
try{
RichTextComponent richTxtComp =
(RichTextComponent) aContent.getComponent(aTextField);
richTxtComp.setRichText(aValue);
aContent.setComponent(aTextField, richTxtComp);
RichTextComponent rtf =
(RichTextComponent)aContent.getComponent(aTextField);
}catch(ComponentNotFoundException ex){
System.out.println("Exception:
"+aTextField+" is not a valid RichTextComponent");
return null;
}catch(Exception e){
System.out.println("Exception = "+e);
return null;
}

return aContent;
}



/*
*Parse site area or site element
*Search for settings element
*call method retrieveAddTemplateMapping to add template mapping to site or site area
*call method addSecuritySettings to add security settings to site or site area
*/
public Object retrieveAddSettings(SiteFrameworkContainer aWCMObject,
Element aObjectElement, boolean isSiteArea){

Element settingsel = getChildByName(aObjectElement, "Settings");
if ( settingsel!= null){
if(isSiteArea )
{
aWCMObject = (SiteArea)retrieveAddTemplateMapping
(aWCMObject, settingsel);
aWCMObject = (SiteArea)addSecuritySettings
(aWCMObject, settingsel);
}
else
{
aWCMObject = (Site)retrieveAddTemplateMapping
(aWCMObject, settingsel);
aWCMObject = (Site)addSecuritySettings
(aWCMObject, settingsel);
}
}
return aWCMObject;
}


清单 13. 将 SecuritySettings 添加到 Lotus Web Content Management 对象
/*
*Parse settings element
*Search for SecuritySettings element
*For every SecuritySettings element, find the AccessRight element
*loop over the AccessRight elements and get the type of the access
*According to the access type, a specific method in Lotus
*Web Content Management
*will be called to add the access rights
*/
public Object addSecuritySettings
(SiteFrameworkContainer aWCMObject, Element settingsel){

for (Node node = settingsel.getFirstChild(); node != null;
node = node.getNextSibling()) {
if (node.getNodeType() == Node.ELEMENT_NODE &&
node.getNodeName().equals("SecuritySettings")) {
Element secel = (Element)node;
NodeList accessRightsnl = secel.getChildNodes();

for (Node accessRightNode = secel.getFirstChild(); accessRightNode !=
null; accessRightNode = accessRightNode.getNextSibling()) {
if (accessRightNode.getNodeType() == Node.ELEMENT_NODE &&
accessRightNode.getNodeName().equals("AccessRight")) {
Element accessRightsel = (Element)accessRightNode;

String accessType = accessRightsel.getAttribute("Type");

NodeList accessnl = accessRightsel.getChildNodes();

if(accessnl != null ) {

for(int y = 0 ; y < accessnl.getLength();y++) {

Node accnode = accessnl.item(y);

if (accnode.getNodeType() ==
accnode.ELEMENT_NODE &&
accnode.getNodeName().equals("Access")) {
Element el = (Element)accnode;
String access = el.getFirstChild().getNodeValue();
if (accessType.equals("addReadAccessMembers")){
aWCMObject.addReadAccessMembers(new String[]{access});
System.out.println("addReadAccessMembers for bject =
"+aWCMObject.getName()+" members = "+access);
}else if(accessType.equals
("addEditAccessMembers")){
aWCMObject.addEditAccessMembers(new String[]{access});
System.out.println("addEditAccessMembers for bject =
"+aWCMObject.getName()+" members =
"+access);

}else if(accessType.equals

("addDeleteAccessMembers")){

aWCMObject.addDeleteAccessMembers
(new String[]{access});
System.out.println
("addDeleteAccessMembers for bject =
"+aWCMObject.getName()+" members = "+access);
}

}
}
}
}
}
}
}
return aWCMObject;
}


清单 14. 解析和添加 Template Mapping SiteArea
/*
*Parse settings element
*Search for TemplateMapping element
*For every TemplateMapping element
*Get the authoring template and presentation template names
*Retrieve the Lotus Web Content Management object from the names
*If item already contains a template mapping with the same authoring template,
*remove it and add the new one
*Else, add the new template mapping
*Save the object, either the site or site area
*/
public Object retrieveAddTemplateMapping
(SiteFrameworkContainer aWCMObject,
Element settingsel){
DocumentId authId = null;
DocumentId presId = null;

NodeList tempnl = settingsel.getChildNodes();

for (Node node = settingsel.getFirstChild(); node !=
null; node = node.getNextSibling()) {
if (node.getNodeType() == Node.ELEMENT_NODE &&
node.getNodeName().equals("TemplateMapping")) {
Element tempel = (Element)node;

String authoringTemp =
getElementValueByTagName("AuthoringTemp", tempel );
String presTemp =
getElementValueByTagName("PresentationTemp", tempel );

authId = getWCMDocumentByName(authoringTemp,
DocumentTypes.AuthoringTemplate);

presId = getWCMDocumentByName(presTemp,
DocumentTypes.PresentationTemplate);

if (authId != null){
try{
if (aWCMObject.hasTemplateMapping(authId)){
}

if (!aWCMObject.hasTemplateMapping(authId)){
aWCMObject.addTemplateMapping(authId, presId);
}
else{

DocumentIdIterator docIt = aWCMObject.getAuthoringTemplateIds();
if (docIt.hasNext()){
DocumentId dids = (DocumentId)docIt.next();
aWCMObject.removeTemplateMapping(dids);
aWCMObject.addTemplateMapping(authId, presId);
}
}

System.out.println("TemplateMapping authName = "+authoringTemp+"
and presName = "+presTemp +" added to object " + aWCMObject.getName());
workspace.save(aWCMObject);
}catch(Exception e){
System.out.println("Exception ="+e);
e.printStackTrace();
}
}else{
return null;
}
}
}

return aWCMObject;
}


清单 15. 将 Lotus Web Content Management 对象保存到工作空间
/*
* This is a helper method that receives a Lotus Web Content Management
* document object and adds it to the workspace
*/
public boolean saveToWorkspace(com.ibm.workplace.wcm.api.Document wcmDocument){

try{
String[] errors = workspace.save(wcmDocument);

for (int i = 0; i < errors.length; i++){
System.out.println("Error while saving "+
wcmDocument.getName()+ " : "+errors[i]);
}
if (errors.length > 0 ){
return false;
}
}catch(Exception e){
System.out.println("Exception = "+e);
e.printStackTrace();
return false;
}
return true;
}


清单 16. 按路径检索 Lotus Web Content Management 对象
/*
* This is a helper method that retrieves a Lotus Web Content Management
* object by its path and returns the DocumentId
*/
public DocumentId getWCMDocumentByPath(String wcmPath, int workFlowStatus) {
DocumentId wcmDocumentId = null;
try{


if(wcmPath != null){
DocumentIdIterator docIdIter = workspace.findByPath(wcmPath, workFlowStatus);
if(docIdIter != null && docIdIter.hasNext()){
wcmDocumentId = docIdIter.nextId();
}
}
}catch(Exception e){
System.out.println("Exception = "+e);
e.printStackTrace();
}

return wcmDocumentId;
}



/*
* This is a helper method that gets the child element according to
* its name of another element if
* it contains only one child with that name
*/
private Element getChildByName(Element element, String name) {
Element rEl = null;
for (Node node = element.getFirstChild(); node != null; node =
node.getNextSibling()) {
if (node.getNodeType() == Node.ELEMENT_NODE &&
node.getNodeName().equals(name)) {
rEl = (Element)node;
break;
}
}
return rEl;
}



/*
* This is a helper method that returns a string value of the given element
*/
public String getElementValueByTagName(String aTagName, Element aElement){
String elementValue = "";

NodeList nodeList = aElement.getElementsByTagName(aTagName);
if(nodeList != null && nodeList.getLength() > 0) {
Element el = (Element)nodeList.item(0);
elementValue = el.getFirstChild().getNodeValue();
}

return elementValue;
}


清单 19. 按名称检索 Lotus Web Content Management 对象
/*
* This is a helper method that returns the DocumentId of a Lotus Web
* Content Management object based on its name
*/
public DocumentId getWCMDocumentByName(String wcmName, DocumentType documentTypes){

DocumentId wcmDocumentId = null;
try{
if(wcmName != null){

DocumentIdIterator docIdIter = workspace.findByName(documentTypes, wcmName);
if(docIdIter != null && docIdIter.hasNext()){
wcmDocumentId = docIdIter.nextId();

}
}
}catch(Exception e){
System.out.println("Exception = "+e);
e.printStackTrace();
}
if (wcmDocumentId == null && ( (documentTypes.equals
(DocumentTypes.AuthoringTemplate)) || (documentTypes.equals
(DocumentTypes.PresentationTemplate)) )){
System.out.println("Exception: "+wcmName+" could not be found in the Repository");
}
return wcmDocumentId;
}


清单 20. 关闭 Lotus Web Content Management 工作空间
/**
* Closes the Lotus Web Content Management workspace
*/
public void closeWorkspace() {
WCM_API.getRepository().endWorkspace();

增强

使用本文给出的解决方案可以进一步实现增强。例如,您可以执行下面的操作:

  • 使用 XML 创建内容
  • 向默认内容添加更复杂的组件
  • 通过只更改站点区域的名称,修改 XML 以多次创建相同的结构

    结束语

    在本文中, 我们给出了一个简单的解决方案,它使您能够以一种自动化方式定义站点结构。使用这种解决方案的用例非常多样;例如,您可能需要在多个服务器上定义站点区 域,或者您的站点中具有大量重复的站点结构。这个解决方案帮助您避免将时间浪费在执行大量既耗时又单调的任务上。

}

注意:在这里给出异常处理只是出于演示目的,而不适合用于生产目的。应当在必要时进行修改以满足您的预期和要求。

helper 类给出一些重要警告:

  • 用户将收到一条警告消息,表示出现一些错误并且创建无法成功完成。
  • 错误被记录到 SystemOut.log 文件中,因此您可以从该文件获得更多有关错误的消息。
  • 当在存储库中没有找到用户时将出现错误,这将导致一个错误被记录到日志中,但是也会为用户生成一条 Creation Completed 消息。


图 2 展示了 XML 元素和实现解决方案后生成的输出之间的样例映射。


图 2. XML 与 Lotus Web Content Management 对象和区段之间的映射
XML 与 Lotus Web Content Management 对象和区段之间的映射

如您所见,实际站点结构与 XML 文件之间的映射非常简单,具有一个表示库的根元素。这个根元素随后包含另一个与站点对应的元素,定义它的名称并显示名称。站点区域以嵌套方式在 XML 文件中定义,用于获得必需的站点结构。

每个站点和站点区域都包含一个设置区段,其中包含安全设置和模板映射区段。下面是必须加以考虑的限制因素:安全设置和模板映射可以在各自的元素或树中的最高级别的站点或站点区域中针对每个站点或站点区域创建,并且其子元素将从父元素中继承。

内容安全设置和工作流被添加到编写模板组件中,而不是 XML 文件中的默认内容区段中。

模板映射和默认内容创建中使用的编写模板和演示模板必须提前创建。

通过定义默认内容的名称,默认内容可以在多个站点区域中重用。当您在 XML 文件中定义了完整的默认内容元素后,您可以通过定义一个只包含名称元素的默认内容标记来使用它。如果默认内容已经存在于库中,也可以使用在多个不同位置重用默认内容这一特性。


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/14751907/viewspace-623931/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-07-04

  • 博文量
    233
  • 访问量
    483833