Search in sources :

Example 1 with XNamed

use of com.sun.star.container.XNamed in project jabref by JabRef.

the class OOBibBase method insertReferenceMark.

private void insertReferenceMark(String name, String citationText, XTextCursor position, boolean withText, OOBibStyle style) throws UnknownPropertyException, WrappedTargetException, PropertyVetoException, IllegalArgumentException, UndefinedCharacterFormatException, CreationException {
    // Check if there is "page info" stored for this citation. If so, insert it into
    // the citation text before inserting the citation:
    Optional<String> pageInfo = getCustomProperty(name);
    String citText;
    if ((pageInfo.isPresent()) && !pageInfo.get().isEmpty()) {
        citText = style.insertPageInfo(citationText, pageInfo.get());
    } else {
        citText = citationText;
    }
    Object bookmark;
    try {
        bookmark = mxDocFactory.createInstance("com.sun.star.text.ReferenceMark");
    } catch (Exception e) {
        throw new CreationException(e.getMessage());
    }
    // Name the reference
    XNamed xNamed = UnoRuntime.queryInterface(XNamed.class, bookmark);
    xNamed.setName(name);
    if (withText) {
        position.setString(citText);
        XPropertySet xCursorProps = UnoRuntime.queryInterface(XPropertySet.class, position);
        // Set language to [None]:
        xCursorProps.setPropertyValue("CharLocale", new Locale("zxx", "", ""));
        if (style.isFormatCitations()) {
            String charStyle = style.getCitationCharacterFormat();
            try {
                xCursorProps.setPropertyValue(CHAR_STYLE_NAME, charStyle);
            } catch (UnknownPropertyException | PropertyVetoException | IllegalArgumentException | WrappedTargetException ex) {
                throw new UndefinedCharacterFormatException(charStyle);
            }
        }
    } else {
        position.setString("");
    }
    // get XTextContent interface
    XTextContent xTextContent = UnoRuntime.queryInterface(XTextContent.class, bookmark);
    position.getText().insertTextContent(position, xTextContent, true);
    // Check if we should italicize the "et al." string in citations:
    boolean italicize = style.getBooleanCitProperty(OOBibStyle.ITALIC_ET_AL);
    if (italicize) {
        String etAlString = style.getStringCitProperty(OOBibStyle.ET_AL_STRING);
        int index = citText.indexOf(etAlString);
        if (index >= 0) {
            italicizeOrBold(position, true, index, index + etAlString.length());
        }
    }
    position.collapseToEnd();
}
Also used : Locale(com.sun.star.lang.Locale) XNamed(com.sun.star.container.XNamed) WrappedTargetException(com.sun.star.lang.WrappedTargetException) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) PropertyVetoException(com.sun.star.beans.PropertyVetoException) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException) IllegalTypeException(com.sun.star.beans.IllegalTypeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WrappedTargetException(com.sun.star.lang.WrappedTargetException) BootstrapException(com.sun.star.comp.helper.BootstrapException) DisposedException(com.sun.star.lang.DisposedException) NoSuchElementException(com.sun.star.container.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) UndefinedParagraphFormatException(org.jabref.logic.openoffice.UndefinedParagraphFormatException) IOException(java.io.IOException) NotRemoveableException(com.sun.star.beans.NotRemoveableException) PropertyExistException(com.sun.star.beans.PropertyExistException) Point(com.sun.star.awt.Point) XPropertySet(com.sun.star.beans.XPropertySet) PropertyVetoException(com.sun.star.beans.PropertyVetoException) XTextContent(com.sun.star.text.XTextContent) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException)

Example 2 with XNamed

use of com.sun.star.container.XNamed in project jabref by JabRef.

the class OOBibBase method createBibTextSection2.

private void createBibTextSection2(boolean end) throws IllegalArgumentException, CreationException {
    XTextCursor mxDocCursor = text.createTextCursor();
    if (end) {
        mxDocCursor.gotoEnd(false);
    }
    OOUtil.insertParagraphBreak(text, mxDocCursor);
    // Create a new TextSection from the document factory and access it's XNamed interface
    XNamed xChildNamed;
    try {
        xChildNamed = UnoRuntime.queryInterface(XNamed.class, mxDocFactory.createInstance("com.sun.star.text.TextSection"));
    } catch (Exception e) {
        throw new CreationException(e.getMessage());
    }
    // Set the new sections name to 'Child_Section'
    xChildNamed.setName(OOBibBase.BIB_SECTION_NAME);
    // Access the Child_Section's XTextContent interface and insert it into the document
    XTextContent xChildSection = UnoRuntime.queryInterface(XTextContent.class, xChildNamed);
    text.insertTextContent(mxDocCursor, xChildSection, false);
}
Also used : XNamed(com.sun.star.container.XNamed) XTextContent(com.sun.star.text.XTextContent) XTextCursor(com.sun.star.text.XTextCursor) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) PropertyVetoException(com.sun.star.beans.PropertyVetoException) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException) IllegalTypeException(com.sun.star.beans.IllegalTypeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WrappedTargetException(com.sun.star.lang.WrappedTargetException) BootstrapException(com.sun.star.comp.helper.BootstrapException) DisposedException(com.sun.star.lang.DisposedException) NoSuchElementException(com.sun.star.container.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) UndefinedParagraphFormatException(org.jabref.logic.openoffice.UndefinedParagraphFormatException) IOException(java.io.IOException) NotRemoveableException(com.sun.star.beans.NotRemoveableException) PropertyExistException(com.sun.star.beans.PropertyExistException)

Example 3 with XNamed

use of com.sun.star.container.XNamed in project jabref by JabRef.

the class OOBibBase method insertBookMark.

private XTextContent insertBookMark(String name, XTextCursor position) throws IllegalArgumentException, CreationException {
    Object bookmark;
    try {
        bookmark = mxDocFactory.createInstance("com.sun.star.text.Bookmark");
    } catch (Exception e) {
        throw new CreationException(e.getMessage());
    }
    // name the bookmark
    XNamed xNamed = UnoRuntime.queryInterface(XNamed.class, bookmark);
    xNamed.setName(name);
    // get XTextContent interface
    XTextContent xTextContent = UnoRuntime.queryInterface(XTextContent.class, bookmark);
    // insert bookmark at the end of the document
    // instead of mxDocText.getEnd you could use a text cursor's XTextRange interface or any XTextRange
    text.insertTextContent(position, xTextContent, true);
    position.collapseToEnd();
    return xTextContent;
}
Also used : XNamed(com.sun.star.container.XNamed) XTextContent(com.sun.star.text.XTextContent) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) PropertyVetoException(com.sun.star.beans.PropertyVetoException) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException) IllegalTypeException(com.sun.star.beans.IllegalTypeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WrappedTargetException(com.sun.star.lang.WrappedTargetException) BootstrapException(com.sun.star.comp.helper.BootstrapException) DisposedException(com.sun.star.lang.DisposedException) NoSuchElementException(com.sun.star.container.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) UndefinedParagraphFormatException(org.jabref.logic.openoffice.UndefinedParagraphFormatException) IOException(java.io.IOException) NotRemoveableException(com.sun.star.beans.NotRemoveableException) PropertyExistException(com.sun.star.beans.PropertyExistException)

Aggregations

IllegalTypeException (com.sun.star.beans.IllegalTypeException)3 NotRemoveableException (com.sun.star.beans.NotRemoveableException)3 PropertyExistException (com.sun.star.beans.PropertyExistException)3 PropertyVetoException (com.sun.star.beans.PropertyVetoException)3 UnknownPropertyException (com.sun.star.beans.UnknownPropertyException)3 BootstrapException (com.sun.star.comp.helper.BootstrapException)3 NoSuchElementException (com.sun.star.container.NoSuchElementException)3 XNamed (com.sun.star.container.XNamed)3 DisposedException (com.sun.star.lang.DisposedException)3 IllegalArgumentException (com.sun.star.lang.IllegalArgumentException)3 WrappedTargetException (com.sun.star.lang.WrappedTargetException)3 XTextContent (com.sun.star.text.XTextContent)3 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 MalformedURLException (java.net.MalformedURLException)3 UndefinedParagraphFormatException (org.jabref.logic.openoffice.UndefinedParagraphFormatException)3 Point (com.sun.star.awt.Point)1 XPropertySet (com.sun.star.beans.XPropertySet)1 Locale (com.sun.star.lang.Locale)1 XTextCursor (com.sun.star.text.XTextCursor)1