@Test public void testReplaceWithSimpleField() { try { search = new TextNavigation("ReplaceDateTarget", doc); OdfContentDom contentDom = doc.getContentDom(); NodeList nodeList = contentDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); int i = nodeList.getLength(); OdfStylesDom styleDom = doc.getStylesDom(); nodeList = styleDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); i += nodeList.getLength(); while (search.hasNext()) { TextSelection item = (TextSelection) search.nextSelection(); FieldSelection fieldSelection = new FieldSelection(item); fieldSelection.replaceWithSimpleField(Field.FieldType.FIXED_DATE_FIELD); i++; } nodeList = contentDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); int j = nodeList.getLength(); nodeList = styleDom.getElementsByTagName(TextDateElement.ELEMENT_NAME.getQName()); j += nodeList.getLength(); Assert.assertEquals(j, i); doc.save(ResourceUtilities.newTestOutputFile(SAVE_FILE_REPLACE)); } catch (Exception e) { Logger.getLogger(FieldSelectionTest.class.getName()).log(Level.SEVERE, e.getMessage(), e); Assert.fail("Failed with " + e.getClass().getName() + ": '" + e.getMessage() + "'"); } }
public Field replaceWithSimpleField(Field.FieldType fieldType) { int leftLength = textSelection.getText().length(); int index = textSelection.getIndex(); prepareSpanContainer(leftLength, index); Field field = null; switch (fieldType) { case DATE_FIELD: field = Fields.createDateField(spanContainer); break; case FIXED_DATE_FIELD: field = Fields.createFixedDateField(spanContainer); break; case TIME_FIELD: field = Fields.createTimeField(spanContainer); break; case FIXED_TIME_FIELD: field = Fields.createFixedTimeField(spanContainer); break; case PREVIOUS_PAGE_NUMBER_FIELD: field = Fields.createPreviousPageNumberField(spanContainer); break; case CURRENT_PAGE_NUMBER_FIELD: field = Fields.createCurrentPageNumberField(spanContainer); break; case NEXT_PAGE_NUMBER_FIELD: field = Fields.createNextPageNumberField(spanContainer); break; case PAGE_COUNT_FIELD: field = Fields.createPageCountField(spanContainer); break; case TITLE_FIELD: field = Fields.createTitleField(spanContainer); break; case SUBJECT_FIELD: field = Fields.createSubjectField(spanContainer); break; case AUTHOR_NAME_FIELD: field = Fields.createAuthorNameField(spanContainer); break; case AUTHOR_INITIALS_FIELD: field = Fields.createAuthorInitialsField(spanContainer); break; case CHAPTER_FIELD: field = Fields.createChapterField(spanContainer); break; case REFERENCE_FIELD: case SIMPLE_VARIABLE_FIELD: case USER_VARIABLE_FIELD: case CONDITION_FIELD: case HIDDEN_TEXT_FIELD: throw new IllegalArgumentException("this is not a vaild simple field type."); } textSelection.mMatchedText = field.getOdfElement().getTextContent(); int textLength = textSelection.mMatchedText.length(); int offset = textLength - leftLength; SelectionManager.refresh(textSelection.getContainerElement(), offset, index + textLength); return field; }
FieldSelection extends Selection { public Field replaceWithSimpleField(Field.FieldType fieldType) { int leftLength = textSelection.getText().length(); int index = textSelection.getIndex(); prepareSpanContainer(leftLength, index); Field field = null; switch (fieldType) { case DATE_FIELD: field = Fields.createDateField(spanContainer); break; case FIXED_DATE_FIELD: field = Fields.createFixedDateField(spanContainer); break; case TIME_FIELD: field = Fields.createTimeField(spanContainer); break; case FIXED_TIME_FIELD: field = Fields.createFixedTimeField(spanContainer); break; case PREVIOUS_PAGE_NUMBER_FIELD: field = Fields.createPreviousPageNumberField(spanContainer); break; case CURRENT_PAGE_NUMBER_FIELD: field = Fields.createCurrentPageNumberField(spanContainer); break; case NEXT_PAGE_NUMBER_FIELD: field = Fields.createNextPageNumberField(spanContainer); break; case PAGE_COUNT_FIELD: field = Fields.createPageCountField(spanContainer); break; case TITLE_FIELD: field = Fields.createTitleField(spanContainer); break; case SUBJECT_FIELD: field = Fields.createSubjectField(spanContainer); break; case AUTHOR_NAME_FIELD: field = Fields.createAuthorNameField(spanContainer); break; case AUTHOR_INITIALS_FIELD: field = Fields.createAuthorInitialsField(spanContainer); break; case CHAPTER_FIELD: field = Fields.createChapterField(spanContainer); break; case REFERENCE_FIELD: case SIMPLE_VARIABLE_FIELD: case USER_VARIABLE_FIELD: case CONDITION_FIELD: case HIDDEN_TEXT_FIELD: throw new IllegalArgumentException("this is not a vaild simple field type."); } textSelection.mMatchedText = field.getOdfElement().getTextContent(); int textLength = textSelection.mMatchedText.length(); int offset = textLength - leftLength; SelectionManager.refresh(textSelection.getContainerElement(), offset, index + textLength); return field; } }
FieldSelection extends Selection { public Field replaceWithSimpleField(Field.FieldType fieldType) { int leftLength = textSelection.getText().length(); int index = textSelection.getIndex(); prepareSpanContainer(leftLength, index); Field field = null; switch (fieldType) { case DATE_FIELD: field = Fields.createDateField(spanContainer); break; case FIXED_DATE_FIELD: field = Fields.createFixedDateField(spanContainer); break; case TIME_FIELD: field = Fields.createTimeField(spanContainer); break; case FIXED_TIME_FIELD: field = Fields.createFixedTimeField(spanContainer); break; case PREVIOUS_PAGE_NUMBER_FIELD: field = Fields.createPreviousPageNumberField(spanContainer); break; case CURRENT_PAGE_NUMBER_FIELD: field = Fields.createCurrentPageNumberField(spanContainer); break; case NEXT_PAGE_NUMBER_FIELD: field = Fields.createNextPageNumberField(spanContainer); break; case PAGE_COUNT_FIELD: field = Fields.createPageCountField(spanContainer); break; case TITLE_FIELD: field = Fields.createTitleField(spanContainer); break; case SUBJECT_FIELD: field = Fields.createSubjectField(spanContainer); break; case AUTHOR_NAME_FIELD: field = Fields.createAuthorNameField(spanContainer); break; case AUTHOR_INITIALS_FIELD: field = Fields.createAuthorInitialsField(spanContainer); break; case CHAPTER_FIELD: field = Fields.createChapterField(spanContainer); break; case REFERENCE_FIELD: case SIMPLE_VARIABLE_FIELD: case USER_VARIABLE_FIELD: case CONDITION_FIELD: case HIDDEN_TEXT_FIELD: throw new IllegalArgumentException("this is not a vaild simple field type."); } textSelection.mMatchedText = field.getOdfElement().getTextContent(); int textLength = textSelection.mMatchedText.length(); int offset = textLength - leftLength; SelectionManager.refresh(textSelection.getContainerElement(), offset, index + textLength); return field; } FieldSelection(TextSelection selection); }
FieldSelection extends Selection { public Field replaceWithSimpleField(Field.FieldType fieldType) { int leftLength = textSelection.getText().length(); int index = textSelection.getIndex(); prepareSpanContainer(leftLength, index); Field field = null; switch (fieldType) { case DATE_FIELD: field = Fields.createDateField(spanContainer); break; case FIXED_DATE_FIELD: field = Fields.createFixedDateField(spanContainer); break; case TIME_FIELD: field = Fields.createTimeField(spanContainer); break; case FIXED_TIME_FIELD: field = Fields.createFixedTimeField(spanContainer); break; case PREVIOUS_PAGE_NUMBER_FIELD: field = Fields.createPreviousPageNumberField(spanContainer); break; case CURRENT_PAGE_NUMBER_FIELD: field = Fields.createCurrentPageNumberField(spanContainer); break; case NEXT_PAGE_NUMBER_FIELD: field = Fields.createNextPageNumberField(spanContainer); break; case PAGE_COUNT_FIELD: field = Fields.createPageCountField(spanContainer); break; case TITLE_FIELD: field = Fields.createTitleField(spanContainer); break; case SUBJECT_FIELD: field = Fields.createSubjectField(spanContainer); break; case AUTHOR_NAME_FIELD: field = Fields.createAuthorNameField(spanContainer); break; case AUTHOR_INITIALS_FIELD: field = Fields.createAuthorInitialsField(spanContainer); break; case CHAPTER_FIELD: field = Fields.createChapterField(spanContainer); break; case REFERENCE_FIELD: case SIMPLE_VARIABLE_FIELD: case USER_VARIABLE_FIELD: case CONDITION_FIELD: case HIDDEN_TEXT_FIELD: throw new IllegalArgumentException("this is not a vaild simple field type."); } textSelection.mMatchedText = field.getOdfElement().getTextContent(); int textLength = textSelection.mMatchedText.length(); int offset = textLength - leftLength; SelectionManager.refresh(textSelection.getContainerElement(), offset, index + textLength); return field; } FieldSelection(TextSelection selection); Field replaceWithSimpleField(Field.FieldType fieldType); void replaceWithReferenceField(ReferenceField field, ReferenceField.DisplayType type); void replaceWithVariableField(VariableField field); ConditionField replaceWithConditionField(String condition, String trueText, String falseText); ConditionField replaceWithHiddenTextField(String condition, String text); void applyStyle(OdfStyleBase style); @Override void cut(); void replaceWith(String newText); @Override void pasteAtEndOf(Selection positionItem); @Override void pasteAtFrontOf(Selection positionItem); }
FieldSelection extends Selection { public Field replaceWithSimpleField(Field.FieldType fieldType) { int leftLength = textSelection.getText().length(); int index = textSelection.getIndex(); prepareSpanContainer(leftLength, index); Field field = null; switch (fieldType) { case DATE_FIELD: field = Fields.createDateField(spanContainer); break; case FIXED_DATE_FIELD: field = Fields.createFixedDateField(spanContainer); break; case TIME_FIELD: field = Fields.createTimeField(spanContainer); break; case FIXED_TIME_FIELD: field = Fields.createFixedTimeField(spanContainer); break; case PREVIOUS_PAGE_NUMBER_FIELD: field = Fields.createPreviousPageNumberField(spanContainer); break; case CURRENT_PAGE_NUMBER_FIELD: field = Fields.createCurrentPageNumberField(spanContainer); break; case NEXT_PAGE_NUMBER_FIELD: field = Fields.createNextPageNumberField(spanContainer); break; case PAGE_COUNT_FIELD: field = Fields.createPageCountField(spanContainer); break; case TITLE_FIELD: field = Fields.createTitleField(spanContainer); break; case SUBJECT_FIELD: field = Fields.createSubjectField(spanContainer); break; case AUTHOR_NAME_FIELD: field = Fields.createAuthorNameField(spanContainer); break; case AUTHOR_INITIALS_FIELD: field = Fields.createAuthorInitialsField(spanContainer); break; case CHAPTER_FIELD: field = Fields.createChapterField(spanContainer); break; case REFERENCE_FIELD: case SIMPLE_VARIABLE_FIELD: case USER_VARIABLE_FIELD: case CONDITION_FIELD: case HIDDEN_TEXT_FIELD: throw new IllegalArgumentException("this is not a vaild simple field type."); } textSelection.mMatchedText = field.getOdfElement().getTextContent(); int textLength = textSelection.mMatchedText.length(); int offset = textLength - leftLength; SelectionManager.refresh(textSelection.getContainerElement(), offset, index + textLength); return field; } FieldSelection(TextSelection selection); Field replaceWithSimpleField(Field.FieldType fieldType); void replaceWithReferenceField(ReferenceField field, ReferenceField.DisplayType type); void replaceWithVariableField(VariableField field); ConditionField replaceWithConditionField(String condition, String trueText, String falseText); ConditionField replaceWithHiddenTextField(String condition, String text); void applyStyle(OdfStyleBase style); @Override void cut(); void replaceWith(String newText); @Override void pasteAtEndOf(Selection positionItem); @Override void pasteAtFrontOf(Selection positionItem);  }