用OpenCms API获取XML数据资源

<%!

// 数据列表

public static List<Map<String, Object>> getDatas(HttpServletRequest oRequest, HttpServletResponse oResponse,PageContext oContext) {
  List oMapList = new ArrayList();
  CmsJspXmlContentBean cms = new CmsJspXmlContentBean(oContext, oRequest,oResponse);
  try {
   I_CmsXmlContentContainer contentContainer = cms.contentload( "allInSubTreeDateReleasedDesc", "/data/ticket/|ticket|10",true);
   List result = contentContainer.getCollectorResult();
   CmsObject cmsobj = cms.getCmsObject();
   for (int j = 0; j < result.size(); ++j) {
    CmsResource resource = (CmsResource) result.get(j);
    CmsXmlContent content = CmsXmlContentFactory.unmarshal(cmsobj,resource, oRequest);
    Map oMap = new HashMap();
    String ID = content.getStringValue(cmsobj, "ID", cms .getRequestContext().getLocale());
    oMap.put("ID", ID);
    String Name = content.getStringValue(cmsobj, "Name", cms .getRequestContext().getLocale());
    oMap.put("Name", Name);
    String Date = content.getStringValue(cmsobj, "Date", cms .getRequestContext().getLocale());
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date d = new Date(Long.parseLong(Date));
    oMap.put("Date", df.format(d));

    oMapList.add(oMap);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return oMapList;
 }

 

// 单条数据

 public static Map<String, Object> getXMLDById(HttpServletRequest oRequest, HttpServletResponse oResponse, PageContext oContext, String dUrl) {
  Map<String, Object> oMap = new HashMap<String, Object>();
  CmsJspXmlContentBean cms = new CmsJspXmlContentBean(oContext, oRequest,oResponse);
  try {
   I_CmsXmlContentContainer contentContainer = cms.contentload("singleFile", dUrl, true);
   Iterator it = contentContainer.getCollectorResult().iterator();
   CmsObject cmsobj = cms.getCmsObject();
   if (it.hasNext()) {
    CmsResource resource = (CmsResource) it.next();
    CmsXmlContent content = CmsXmlContentFactory.unmarshal(cmsobj,resource, oRequest);
    String ID = content.getStringValue(cmsobj, "ID", cms .getRequestContext().getLocale());
    oMap.put("ID", ID);
    String Name = content.getStringValue(cmsobj, "Name", cms .getRequestContext().getLocale());
    oMap.put("Name", Name);
    String Date = content.getStringValue(cmsobj, "Date", cms .getRequestContext().getLocale());
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date d = new Date(Long.parseLong(Date));
    oMap.put("Date", df.format(d));
   }
  } catch (Exception e) {
  }
  return oMap;
 }

%>

阅读更多
个人分类: OpenCms内容管理
上一篇OpenCms中简单的Login模板实例代码
下一篇在OpenCms中利用Java代码删除、创建、更新用户!
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭