关闭

用OpenCms API获取XML数据资源

1107人阅读 评论(0) 收藏 举报

<%!

// 数据列表

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;
 }

%>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:27637次
    • 积分:383
    • 等级:
    • 排名:千里之外
    • 原创:8篇
    • 转载:3篇
    • 译文:0篇
    • 评论:2条