`
zhans52
  • 浏览: 35264 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

portal使用WCM api开发 展示已发布、待审核信息

阅读更多

    最近项目使用WCM作为portal的后台发布系统,前台数据展示集成考虑了2种方式:一种是在wcm中创建菜单,前台使用web内容管理器配置;二是使用wcm api 获取数据展示。

     先是使用了创建菜单的方式,但是发现有如下几个问题没有解决:一是样式问题,样式不好控制,而且有时候数据还出不来,我水平比较菜,都是在摸索前进,觉得 把时间花在这上面风险太大,而且不利于前台维护,每复制一个web内容管理器都要到页面上进行配置一次,也就是说如果想一个portlet多个页面复用或 者换一个页面那就重新需要配置一次。

     所以改为使用了wcm api的方式。研究发现,wcm api里可以做所有的事情。当然,先从前台展示开始。通过api先获取到已发布(流程节点,也可以根据此处获取待审核,草稿等其他节点信息)的内容,然后 再根据站点区域(由于我的设计是一个流程多个站点区域使用)获取数据进行封装,传回前台展示。

    我的封装数据格式是:["zhandian1":{数据1},"zhandian2":{数据2}......],这样在每个前台页面根据不同的站点获取不同的数据

代码如下:

1、连接到WCM

static PropertiesConfig con = new PropertiesConfig();
	private static Workspace workspace;
	private static String libraryName=con.getProperties("library_name");//库名称
	private static String publishCode=con.getProperties("publish_code");//已发布节点名称
	
	static{
		try {
			workspace = WCM_API.getRepository().getSystemWorkspace();
		} catch (ServiceNotAvailableException e) {
			System.out.println("获取workspace失败:服务不可用!!");
			e.printStackTrace();
		} catch (OperationFailedException e) {
			System.out.println("获取workspace失败:操作失败!!");
			e.printStackTrace();
		}
		workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary(libraryName));
	}

 2、返回发布节点

/**
	 * 取得发布阶段,并且给以数组的方式返回。
	 */
	private static DocumentId[] getWorkFlowStageByPublic(){
		DocumentIdIterator workFlowStageIdIterator = workspace.findByName(DocumentTypes.WorkflowStage,publishCode);
		DocumentId[] ids = new DocumentId[1];
		ids[0] = workFlowStageIdIterator.nextId();
		return ids;
	}

 3、获取所有已发布信息

	/**
	 * 返回已发布信息。
	 * @return DocumentId
	 */
	private static List<DocumentId> getPublicContent(){
		DocumentId[] workflowStgeId = getWorkFlowStageByPublic();
		DocumentIdIterator contentIdIterator = null;
		List<DocumentId> contentList = new ArrayList<DocumentId>();
		try {
			contentIdIterator = workspace.findContentByWorkflowStage(workflowStgeId);
		} catch (IllegalDocumentTypeException e) {
			e.printStackTrace();
		}
		while(contentIdIterator.hasNext()){
			contentList.add(contentIdIterator.nextId());
		}
		return contentList;
	}

 4、获取所有的栏目以及文章所处站点区域

	
	/**
	 * 取出文章所在的栏目
	 * @param ids
	 * @return
	 */
	private static SiteArea getSiteAndSiteArea(DocumentIdIterator ids){
		SiteArea doc = null;
		if(ids.hasNext()){
			try {
				doc = (SiteArea)workspace.getById(ids.nextId());
			} catch (DocumentRetrievalException e) {
				e.printStackTrace();
			} catch (AuthorizationException e) {
				e.printStackTrace();
			}
		}
		return doc;
	}
	
	/**
	 * 取出所有的栏目
	 * @param ids
	 * @return 
	 */
	@SuppressWarnings("deprecation")
	private static Map<String, ArrayList<Content>> getSiteAreaS(){
		DocumentIdIterator siteAreas =  workspace.findByType(DocumentTypes.SiteArea);
		Map<String, ArrayList<Content>> map = null;
		int count = siteAreas.getCount();
		if(count>0){
			map = new HashMap<String, ArrayList<Content>>();
			while(siteAreas.hasNext()){
				DocumentId s = siteAreas.nextId();
				map.put(s.getName(), new ArrayList<Content>());
			}
		}
		return map;
	}

 5、组装数据

(略)


6、前台获取数据

<%@page session="false" contentType="text/html" pageEncoding="GB18030" import="java.util.*,javax.portlet.*" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>                
<portlet:defineObjects/>
<%
	PortletPreferences ref = renderRequest.getPreferences();
	String moreUrl = ref.getValue("moreUrl","");
	String json = (String)renderRequest.getAttribute("json");
%>
<script type="text/javascript">
	var data=eval(<%=json%>);
	nl.data=data;
</script>

 7、展示页面获取展示

<script type="text/javascript">
	$(document).ready(function() {
		var d = nl.data["<%=key%>"]
		console.info(nl.data);
		$("#<portlet:namespace/>div").portalui_showLine({
				data:d,
				moreUrl:nl.moreUrlPath+"<%=moreUrl%>",
   			size:<%=size%>
	   	});
	});
</script>

 

同时,感谢网友天山来客的大力技术支持,是他为我指明了方向

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics