?? testcmsxmlcontentwithvfs.java
字號:
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
I_CmsXmlContentValue value1;
value1 = xmlcontent.addValue(cms, "Title", Locale.ENGLISH, 0);
assertEquals("Test", value1.getStringValue(cms));
value1 = xmlcontent.addValue(cms, "Cascade[1]/Option", Locale.ENGLISH, 0);
assertEquals("Default value from the XML", value1.getStringValue(cms));
// check exact default mappings for nested content
value1 = xmlcontent.addValue(cms, "Cascade[1]/Option", Locale.ENGLISH, 1);
assertEquals("Default value from outer content definition", value1.getStringValue(cms));
// check generic default mappings for nested content
value1 = xmlcontent.addValue(cms, "Cascade[1]/VfsLink", Locale.ENGLISH, 1);
assertEquals("/default/for/all/from/outer.txt", value1.getStringValue(cms));
value1 = xmlcontent.addValue(cms, "Cascade[1]/VfsLink", Locale.ENGLISH, 2);
assertEquals("/default/for/all/from/outer.txt", value1.getStringValue(cms));
}
/**
* Test default values after a new XML content has been created.<p>
*
* @throws Exception in case the test fails
*/
public void testDefaultOnCreation() throws Exception {
CmsObject cms = getCmsObject();
echo("Testing default values when creating an XML content resource");
CmsXmlEntityResolver resolver = new CmsXmlEntityResolver(cms);
// create a new xml content article
String xmlContentFile = "/xmlcontent/article_0005.html";
cms.createResource(xmlContentFile, 12);
CmsFile file = cms.readFile(xmlContentFile);
String content = new String(file.getContents(), CmsEncoder.ENCODING_UTF_8);
CmsXmlContent xmlcontent = CmsXmlContentFactory.unmarshal(content, CmsEncoder.ENCODING_UTF_8, resolver);
String value = xmlcontent.getStringValue(cms, "Title", Locale.ENGLISH);
assertEquals("Default title value", value);
value = xmlcontent.getStringValue(cms, "Release", Locale.ENGLISH);
assertEquals("1114525380000", value);
}
/**
* Test default values in the appinfo node using a nested XML content schema when creating a new content.<p>
*
* The nested content definition must be non-optional, and must have non-optional element.<p>
*
* @throws Exception in case something goes wrong
*/
public void testDefaultOnCreationWithNested() throws Exception {
CmsObject cms = getCmsObject();
echo("Testing for default values in nested XML content schemas when creating a new content");
CmsXmlEntityResolver resolver = new CmsXmlEntityResolver(cms);
String content;
// unmarshal content definitions
content = CmsFileUtil.readFile(
"org/opencms/xml/content/xmlcontent-definition-3b.xsd",
CmsEncoder.ENCODING_UTF_8);
// store content definition in entitiy resolver
CmsXmlEntityResolver.cacheSystemId(SCHEMA_SYSTEM_ID_3B, content.getBytes(CmsEncoder.ENCODING_UTF_8));
content = CmsFileUtil.readFile(
"org/opencms/xml/content/xmlcontent-definition-4b.xsd",
CmsEncoder.ENCODING_UTF_8);
// store content definition in entitiy resolver
CmsXmlEntityResolver.cacheSystemId(SCHEMA_SYSTEM_ID_4B, content.getBytes(CmsEncoder.ENCODING_UTF_8));
// create the content definition
CmsXmlContentDefinition cd = CmsXmlContentDefinition.unmarshal(content, SCHEMA_SYSTEM_ID_4B, resolver);
CmsXmlContent xmlcontent = CmsXmlContentFactory.createDocument(cms, Locale.ENGLISH, content, cd);
String value = xmlcontent.getStringValue(cms, "Title", Locale.ENGLISH);
assertEquals("Test", value);
value = xmlcontent.getStringValue(cms, "Cascade/Option", Locale.ENGLISH);
assertEquals("Default value from outer content definition", value);
value = xmlcontent.getStringValue(cms, "Cascade/Option[2]", Locale.ENGLISH);
assertEquals("Default value from outer content definition (for option node 2)", value);
value = xmlcontent.getStringValue(cms, "Cascade/VfsLink", Locale.ENGLISH);
assertEquals("/default/for/all/from/outer.txt", value);
}
/**
* Tests the Locale settings of XMLContents with only optional elements and no element present.<p>
*
* @throws Exception if the test fails
*/
public void testEmptyLocale() throws Exception {
CmsObject cms = getCmsObject();
echo("Testing handling of empty locale nodes in XML content");
CmsXmlEntityResolver resolver = new CmsXmlEntityResolver(cms);
String iso = "ISO-8859-1";
String content;
CmsXmlContent xmlcontent;
// unmarshal content definition
content = CmsFileUtil.readFile(
"org/opencms/xml/content/xmlcontent-definition-8.xsd",
CmsEncoder.ENCODING_UTF_8);
// store content definition in entitiy resolver
CmsXmlEntityResolver.cacheSystemId(SCHEMA_SYSTEM_ID_8, content.getBytes(iso));
CmsXmlContentDefinition cd1 = CmsXmlContentDefinition.unmarshal(content, SCHEMA_SYSTEM_ID_8, resolver);
// read an existing (empty) XML content with just one locale node
content = CmsFileUtil.readFile("org/opencms/xml/content/xmlcontent-8.xml", iso);
xmlcontent = CmsXmlContentFactory.unmarshal(content, iso, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
List locales = xmlcontent.getLocales();
assertEquals(1, locales.size());
assertEquals(Locale.ENGLISH, locales.get(0));
// create a fresh XML content based on the schema and try again
xmlcontent = CmsXmlContentFactory.createDocument(null, Locale.ENGLISH, CmsEncoder.ENCODING_UTF_8, cd1);
xmlcontent.validateXmlStructure(resolver);
locales = xmlcontent.getLocales();
assertEquals(1, locales.size());
assertEquals(Locale.ENGLISH, locales.get(0));
}
/**
* Tests locale copy, move and remove operation on an XML content.<p>
*
* @throws Exception if the test fails
*/
public void testCopyMoveRemoveLocale() throws Exception {
CmsObject cms = getCmsObject();
echo("Testing locale copy, move and remove operation on an XML content");
CmsXmlEntityResolver resolver = new CmsXmlEntityResolver(cms);
String iso = "ISO-8859-1";
String content;
CmsXmlContent xmlcontent;
// unmarshal content definition
content = CmsFileUtil.readFile("org/opencms/xml/content/xmlcontent-definition-8.xsd", CmsEncoder.ENCODING_UTF_8);
// store content definition in entitiy resolver
CmsXmlEntityResolver.cacheSystemId(SCHEMA_SYSTEM_ID_8, content.getBytes(iso));
// read an existing (empty) XML content with just one locale node
content = CmsFileUtil.readFile("org/opencms/xml/content/xmlcontent-8.xml", iso);
xmlcontent = CmsXmlContentFactory.unmarshal(content, iso, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
List locales = xmlcontent.getLocales();
assertEquals(1, locales.size());
assertEquals(Locale.ENGLISH, locales.get(0));
xmlcontent.copyLocale(Locale.ENGLISH, Locale.GERMANY);
assertEquals(2, xmlcontent.getLocales().size());
assertTrue(xmlcontent.hasLocale(Locale.ENGLISH));
assertTrue(xmlcontent.hasLocale(Locale.GERMANY));
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
xmlcontent.moveLocale(Locale.GERMANY, Locale.FRENCH);
assertEquals(2, xmlcontent.getLocales().size());
assertTrue(xmlcontent.hasLocale(Locale.ENGLISH));
assertTrue(xmlcontent.hasLocale(Locale.FRENCH));
assertFalse(xmlcontent.hasLocale(Locale.GERMANY));
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
xmlcontent.removeLocale(Locale.ENGLISH);
assertEquals(1, xmlcontent.getLocales().size());
assertTrue(xmlcontent.hasLocale(Locale.FRENCH));
assertFalse(xmlcontent.hasLocale(Locale.ENGLISH));
assertFalse(xmlcontent.hasLocale(Locale.GERMANY));
assertEquals(Locale.FRENCH, xmlcontent.getLocales().get(0));
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
}
/**
* Test using the GUI widget mapping appinfo nodes.<p>
*
* @throws Exception in case something goes wrong
*/
public void testLayoutWidgetMapping() throws Exception {
CmsObject cms = getCmsObject();
echo("Testing mapping of the XML content GUI to different widgets");
CmsXmlEntityResolver resolver = new CmsXmlEntityResolver(cms);
String content;
// unmarshal content definition
content = CmsFileUtil.readFile(
"org/opencms/xml/content/xmlcontent-definition-5.xsd",
CmsEncoder.ENCODING_UTF_8);
CmsXmlContentDefinition definition = CmsXmlContentDefinition.unmarshal(content, SCHEMA_SYSTEM_ID_5, resolver);
// store content definition in entitiy resolver
CmsXmlEntityResolver.cacheSystemId(SCHEMA_SYSTEM_ID_5, content.getBytes(CmsEncoder.ENCODING_UTF_8));
// now read the XML content
content = CmsFileUtil.readFile("org/opencms/xml/content/xmlcontent-5.xml", CmsEncoder.ENCODING_UTF_8);
CmsXmlContent xmlcontent = CmsXmlContentFactory.unmarshal(content, CmsEncoder.ENCODING_UTF_8, resolver);
// validate the XML structure
xmlcontent.validateXmlStructure(resolver);
I_CmsWidget widget;
I_CmsXmlContentHandler handler = definition.getContentHandler();
// make sure the selected widgets are of the configured "non-standard" type
widget = handler.getWidget(xmlcontent.getValue("Title", Locale.ENGLISH));
assertNotNull(widget);
assertEquals(CmsCheckboxWidget.class.getName(), widget.getClass().getName());
assertEquals("Configuration for Title", handler.getConfiguration(xmlcontent.getValue("Title", Locale.ENGLISH)));
// make sure the alias name works
widget = handler.getWidget(xmlcontent.getValue("Test", Locale.ENGLISH));
assertNotNull(widget);
assertEquals(CmsHtmlWidget.class.getName(), widget.getClass().getName());
assertEquals("Configuration for Test", handler.getConfiguration(xmlcontent.getValue("Test", Locale.ENGLISH)));
// make sure the custom class name works
widget = handler.getWidget(xmlcontent.getValue("Toast", Locale.ENGLISH));
assertNotNull(widget);
assertEquals(TestCustomInputWidgetImpl.class.getName(), widget.getClass().getName());
assertEquals("Configuration for Toast", handler.getConfiguration(xmlcontent.getValue("Toast", Locale.ENGLISH)));
// custom widget configuration has extended the handler String
assertEquals("Configuration for Toast[some addition here]", widget.getConfiguration());
}
/**
* Test resolving the links from an XML content.<p>
*
* @throws Exception in case something goes wrong
*/
public void testLinkResolver() throws Exception {
CmsObject cms = getCmsObject();
echo("Testing link resolver for XML content");
CmsXmlEntityResolver resolver = new CmsXmlEntityResolver(cms);
String content;
// unmarshal content definition
content = CmsFileUtil.readFile(
"org/opencms/xml/content/xmlcontent-definition-2.xsd",
CmsEncoder.ENCODING_UTF_8);
CmsXmlContentDefinition definition = CmsXmlContentDefinition.unmarshal(content, SCHEMA_SYSTEM_ID_2, resolver);
// store content definition in entitiy resolver
CmsXmlEntityResolver.cacheSystemId(SCHEMA_SYSTEM_ID_2, content.getBytes(CmsEncoder.ENCODING_UTF_8));
// now create the XML content
content = CmsFileUtil.readFile("org/opencms/xml/content/xmlcontent-2.xml", CmsEncoder.ENCODING_UTF_8);
CmsXmlContent xmlcontent = CmsXmlContentFactory.unmarshal(content, CmsEncoder.ENCODING_UTF_8, resolver);
assertTrue(xmlcontent.hasValue("Html", Locale.ENGLISH));
assertTrue(xmlcontent.hasValue("VfsLink", Locale.ENGLISH));
assertSame(definition.getContentHandler().getClass().getName(), CmsDefaultXmlContentHandler.class.getName());
CmsXmlHtmlValue htmlValue = (CmsXmlHtmlValue)xmlcontent.getValue("Html", Locale.ENGLISH);
CmsXmlVfsFileValue vfsValue = (CmsXmlVfsFileValue)xmlcontent.getValue("VfsLink", Locale.ENGLISH);
// must set the value again to ensure link table is properly initialized
htmlValue.setStringValue(cms, htmlValue.getStringValue(cms));
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -