testcmsxmlcontentlinks.java
来自「找了很久才找到到源代码」· Java 代码 · 共 913 行 · 第 1/3 页
JAVA
913 行
// read the content again
xmlcontent = CmsXmlContentFactory.unmarshal(cms, content, CmsEncoder.ENCODING_UTF_8, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
// get and validate the vfs reference
expectedRefLink = getExpected(cms, false);
refLink = getVfsFileRefLink(cms, xmlcontent, "VfsLink");
assertLink(expectedRefLink, refLink, false);
// get and validate the html link, should be unchanged
expectedHtmlLink = getExpected(cms, true);
assertLink(expectedHtmlLink, getHtmlLink(cms, xmlcontent, "Html", "link0"), false);
// validate, and assert the result
CmsXmlContentErrorHandler errHandler = xmlcontent.validate(cms);
assertTrue(errHandler.getErrors().isEmpty());
assertEquals(errHandler.getWarnings().size(), 1);
assertTrue(errHandler.getWarnings().containsKey(Locale.ENGLISH));
Map enWarnings = (Map)errHandler.getWarnings().get(Locale.ENGLISH);
assertEquals(enWarnings.size(), 1);
assertTrue(enWarnings.containsKey("VfsLink[1]"));
assertTrue(enWarnings.containsValue(org.opencms.xml.content.Messages.get().getBundle().key(
org.opencms.xml.content.Messages.GUI_XMLCONTENT_CHECK_WARNING_NOT_RELEASED_0)));
// reset the time to have the 'normal' behaviour again
cms.getRequestContext().setRequestTime(System.currentTimeMillis());
// check offline
// read the content again
xmlcontent = CmsXmlContentFactory.unmarshal(cms, content, CmsEncoder.ENCODING_UTF_8, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
// get the broken vfs reference
assertNull(xmlcontent.getValue("VfsLink", Locale.ENGLISH));
assertEquals(xmlcontent.getNames(Locale.ENGLISH).size(), 1);
// get and validate the html link, should be unchanged
expectedHtmlLink = getExpected(cms, true);
assertLink(expectedHtmlLink, getHtmlLink(cms, xmlcontent, "Html", "link0"), false);
// validate, and assert the result
errHandler = xmlcontent.validate(cms);
assertFalse(errHandler.hasErrors());
assertFalse(errHandler.hasWarnings());
// check online, always automatically checked, and includes time window check
CmsProject project = cms.getRequestContext().currentProject();
try {
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
// read the content again
xmlcontent = CmsXmlContentFactory.unmarshal(cms, content, CmsEncoder.ENCODING_UTF_8, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
// get the broken vfs reference
assertNull(xmlcontent.getValue("VfsLink", Locale.ENGLISH));
assertEquals(xmlcontent.getNames(Locale.ENGLISH).size(), 1);
// get and validate the html link, should be unchanged
expectedHtmlLink = getExpected(cms, true);
assertLink(expectedHtmlLink, getHtmlLink(cms, xmlcontent, "Html", "link0"), false);
// validate, and assert the result
errHandler = xmlcontent.validate(cms);
assertFalse(errHandler.hasErrors());
assertFalse(errHandler.hasWarnings());
} finally {
cms.getRequestContext().setCurrentProject(project);
}
// delete the link
cms.lockResource(FILENAME);
cms.deleteResource(FILENAME, CmsResource.DELETE_PRESERVE_SIBLINGS);
cms.unlockResource(FILENAME);
OpenCms.getPublishManager().publishResource(cms, FILENAME);
OpenCms.getPublishManager().waitWhileRunning();
// check offline, without link checking.
// set the flag to prevent link checking
cms.getRequestContext().setRequestTime(CmsResource.DATE_RELEASED_EXPIRED_IGNORE);
// read the content again
xmlcontent = CmsXmlContentFactory.unmarshal(cms, content, CmsEncoder.ENCODING_UTF_8, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
// get and validate the vfs reference
expectedRefLink = getExpected(cms, false);
refLink = getVfsFileRefLink(cms, xmlcontent, "VfsLink");
assertLink(expectedRefLink, refLink, false);
// get and validate the html link, should be unchanged
expectedHtmlLink = getExpected(cms, true);
assertLink(expectedHtmlLink, getHtmlLink(cms, xmlcontent, "Html", "link0"), false);
// validate, and assert the result
errHandler = xmlcontent.validate(cms);
assertEquals(errHandler.getErrors().size(), 1);
assertTrue(errHandler.getErrors().containsKey(Locale.ENGLISH));
Map enErrors = (Map)errHandler.getErrors().get(Locale.ENGLISH);
assertEquals(enErrors.size(), 1);
assertTrue(enErrors.containsKey("VfsLink[1]"));
assertTrue(enErrors.containsValue(org.opencms.xml.content.Messages.get().getBundle().key(
org.opencms.xml.content.Messages.GUI_XMLCONTENT_CHECK_ERROR_0)));
assertTrue(errHandler.getWarnings().isEmpty());
// reset the time to have the 'normal' behaviour again
cms.getRequestContext().setRequestTime(System.currentTimeMillis());
// check offline.
// read the content again
xmlcontent = CmsXmlContentFactory.unmarshal(cms, content, CmsEncoder.ENCODING_UTF_8, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
// get the broken vfs reference
assertNull(xmlcontent.getValue("VfsLink", Locale.ENGLISH));
assertEquals(xmlcontent.getNames(Locale.ENGLISH).size(), 1);
// get and validate the html link, should be unchanged
expectedHtmlLink = getExpected(cms, true);
assertLink(expectedHtmlLink, getHtmlLink(cms, xmlcontent, "Html", "link0"), false);
// validate, and assert the result
errHandler = xmlcontent.validate(cms);
assertFalse(errHandler.hasErrors());
assertFalse(errHandler.hasWarnings());
// check online, always automatically checked, and includes time window check
project = cms.getRequestContext().currentProject();
try {
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
// read the content again
xmlcontent = CmsXmlContentFactory.unmarshal(cms, content, CmsEncoder.ENCODING_UTF_8, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
// get the broken vfs reference
assertNull(xmlcontent.getValue("VfsLink", Locale.ENGLISH));
assertEquals(xmlcontent.getNames(Locale.ENGLISH).size(), 1);
// get and validate the html link, should be unchanged
expectedHtmlLink = getExpected(cms, true);
assertLink(expectedHtmlLink, getHtmlLink(cms, xmlcontent, "Html", "link0"), false);
// validate, and assert the result
errHandler = xmlcontent.validate(cms);
assertFalse(errHandler.hasErrors());
assertFalse(errHandler.hasWarnings());
} finally {
cms.getRequestContext().setCurrentProject(project);
}
// recreate the file for the next test case
cms.createResource(FILENAME, CmsResourceTypePlain.getStaticTypeId());
cms.unlockResource(FILENAME);
OpenCms.getPublishManager().publishResource(cms, FILENAME);
OpenCms.getPublishManager().waitWhileRunning();
}
/**
* Test removing the parent node of a broken link.<p>
*
* @throws Exception in case something goes wrong
*/
public void testRemoveParent() throws Exception {
CmsObject cms = getCmsObject();
echo("Testing removing the parent node of a broken link");
CmsXmlEntityResolver resolver = new CmsXmlEntityResolver(cms);
// now read the XML content
String content = CmsFileUtil.readFile("org/opencms/xml/content/xmlcontent-12.xml", CmsEncoder.ENCODING_UTF_8);
CmsXmlContent xmlcontent = CmsXmlContentFactory.unmarshal(cms, content, CmsEncoder.ENCODING_UTF_8, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
// get a valid string
assertEquals(xmlcontent.getValue("String", Locale.ENGLISH).getStringValue(cms), "test");
// get and validate the vfs reference
CmsLink expectedRefLink = getExpected(cms, false);
CmsLink refLink = getVfsFileRefLink(cms, xmlcontent, "ALink[1]/VfsLink");
assertLink(expectedRefLink, refLink, true);
// get and validate the html link
CmsLink htmlLink = getHtmlLink(cms, xmlcontent, "ALink[1]/Html", "link0");
CmsLink expectedHtmlLink = getExpected(cms, true);
assertLink(expectedHtmlLink, htmlLink, true);
// change the time window
cms.lockResource(FILENAME);
cms.setDateReleased(FILENAME, System.currentTimeMillis() + 1000000, false);
cms.setDateExpired(FILENAME, System.currentTimeMillis() + 2000000, false);
cms.unlockResource(FILENAME);
OpenCms.getPublishManager().publishResource(cms, FILENAME);
OpenCms.getPublishManager().waitWhileRunning();
// check offline, without link checking.
// set the flag to prevent link checking
cms.getRequestContext().setRequestTime(CmsResource.DATE_RELEASED_EXPIRED_IGNORE);
// read the content again
xmlcontent = CmsXmlContentFactory.unmarshal(cms, content, CmsEncoder.ENCODING_UTF_8, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
// get a valid string
assertEquals(xmlcontent.getValue("String", Locale.ENGLISH).getStringValue(cms), "test");
// get and validate the vfs reference
expectedRefLink = getExpected(cms, false);
refLink = getVfsFileRefLink(cms, xmlcontent, "ALink[1]/VfsLink");
assertLink(expectedRefLink, refLink, false);
// get and validate the html link, should be unchanged
expectedHtmlLink = getExpected(cms, true);
assertLink(expectedHtmlLink, getHtmlLink(cms, xmlcontent, "ALink[1]/Html", "link0"), false);
// validate, and assert the result
CmsXmlContentErrorHandler errHandler = xmlcontent.validate(cms);
assertTrue(errHandler.getErrors().isEmpty());
assertEquals(errHandler.getWarnings().size(), 1);
assertTrue(errHandler.getWarnings().containsKey(Locale.ENGLISH));
Map enWarnings = (Map)errHandler.getWarnings().get(Locale.ENGLISH);
assertEquals(enWarnings.size(), 1);
assertTrue(enWarnings.containsKey("ALink[1]/VfsLink[1]"));
assertTrue(enWarnings.containsValue(org.opencms.xml.content.Messages.get().getBundle().key(
org.opencms.xml.content.Messages.GUI_XMLCONTENT_CHECK_WARNING_NOT_RELEASED_0)));
// reset the time to have the 'normal' behaviour again
cms.getRequestContext().setRequestTime(System.currentTimeMillis());
// check offline
// read the content again
xmlcontent = CmsXmlContentFactory.unmarshal(cms, content, CmsEncoder.ENCODING_UTF_8, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
// get a valid string
assertEquals(xmlcontent.getValue("String", Locale.ENGLISH).getStringValue(cms), "test");
// get the broken vfs reference
assertNull(xmlcontent.getValue("ALink", Locale.ENGLISH));
assertEquals(xmlcontent.getNames(Locale.ENGLISH).size(), 1);
// validate, and assert the result
errHandler = xmlcontent.validate(cms);
assertFalse(errHandler.hasErrors());
assertFalse(errHandler.hasWarnings());
// check online, always automatically checked, and includes time window check
CmsProject project = cms.getRequestContext().currentProject();
try {
cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
// read the content again
xmlcontent = CmsXmlContentFactory.unmarshal(cms, content, CmsEncoder.ENCODING_UTF_8, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
// get a valid string
assertEquals(xmlcontent.getValue("String", Locale.ENGLISH).getStringValue(cms), "test");
// get the broken vfs reference
assertNull(xmlcontent.getValue("ALink", Locale.ENGLISH));
assertEquals(xmlcontent.getNames(Locale.ENGLISH).size(), 1);
// validate, and assert the result
errHandler = xmlcontent.validate(cms);
assertFalse(errHandler.hasErrors());
assertFalse(errHandler.hasWarnings());
} finally {
cms.getRequestContext().setCurrentProject(project);
}
// delete the link
cms.lockResource(FILENAME);
cms.deleteResource(FILENAME, CmsResource.DELETE_PRESERVE_SIBLINGS);
cms.unlockResource(FILENAME);
OpenCms.getPublishManager().publishResource(cms, FILENAME);
OpenCms.getPublishManager().waitWhileRunning();
// check offline, without link checking.
// set the flag to prevent link checking
cms.getRequestContext().setRequestTime(CmsResource.DATE_RELEASED_EXPIRED_IGNORE);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?