<%!
public static void updateXMLDById(HttpServletRequest oRequest,
HttpServletResponse oResponse, PageContext oContext, String dpUrl) {
try {
CmsJspActionElement cms = new CmsJspActionElement(oContext,
oRequest, oResponse);
CmsObject cmsObject = cms.getCmsObject();
// 修改的大环境设置
cmsObject.loginUser("Admin", "admin");
CmsProject cmsproject = cmsObject.readProject("Offline");
cmsObject.getRequestContext().setCurrentProject(cmsproject);
// 文件属性更新
CmsProperty titleProp = new CmsProperty();
titleProp.setName(CmsPropertyDefinition.PROPERTY_TITLE);
// 内容的改变
String dUrl = cmsObject.getRequestContext().removeSiteRoot(dpUrl);
Locale locale = cmsObject.getRequestContext().getLocale();
CmsFile cmsFile = cmsObject.readFile(dUrl,CmsResourceFilter.IGNORE_EXPIRATION);
CmsXmlContent cmsXmlContent = CmsXmlContentFactory.unmarshal(cmsObject, cmsFile);
cmsXmlContent.getValue("Name", locale).setStringValue(cmsObject, "MrZhao");
byte[] contentXml = cmsXmlContent.marshal();
cmsFile.setContents(contentXml);
//
cmsObject.lockResource(dUrl);
cmsObject.writeFile(cmsFile);
cmsObject.unlockResource(dUrl);
//
cmsObject.publishResource(dUrl);
} catch (Exception e) {
e.printStackTrace();
}
}
%>