use of com.sun.star.text.XText in project zotero-libreoffice-integration by zotero.
the class Document method cursorInField.
public ReferenceMark cursorInField(String fieldType) throws Exception {
// create two text cursors containing the selection
XTextViewCursor selectionCursor = getSelection();
XText text = selectionCursor.getText();
XParagraphCursor paragraphCursor1 = (XParagraphCursor) UnoRuntime.queryInterface(XParagraphCursor.class, text.createTextCursorByRange(selectionCursor));
XParagraphCursor paragraphCursor2 = (XParagraphCursor) UnoRuntime.queryInterface(XParagraphCursor.class, text.createTextCursorByRange(selectionCursor));
// extend one cursor to the beginning of the paragraph and one to the end
paragraphCursor1.goLeft((short) 1, false);
paragraphCursor1.gotoStartOfParagraph(true);
paragraphCursor2.gotoEndOfParagraph(true);
// get enumerator corresponding to first cursor
XEnumerationAccess enumeratorAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, paragraphCursor1);
Object nextElement = enumeratorAccess.createEnumeration().nextElement();
enumeratorAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, nextElement);
XEnumeration enumerator = enumeratorAccess.createEnumeration();
while (enumerator.hasMoreElements()) {
// look for a ReferenceMark or Bookmark
XPropertySet textProperties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, enumerator.nextElement());
String textPropertyType = (String) textProperties.getPropertyValue("TextPortionType");
if (textPropertyType.equals(fieldType)) {
ReferenceMark mark = mMarkManager.getMark(textProperties.getPropertyValue(fieldType), fieldType);
if (mark != null) {
// check second enumerator for the same field
enumeratorAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, paragraphCursor2);
nextElement = enumeratorAccess.createEnumeration().nextElement();
enumeratorAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, nextElement);
XEnumeration enumerator2 = enumeratorAccess.createEnumeration();
while (enumerator2.hasMoreElements()) {
textProperties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, enumerator2.nextElement());
textPropertyType = (String) textProperties.getPropertyValue("TextPortionType");
if (textPropertyType.equals(fieldType)) {
if (mark == mMarkManager.getMark(textProperties.getPropertyValue(fieldType), fieldType)) {
return mark;
}
}
}
}
}
}
return null;
}
Aggregations