@Test
public void testReplaceWithSimpleField_time_field() {
try {
search = new TextNavigation("ReplaceDateTarget", doc);
// count the initial date field count. should be 1.
OdfContentDom contentDom = doc.getContentDom();
NodeList nodeList = contentDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName());
int i = nodeList.getLength();
//change all <code>ext:fixed</code> value be false
for(int k =0;k<nodeList.getLength();k++){
Node nv = nodeList.item(k);
if(nv.getFirstChild().getNodeValue().matches("^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$")){
NamedNodeMap nameMap = nv.getAttributes();
Node nfix = nameMap.getNamedItem("text:fixed");
nfix.setNodeValue("false");
}
}
OdfStylesDom styleDom = doc.getStylesDom();
nodeList = styleDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName());
i += nodeList.getLength();
// replace all the 3 "ReplaceDateTarget" to FixedDateField.
while (search.hasNext()) {
TextSelection item = (TextSelection) search.nextSelection();
FieldSelection fieldSelection = new FieldSelection(item);
//fieldSelection.replaceWithSimpleField(Field.FieldType.FIXED_DATE_FIELD);
fieldSelection.replaceWithSimpleField(Field.FieldType.TIME_FIELD);
i++;
}
nodeList = contentDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName());
int j = nodeList.getLength();
nodeList = styleDom.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName());
j += nodeList.getLength();
Assert.assertEquals(j, i);
//save
doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE));
//validate
TextDocument doc1 = (TextDocument) Document.loadDocument(ResourceUtilities.getAbsolutePath(SAVE_FILE_REPLACE));
OdfContentDom contentDom1 = doc1.getContentDom();
nodeList = contentDom1.getElementsByTagName(TextTimeElement.ELEMENT_NAME.getQName());
for(int k =0;k<nodeList.getLength();k++){
//
Node nv = nodeList.item(k);
if(nv.getFirstChild().getNodeValue().matches("^([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$")){
NamedNodeMap nameMap = nv.getAttributes();