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;
}
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();
}
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);
}
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());
}
}
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;
}
Aggregations