com.sun.star.lang.IllegalArgumentException Java Examples

The following examples show how to use com.sun.star.lang.IllegalArgumentException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractConversionTask.java    From kkFileView with Apache License 2.0 6 votes vote down vote up
private XComponent loadDocument(OfficeContext context, File inputFile) throws OfficeException {
    if (!inputFile.exists()) {
        throw new OfficeException("input document not found");
    }
    XComponentLoader loader = cast(XComponentLoader.class, context.getService(SERVICE_DESKTOP));
    Map<String,?> loadProperties = getLoadProperties(inputFile);
    XComponent document = null;
    try {
        document = loader.loadComponentFromURL(toUrl(inputFile), "_blank", 0, toUnoProperties(loadProperties));
    } catch (IllegalArgumentException illegalArgumentException) {
        throw new OfficeException("could not load document: " + inputFile.getName(), illegalArgumentException);
    } catch (ErrorCodeIOException errorCodeIOException) {
        throw new OfficeException("could not load document: "  + inputFile.getName() + "; errorCode: " + errorCodeIOException.ErrCode, errorCodeIOException);
    } catch (IOException ioException) {
        throw new OfficeException("could not load document: "  + inputFile.getName(), ioException);
    }
    if (document == null) {
        throw new OfficeException("could not load document: "  + inputFile.getName());
    }
    return document;
}
 
Example #2
Source File: AbstractConversionTask.java    From wenku with MIT License 6 votes vote down vote up
private XComponent loadDocument(OfficeContext context, File inputFile) throws OfficeException {
    if (!inputFile.exists()) {
        throw new OfficeException("input document not found");
    }
    XComponentLoader loader = cast(XComponentLoader.class, context.getService(SERVICE_DESKTOP));
    Map<String,?> loadProperties = getLoadProperties(inputFile);
    XComponent document = null;
    try {
        document = loader.loadComponentFromURL(toUrl(inputFile), "_blank", 0, toUnoProperties(loadProperties));
    } catch (IllegalArgumentException illegalArgumentException) {
        throw new OfficeException("could not load document: " + inputFile.getName(), illegalArgumentException);
    } catch (ErrorCodeIOException errorCodeIOException) {
        throw new OfficeException("could not load document: "  + inputFile.getName() + "; errorCode: " + errorCodeIOException.ErrCode, errorCodeIOException);
    } catch (IOException ioException) {
        throw new OfficeException("could not load document: "  + inputFile.getName(), ioException);
    }
    if (document == null) {
        throw new OfficeException("could not load document: "  + inputFile.getName());
    }
    return document;
}
 
Example #3
Source File: AnglePattern.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Converts the given argument to a pattern valid for {@link AngleFormat}.
 *
 * @param  patternOrVoid  the optional pattern argument from the OpenOffice formula.
 * @throws IllegalArgumentException if {@code patternOrVoid} is not a string value or void.
 */
AnglePattern(final Object patternOrVoid) throws IllegalArgumentException {
    if (AnyConverter.isVoid(patternOrVoid)) {
        pattern = "D°MM'SS.s\"";
    } else {
        pattern = AnyConverter.toString(patternOrVoid);
        final int lc = pattern.length() - 1;
        if (lc > 0) {
            final char c = pattern.charAt(lc);
            switch (c) {
                case 'N': case 'n': case 'S': case 's': type = LATITUDE;  break;
                case 'E': case 'e': case 'W': case 'w': type = LONGITUDE; break;
                default: return;
            }
            pattern = pattern.substring(0, lc);
        }
    }
}
 
Example #4
Source File: AbstractConversionTask.java    From kkFileViewOfficeEdit with Apache License 2.0 6 votes vote down vote up
private XComponent loadDocument(OfficeContext context, File inputFile) throws OfficeException {
    if (!inputFile.exists()) {
        throw new OfficeException("input document not found");
    }
    XComponentLoader loader = cast(XComponentLoader.class, context.getService(SERVICE_DESKTOP));
    Map<String,?> loadProperties = getLoadProperties(inputFile);
    XComponent document = null;
    try {
        document = loader.loadComponentFromURL(toUrl(inputFile), "_blank", 0, toUnoProperties(loadProperties));
    } catch (IllegalArgumentException illegalArgumentException) {
        throw new OfficeException("could not load document: " + inputFile.getName(), illegalArgumentException);
    } catch (ErrorCodeIOException errorCodeIOException) {
        throw new OfficeException("could not load document: "  + inputFile.getName() + "; errorCode: " + errorCodeIOException.ErrCode, errorCodeIOException);
    } catch (IOException ioException) {
        throw new OfficeException("could not load document: "  + inputFile.getName(), ioException);
    }
    if (document == null) {
        throw new OfficeException("could not load document: "  + inputFile.getName());
    }
    return document;
}
 
Example #5
Source File: ReferencingFunctions.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the accuracy of a transformation between two coordinate reference systems.
 *
 * @param  sourceCRS       the authority code for the source coordinate reference system.
 * @param  targetCRS       the authority code for the target coordinate reference system.
 * @param  areaOfInterest  an optional bounding box of source coordinates to transform.
 * @throws IllegalArgumentException if {@code points} is not a {@code double[][]} value or void.
 * @return the operation accuracy.
 */
@Override
public double getAccuracy(final String sourceCRS, final String targetCRS, final Object areaOfInterest)
        throws IllegalArgumentException
{
    final double[][] coordinates;
    if (AnyConverter.isVoid(areaOfInterest)) {
        coordinates = null;
    } else if (areaOfInterest instanceof double[][]) {
        coordinates = (double[][]) areaOfInterest;
    } else if (areaOfInterest instanceof Object[][]) {
        final Object[][] values = (Object[][]) areaOfInterest;
        coordinates = new double[values.length][];
        for (int j=0; j<values.length; j++) {
            final Object[] row = values[j];
            final double[] coord = new double[row.length];
            for (int i=0; i<row.length; i++) {
                coord[i] = AnyConverter.toDouble(row[i]);
            }
            coordinates[j] = coord;
        }
    } else {
        throw new IllegalArgumentException();
    }
    try {
        return new Transformer(this, getCRS(sourceCRS), targetCRS, coordinates).getAccuracy();
    } catch (Exception exception) {
        reportException("getAccuracy", exception);
        return Double.NaN;
    }
}
 
Example #6
Source File: ReferencingFunctionsTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link ReferencingFunctions#formatAngle(String, Object)}.
 *
 * @throws IllegalArgumentException if the pattern used by the test is not a string or void.
 */
@Test
public void testFormatAngle() throws IllegalArgumentException {
    assertEquals("43°30.0'", singleton(instance.formatAngle(new double[][] {{43.50}}, "D°MM.m'", "en")));
    assertEquals("4330",     singleton(instance.formatAngle(new double[][] {{43.50}}, "DMM",     "en")));
    assertEquals("-3°15.0'", singleton(instance.formatAngle(new double[][] {{-3.25}}, "D°MM.m'", "en")));
}
 
Example #7
Source File: ReferencingFunctionsTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link ReferencingFunctions#parseAngle(String, Object)}.
 *
 * @throws IllegalArgumentException if the pattern used by the test is not a string or void.
 */
@Test
public void testParseAngle() throws IllegalArgumentException {
    assertEquals(43.50, singleton(instance.parseAngle(new String[][] {{"43°30'"}}, "D°MM.m'", "en")), STRICT);
    assertEquals(43.50, singleton(instance.parseAngle(new String[][] {{"4330"}},   "DMM",     "en")), STRICT);
    assertEquals(-3.25, singleton(instance.parseAngle(new String[][] {{"-3°15'"}}, "D°MM.m'", "en")), STRICT);
}
 
Example #8
Source File: ReferencingFunctionsTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link ReferencingFunctions#getAccuracy(String, String, double[][])}.
 * This test asks for a transformation from NAD83 to WGS84.
 *
 * @throws IllegalArgumentException if {@code points} is not a {@code double[][]} value or void.
 */
@Test
public void testGetAccuracy() throws IllegalArgumentException {
    final double accuracy = instance.getAccuracy("EPSG:4269", "EPSG:4326", new double[][] {
        {37.783, -122.417},     // San-Francisco
        {40.713,  -74.006},     // New-York
        {34.050, -118.250},     // Los Angeles
        {29.763,  -95.383},     // Houston
        {41.837,  -87.685},     // Chicago
        {25.775,  -80.209},     // Miami
    });
    assertTrue("Accuracy = " + accuracy,
            accuracy > Formulas.LINEAR_TOLERANCE &&
            accuracy <= PositionalAccuracyConstant.UNKNOWN_ACCURACY);
}
 
Example #9
Source File: ReferencingFunctions.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Converts text in degrees-minutes-seconds to an angle in decimal degrees.
 * See {@link org.apache.sis.measure.AngleFormat} for pattern description.
 *
 * @param  text     the text to be converted to an angle.
 * @param  pattern  an optional text that describes the format (example: "D°MM.m'").
 * @param  locale   the convention to use (e.g. decimal separator symbol).
 * @return the angle parsed as a number.
 * @throws IllegalArgumentException if {@code pattern} is not a string value or void.
 */
@Override
public double[][] parseAngle(final String[][] text, final Object pattern, final Object locale)
        throws IllegalArgumentException
{
    final AnglePattern p = new AnglePattern(pattern);
    final double[][] result = p.parse(text, AnyConverter.isVoid(locale)
            ? getJavaLocale() : Locales.parse(AnyConverter.toString(locale)));
    if (p.warning != null) {
        reportException("parseAngle", p.warning);
    }
    return result;
}
 
Example #10
Source File: BootstrapConnector.java    From yarg with Apache License 2.0 5 votes vote down vote up
/**
 * Try to connect to office.
 * 
 * @return      The remote component context
 */
protected XComponentContext getRemoteContext(XUnoUrlResolver xUrlResolver) throws BootstrapException, ConnectionSetupException, IllegalArgumentException, NoConnectException {

    Object context = xUrlResolver.resolve(oooConnectionString);
    XComponentContext xContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, context);
    if (xContext == null) {
        throw new BootstrapException("no component context!");
    }
    return xContext;
}
 
Example #11
Source File: JodConverterMetadataExtracterWorker.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void execute(OfficeContext context)
{
    if (logger.isDebugEnabled())
    {
        logger.debug("Extracting metadata from file " + inputFile);
    }

    XComponent document = null;
    try
    {
        if (!inputFile.exists())
        {
            throw new OfficeException("input document not found");
        }
        XComponentLoader loader = cast(XComponentLoader.class, context
                .getService(SERVICE_DESKTOP));
        
        // Need to set the Hidden property to ensure that OOo GUI does not appear.
        PropertyValue hiddenOOo = new PropertyValue();
        hiddenOOo.Name = "Hidden";
        hiddenOOo.Value = Boolean.TRUE;
        PropertyValue readOnly = new PropertyValue();
        readOnly.Name = "ReadOnly";
        readOnly.Value = Boolean.TRUE;

        try
        {
            document = loader.loadComponentFromURL(toUrl(inputFile), "_blank", 0,
                    new PropertyValue[]{hiddenOOo, readOnly});
        } catch (IllegalArgumentException illegalArgumentException)
        {
            throw new OfficeException("could not load document: "
                    + inputFile.getName(), illegalArgumentException);
        } catch (ErrorCodeIOException errorCodeIOException)
        {
            throw new OfficeException("could not load document: "
                    + inputFile.getName() + "; errorCode: "
                    + errorCodeIOException.ErrCode, errorCodeIOException);
        } catch (IOException ioException)
        {
            throw new OfficeException("could not load document: "
                    + inputFile.getName(), ioException);
        }
        if (document == null)
        {
            throw new OfficeException("could not load document: "
                    + inputFile.getName());
        }
        XRefreshable refreshable = cast(XRefreshable.class, document);
        if (refreshable != null)
        {
            refreshable.refresh();
        }

        XDocumentInfoSupplier docInfoSupplier = cast(XDocumentInfoSupplier.class, document);
        XPropertySet propSet = cast(XPropertySet.class, docInfoSupplier.getDocumentInfo());

        // The strings below are property names as used by OOo. They need upper-case
        // initial letters.
        Object author = getPropertyValueIfAvailable(propSet, "Author");
        Object description = getPropertyValueIfAvailable(propSet, "Subject");
        Object title = getPropertyValueIfAvailable(propSet, "Title");
        
        Map<String, Serializable> results = new HashMap<String, Serializable>(3);
        results.put(KEY_AUTHOR, author == null ? null : author.toString());
        results.put(KEY_DESCRIPTION, description == null ? null : description.toString());
        results.put(KEY_TITLE, title == null ? null : title.toString());
        callback.setResults(results);
    } catch (OfficeException officeException)
    {
        throw officeException;
    } catch (Exception exception)
    {
        throw new OfficeException("conversion failed", exception);
    } finally
    {
        if (document != null)
        {
            XCloseable closeable = cast(XCloseable.class, document);
            if (closeable != null)
            {
                try
                {
                    closeable.close(true);
                } catch (CloseVetoException closeVetoException)
                {
                    // whoever raised the veto should close the document
                }
            } else
            {
                document.dispose();
            }
        }
    }
}
 
Example #12
Source File: OpenOfficeDocumentConverter.java    From tmxeditor8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Load document.
 * @param inputUrl
 *            the input url
 * @param loadProperties
 *            the load properties
 * @return the x component
 * @throws IllegalArgumentException
 *             the illegal argument exception
 */
@SuppressWarnings("unchecked")
private XComponent loadDocument(String inputUrl, Map loadProperties) throws com.sun.star.io.IOException,
		IllegalArgumentException {
	XComponentLoader desktop = openOfficeConnection.getDesktopObject();
	return desktop.loadComponentFromURL(inputUrl, "_blank", 0, toPropertyValues(loadProperties)); //$NON-NLS-1$
}
 
Example #13
Source File: ReferencingFunctions.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Converts an angle to text according to a given format. This method uses the pattern
 * described by {@link org.apache.sis.measure.AngleFormat} with the following extension:
 *
 * <ul>
 *   <li>If the pattern ends with E or W, then the angle is formatted as a longitude.</li>
 *   <li>If the pattern ends with N or S, then the angle is formatted as a latitude.</li>
 * </ul>
 *
 * @param  value    the angle value (in decimal degrees) to be converted.
 * @param  pattern  an optional text that describes the format (example: "D°MM.m'").
 * @param  locale   the convention to use (e.g. decimal separator symbol).
 * @return the angle formatted as a string.
 * @throws IllegalArgumentException if {@code pattern} is not a string value or void.
 */
@Override
public String[][] formatAngle(final double[][] value, final Object pattern, final Object locale)
        throws IllegalArgumentException
{
    return new AnglePattern(pattern).format(value, AnyConverter.isVoid(locale)
            ? getJavaLocale() : Locales.parse(AnyConverter.toString(locale)));
}
 
Example #14
Source File: OpenOfficeDocumentConverter.java    From translationstudio8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Load document.
 * @param inputUrl
 *            the input url
 * @param loadProperties
 *            the load properties
 * @return the x component
 * @throws IllegalArgumentException
 *             the illegal argument exception
 */
@SuppressWarnings("unchecked")
private XComponent loadDocument(String inputUrl, Map loadProperties) throws com.sun.star.io.IOException,
		IllegalArgumentException {
	XComponentLoader desktop = openOfficeConnection.getDesktopObject();
	return desktop.loadComponentFromURL(inputUrl, "_blank", 0, toPropertyValues(loadProperties)); //$NON-NLS-1$
}
 
Example #15
Source File: TextContentEnumeration.java    From noa-libre with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Constructs new TextContentEnumeration.
 * 
 * @param textDocument text document to be used
 * @param xTextRange OpenOffice.org XTextRange interface
 * 
 * @throws IllegalArgumentException IllegalArgumentException IllegalArgumentException if the OpenOffice.org interface 
 * is not valid
 * 
 * @author Andreas Bröker
 * @author Sebastian Rösgen
 */
public TextContentEnumeration(ITextDocument textDocument, XTextRange xTextRange) throws IllegalArgumentException {
  if(textDocument == null)
    throw new IllegalArgumentException("Submitted text document is not valid.");
  
  if(xTextRange == null)
    throw new IllegalArgumentException("Submitted OpenOffice.org XTextRange interface is not valid.");
  
  this.xTextRange = xTextRange;
  this.textDocument = textDocument;
}
 
Example #16
Source File: TextTable.java    From noa-libre with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Constructs new TextTable.
 * 
 * @param textDocument text document to be used
 * @param xTextTable OpenOffice.org XTextTable interface
 * 
 * @throws IllegalArgumentException if the submitted text document or OpenOffice.org XTextTable interface 
 * is not valid
 * 
 * @author Andreas Bröker
 */
public TextTable(ITextDocument textDocument, XTextTable xTextTable)
    throws IllegalArgumentException {
  super(textDocument);
  if (xTextTable == null)
    throw new IllegalArgumentException("Submitted OpenOffice.org XTextTable interface is not valid.");
  this.xTextTable = xTextTable;
}
 
Example #17
Source File: XReferencing.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the accuracy of a transformation between two coordinate reference systems.
 *
 * @param  sourceCRS       the authority code for the source coordinate reference system.
 * @param  targetCRS       the authority code for the target coordinate reference system.
 * @param  areaOfInterest  an optional bounding box of source coordinates to transform.
 * @return the operation accuracy.
 * @throws IllegalArgumentException if {@code points} is not a {@code double[][]} value or void.
 */
double getAccuracy(String sourceCRS, String targetCRS, Object areaOfInterest) throws IllegalArgumentException;
 
Example #18
Source File: XReferencing.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * Converts text in degrees-minutes-seconds to an angle in decimal degrees.
 * See {@link org.apache.sis.measure.AngleFormat} for pattern description.
 *
 * @param  text     the text to be converted to an angle.
 * @param  pattern  an optional text that describes the format (example: "D°MM.m'").
 * @param  locale   the convention to use (e.g. decimal separator symbol).
 * @return the angle parsed as a number.
 * @throws IllegalArgumentException if {@code pattern} is not a string value or void.
 */
double[][] parseAngle(String[][] text, Object pattern, Object locale) throws IllegalArgumentException;
 
Example #19
Source File: XReferencing.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * Converts an angle to text according to a given format. This method uses the pattern
 * described by {@link org.apache.sis.measure.AngleFormat} with the following extension:
 *
 * <ul>
 *   <li>If the pattern ends with E or W, then the angle is formatted as a longitude.</li>
 *   <li>If the pattern ends with N or S, then the angle is formatted as a latitude.</li>
 * </ul>
 *
 * @param  value    the angle value (in decimal degrees) to be converted.
 * @param  pattern  an optional text that describes the format (example: "D°MM.m'").
 * @param  locale   the convention to use (e.g. decimal separator symbol).
 * @return the angle formatted as a string.
 * @throws IllegalArgumentException if {@code pattern} is not a string value or void.
 */
String[][] formatAngle(double[][] value, Object pattern, Object locale) throws IllegalArgumentException;