Search in sources :

Example 1 with IllegalArgumentException

use of com.sun.star.lang.IllegalArgumentException in project LAMSADE-tools by LAntoine.

the class ConnectionToYearbook method htmlPageFiller.

/**
	 *
	 * @param webtrgt
	 *            is the webtarget (url with parameters)
	 * @return a filled html page File
	 * @throws IllegalArgumentException
	 *             if webtarget is null
	 * @throws NullPointerException
	 *             if no data found
	 * @throws FileNotFoundException
	 */
private InputStream htmlPageFiller(WebTarget webtrgt) throws IllegalArgumentException, NullPointerException, FileNotFoundException {
    if (webtrgt == null) {
        throw new IllegalArgumentException("Web Target is null, error during the target construction");
    }
    htmlPageFile = webtrgt.request(MediaType.TEXT_HTML_TYPE).get(File.class);
    if (htmlPageFile == null) {
        throw new NullPointerException("htmlPage has no data, the yearbook site may be down");
    }
    logger.debug("Yearbook successfully targeted");
    htmlPage = new FileInputStream(htmlPageFile);
    return htmlPage;
}
Also used : File(java.io.File) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException) FileInputStream(java.io.FileInputStream)

Example 2 with IllegalArgumentException

use of com.sun.star.lang.IllegalArgumentException 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 3 with IllegalArgumentException

use of com.sun.star.lang.IllegalArgumentException 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 4 with IllegalArgumentException

use of com.sun.star.lang.IllegalArgumentException in project jabref by JabRef.

the class OOBibBase method insertEntry.

/**
     * This method inserts a cite marker in the text for the given BibEntry,
     * and may refresh the bibliography.
     * @param entries The entries to cite.
     * @param database The database the entry belongs to.
     * @param style The bibliography style we are using.
     * @param inParenthesis Indicates whether it is an in-text citation or a citation in parenthesis.
     *   This is not relevant if numbered citations are used.
     * @param withText Indicates whether this should be a normal citation (true) or an empty
     *   (invisible) citation (false).
     * @param sync Indicates whether the reference list should be refreshed.
     * @throws IllegalTypeException
     * @throws PropertyExistException
     * @throws NotRemoveableException
     * @throws UnknownPropertyException
     * @throws UndefinedCharacterFormatException
     * @throws NoSuchElementException
     * @throws WrappedTargetException
     * @throws IOException
     * @throws PropertyVetoException
     * @throws CreationException
     * @throws BibEntryNotFoundException
     * @throws UndefinedParagraphFormatException
     */
public void insertEntry(List<BibEntry> entries, BibDatabase database, List<BibDatabase> allBases, OOBibStyle style, boolean inParenthesis, boolean withText, String pageInfo, boolean sync) throws IllegalArgumentException, UnknownPropertyException, NotRemoveableException, PropertyExistException, IllegalTypeException, UndefinedCharacterFormatException, WrappedTargetException, NoSuchElementException, PropertyVetoException, IOException, CreationException, BibEntryNotFoundException, UndefinedParagraphFormatException {
    try {
        XTextViewCursor xViewCursor = xViewCursorSupplier.getViewCursor();
        if (entries.size() > 1) {
            if (style.getBooleanCitProperty(OOBibStyle.MULTI_CITE_CHRONOLOGICAL)) {
                entries.sort(yearAuthorTitleComparator);
            } else {
                entries.sort(entryComparator);
            }
        }
        String keyString = String.join(",", entries.stream().map(entry -> entry.getCiteKeyOptional().orElse("")).collect(Collectors.toList()));
        // Insert bookmark:
        String bName = getUniqueReferenceMarkName(keyString, withText ? inParenthesis ? OOBibBase.AUTHORYEAR_PAR : OOBibBase.AUTHORYEAR_INTEXT : OOBibBase.INVISIBLE_CIT);
        // If we should store metadata for page info, do that now:
        if (pageInfo != null) {
            LOGGER.info("Storing page info: " + pageInfo);
            setCustomProperty(bName, pageInfo);
        }
        xViewCursor.getText().insertString(xViewCursor, " ", false);
        if (style.isFormatCitations()) {
            XPropertySet xCursorProps = UnoRuntime.queryInterface(XPropertySet.class, xViewCursor);
            String charStyle = style.getCitationCharacterFormat();
            try {
                xCursorProps.setPropertyValue(CHAR_STYLE_NAME, charStyle);
            } catch (UnknownPropertyException | PropertyVetoException | IllegalArgumentException | WrappedTargetException ex) {
                // Setting the character format failed, so we throw an exception that
                // will result in an error message for the user. Before that,
                // delete the space we inserted:
                xViewCursor.goLeft((short) 1, true);
                xViewCursor.setString("");
                throw new UndefinedCharacterFormatException(charStyle);
            }
        }
        xViewCursor.goLeft((short) 1, false);
        Map<BibEntry, BibDatabase> databaseMap = new HashMap<>();
        for (BibEntry entry : entries) {
            databaseMap.put(entry, database);
        }
        String citeText = style.isNumberEntries() ? "-" : style.getCitationMarker(entries, databaseMap, inParenthesis, null, null);
        insertReferenceMark(bName, citeText, xViewCursor, withText, style);
        xViewCursor.collapseToEnd();
        xViewCursor.goRight((short) 1, false);
        XTextRange position = xViewCursor.getEnd();
        if (sync) {
            // To account for numbering and for uniqiefiers, we must refresh the cite markers:
            updateSortedReferenceMarks();
            refreshCiteMarkers(allBases, style);
            // Insert it at the current position:
            rebuildBibTextSection(allBases, style);
        }
        // Go back to the relevant position:
        xViewCursor.gotoRange(position, false);
    } catch (DisposedException ex) {
        // or catch a DisposedException (which is in a OO JAR file).
        throw new ConnectionLostException(ex.getMessage());
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) XTextRange(com.sun.star.text.XTextRange) WrappedTargetException(com.sun.star.lang.WrappedTargetException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UnknownPropertyException(com.sun.star.beans.UnknownPropertyException) XPropertySet(com.sun.star.beans.XPropertySet) PropertyVetoException(com.sun.star.beans.PropertyVetoException) BibDatabase(org.jabref.model.database.BibDatabase) IllegalArgumentException(com.sun.star.lang.IllegalArgumentException) XTextViewCursor(com.sun.star.text.XTextViewCursor) DisposedException(com.sun.star.lang.DisposedException)

Example 5 with IllegalArgumentException

use of com.sun.star.lang.IllegalArgumentException 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

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