}
@Test
public void testGetInContentMetaFromCache() throws Exception {
OdfTextDocument odt = (OdfTextDocument) OdfDocument
.loadDocument(ResourceUtilities.getAbsolutePath(SIMPLE_ODT));
Model m1 = odt.getInContentMetadataFromCache();
// We have the following 1 triple in cache:
// (http://dbpedia.org/page/J._R._R._Tolkien
// http://www.w3.org/2006/vcard/ns#fn 'John Ronald Reuel Tolkien')
TestCase.assertEquals(1, m1.size());
OdfContentDom contentDom = odt.getContentDom();
XPath xpath = contentDom.getXPath();
TextMetaElement tm = (TextMetaElement) xpath.evaluate(
"//text:p/text:meta[last()]", contentDom, XPathConstants.NODE);
tm.setXhtmlAboutAttribute("http://dbpedia.org/page/J._K._Rowling");
m1 = odt.getInContentMetadataFromCache();
PrintUtil.printOut(m1.listStatements());
TestCase.assertEquals("http://dbpedia.org/page/J._K._Rowling", m1
.listStatements().nextStatement().getSubject().getURI());
tm.setTextContent("Joanne Kathleen Rowling");
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals("Joanne Kathleen Rowling", m1.listStatements()
.nextStatement().getObject().toString());
tm.setXhtmlPropertyAttribute("dc:name");
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals("http://purl.org/dc/elements/1.1/name", m1
.listStatements().nextStatement().getPredicate().getURI());
Node parent = tm.getParentNode();
parent.removeChild(tm);
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(0, m1.size());
parent.appendChild(tm);
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(1, m1.size());
parent.removeChild(tm);
TextPElement pEle = contentDom.newOdfElement(TextPElement.class);
parent.appendChild(pEle);
pEle.setXhtmlAboutAttribute("[dbpedia:J._K._Rowling]");
pEle.setXhtmlPropertyAttribute("dbpprop:birthDate dbpprop:dateOfBirth");
pEle.setXhtmlDatatypeAttribute("xsd:date");
pEle.setXhtmlContentAttribute("1965-07-31");
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(2, m1.size());
StmtIterator iter = m1.listStatements();
while (iter.hasNext()) {
Statement stmt = iter.nextStatement();
TestCase.assertEquals("http://dbpedia.org/page/J._K._Rowling", stmt
.getSubject().getURI());
TestCase.assertTrue(stmt.getObject().canAs(Literal.class));
Literal literal = stmt.getObject().as(Literal.class);
TestCase.assertEquals("http://www.w3.org/2001/XMLSchema#date",
literal.getDatatypeURI());
TestCase.assertEquals("1965-07-31", literal.getLexicalForm());
}
pEle.setXhtmlPropertyAttribute("dc:date");
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(1, m1.size());
TestCase.assertEquals("http://purl.org/dc/elements/1.1/date", m1
.listStatements().nextStatement().getPredicate().getURI());
parent.removeChild(pEle);
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(0, m1.size());
parent.appendChild(pEle);
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(1, m1.size());
parent.removeChild(pEle);
TextHElement hEle = contentDom.newOdfElement(TextHElement.class);
parent.appendChild(hEle);
hEle.setXhtmlAboutAttribute("[dbpedia:J._K._Rowling]");
hEle.setXhtmlPropertyAttribute("dbpprop:children");
hEle.setXhtmlDatatypeAttribute("xsd:integer");
hEle.setTextContent("2");
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(1, m1.size());
TestCase.assertEquals("http://dbpedia.org/page/J._K._Rowling", m1
.listStatements().nextStatement().getSubject().getURI());
TestCase.assertEquals("http://dbpedia.org/property/children", m1
.listStatements().nextStatement().getPredicate().getURI());
TestCase.assertTrue(m1.listStatements().nextStatement().getObject()
.canAs(Literal.class));
TestCase.assertEquals("2^^http://www.w3.org/2001/XMLSchema#integer", m1
.listStatements().nextStatement().getObject().toString());
hEle.setTextContent("3");
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals("3^^http://www.w3.org/2001/XMLSchema#integer", m1
.listStatements().nextStatement().getObject().toString());
parent.removeChild(hEle);
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(0, m1.size());
parent.appendChild(hEle);
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(1, m1.size());
parent.removeChild(hEle);
TableTableCellElement ttce = contentDom
.newOdfElement(TableTableCellElement.class);
parent.appendChild(ttce);
ttce.setXhtmlAboutAttribute("[dbpedia:J._K._Rowling]");
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(0, m1.size());
ttce.setXhtmlPropertyAttribute("dbpprop:nationality");
ttce.setTextContent("British");
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(1, m1.size());
ttce.setXhtmlAboutAttribute("http://dbpedia.org/page/J._R._R._Tolkien");
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(1, m1.size());
TestCase.assertEquals("http://dbpedia.org/page/J._R._R._Tolkien", m1
.listStatements().nextStatement().getSubject().getURI());
TableCoveredTableCellElement tctce = contentDom
.newOdfElement(TableCoveredTableCellElement.class);
parent.appendChild(tctce);
tctce.setXhtmlAboutAttribute("[dbpedia:J._R._R._Tolkien]");
tctce.setXhtmlPropertyAttribute("dbpprop:shortDescription");
tctce.setXhtmlContentAttribute("British philologist and author");
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(2, m1.size());
parent.removeChild(ttce);
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(1, m1.size());
parent.appendChild(ttce);
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(2, m1.size());
parent.removeChild(ttce);
parent.removeChild(tctce);
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(0, m1.size());
parent.appendChild(tctce);
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(1, m1.size());
parent.removeChild(tctce);
m1 = odt.getInContentMetadataFromCache();
TestCase.assertEquals(0, m1.size());
}