com.sun.star.uno.AnyConverter Java Examples

The following examples show how to use com.sun.star.uno.AnyConverter. 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: MemoryUsage.java    From kkFileViewOfficeEdit with Apache License 2.0 6 votes vote down vote up
private XSpreadsheet createSpreadsheet(XScriptContext ctxt)
    throws Exception
{
    XComponentLoader loader = (XComponentLoader)
        UnoRuntime.queryInterface(
            XComponentLoader.class, ctxt.getDesktop());

    XComponent comp = loader.loadComponentFromURL(
        "private:factory/scalc", "_blank", 4, new PropertyValue[0]);

    XSpreadsheetDocument doc = (XSpreadsheetDocument)
        UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);

    XIndexAccess index = (XIndexAccess)
        UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());

    XSpreadsheet sheet = (XSpreadsheet) AnyConverter.toObject(
        new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));

    return sheet;
}
 
Example #2
Source File: MemoryUsage.java    From kkFileView with Apache License 2.0 6 votes vote down vote up
private XSpreadsheet createSpreadsheet(XScriptContext ctxt)
    throws Exception
{
    XComponentLoader loader = (XComponentLoader)
        UnoRuntime.queryInterface(
            XComponentLoader.class, ctxt.getDesktop());

    XComponent comp = loader.loadComponentFromURL(
        "private:factory/scalc", "_blank", 4, new PropertyValue[0]);

    XSpreadsheetDocument doc = (XSpreadsheetDocument)
        UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);

    XIndexAccess index = (XIndexAccess)
        UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());

    XSpreadsheet sheet = (XSpreadsheet) AnyConverter.toObject(
        new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));

    return sheet;
}
 
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: 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 #5
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 #6
Source File: HighlightText.java    From kkFileViewOfficeEdit with Apache License 2.0 4 votes vote down vote up
private boolean tryLoadingLibrary(
    XMultiComponentFactory xmcf, XScriptContext context, String name)
{
    System.err.println("Try to load ScriptBindingLibrary");

    try {
        Object obj = xmcf.createInstanceWithContext(
           "com.sun.star.script.Application" + name + "LibraryContainer",
           context.getComponentContext());

        XLibraryContainer xLibraryContainer = (XLibraryContainer)
            UnoRuntime.queryInterface(XLibraryContainer.class, obj);

        System.err.println("Got XLibraryContainer");

        Object serviceObj = context.getComponentContext().getValueByName(
            "/singletons/com.sun.star.util.theMacroExpander");
                                                                            
        XMacroExpander xme = (XMacroExpander) AnyConverter.toObject(
            new Type(XMacroExpander.class), serviceObj);
                                                                            
        String bootstrapName = "bootstraprc";
        if (System.getProperty("os.name").startsWith("Windows")) {
            bootstrapName = "bootstrap.ini";
        }

        String libURL = xme.expandMacros(
            "${$OOO_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" +
            "/share/basic/ScriptBindingLibrary/" +
            name.toLowerCase() + ".xlb/");

        System.err.println("libURL is: " + libURL);

        xLibraryContainer.createLibraryLink(
            "ScriptBindingLibrary", libURL, false);

        System.err.println("liblink created");

    } catch (com.sun.star.uno.Exception e) {
        System.err.println("Got an exception loading lib: " + e.getMessage());
        return false;
    }
    return true;
}
 
Example #7
Source File: HighlightText.java    From kkFileView with Apache License 2.0 4 votes vote down vote up
private boolean tryLoadingLibrary(
    XMultiComponentFactory xmcf, XScriptContext context, String name)
{
    System.err.println("Try to load ScriptBindingLibrary");

    try {
        Object obj = xmcf.createInstanceWithContext(
           "com.sun.star.script.Application" + name + "LibraryContainer",
           context.getComponentContext());

        XLibraryContainer xLibraryContainer = (XLibraryContainer)
            UnoRuntime.queryInterface(XLibraryContainer.class, obj);

        System.err.println("Got XLibraryContainer");

        Object serviceObj = context.getComponentContext().getValueByName(
            "/singletons/com.sun.star.util.theMacroExpander");
                                                                            
        XMacroExpander xme = (XMacroExpander) AnyConverter.toObject(
            new Type(XMacroExpander.class), serviceObj);
                                                                            
        String bootstrapName = "bootstraprc";
        if (System.getProperty("os.name").startsWith("Windows")) {
            bootstrapName = "bootstrap.ini";
        }

        String libURL = xme.expandMacros(
            "${$OOO_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" +
            "/share/basic/ScriptBindingLibrary/" +
            name.toLowerCase() + ".xlb/");

        System.err.println("libURL is: " + libURL);

        xLibraryContainer.createLibraryLink(
            "ScriptBindingLibrary", libURL, false);

        System.err.println("liblink created");

    } catch (com.sun.star.uno.Exception e) {
        System.err.println("Got an exception loading lib: " + e.getMessage());
        return false;
    }
    return true;
}
 
Example #8
Source File: TextContentService.java    From noa-libre with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs new image.
 * 
 * @param graphicInfo the graphic information to construct image with
 * 
 * @return new image
 * 
 * @throws TextException if the image can not be constructed
 * 
 * @author Markus Krüger
 * @date 09.07.2007
 */
public ITextDocumentImage constructNewImage(GraphicInfo graphicInfo) throws TextException {
  try {
    if (xMultiServiceFactory == null)
      throw new TextException("OpenOffice.org XMultiServiceFactory inteface not valid.");

    if (xBitmapContainer == null)
      xBitmapContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class,
          xMultiServiceFactory.createInstance("com.sun.star.drawing.BitmapTable"));

    XTextContent xImage = (XTextContent) UnoRuntime.queryInterface(XTextContent.class,
        xMultiServiceFactory.createInstance("com.sun.star.text.TextGraphicObject"));

    XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xImage);

    String tempId = "tempImageId" + System.currentTimeMillis();
    xBitmapContainer.insertByName(tempId, graphicInfo.getUrl());
    String internalURL = AnyConverter.toString(xBitmapContainer.getByName(tempId));

    xProps.setPropertyValue("AnchorType", graphicInfo.getAnchor());
    xProps.setPropertyValue("GraphicURL", internalURL);
    xProps.setPropertyValue("Width", Integer.valueOf(graphicInfo.getWidth()));
    xProps.setPropertyValue("Height", Integer.valueOf(graphicInfo.getHeight()));
    xProps.setPropertyValue("HoriOrient", Short.valueOf(graphicInfo.getHorizontalAlignment()));
    xProps.setPropertyValue("VertOrient", Short.valueOf(graphicInfo.getVerticalAlignment()));

    ITextDocumentImage textDocumentImage = new TextDocumentImage(textDocument,
        xImage,
        graphicInfo);

    if (imageToImageIds == null)
      imageToImageIds = new HashMap<ITextDocumentImage, String>();
    imageToImageIds.put(textDocumentImage, tempId);

    return textDocumentImage;
  }
  catch (Exception exception) {
    TextException textException = new TextException(exception.getMessage());
    textException.initCause(exception);
    throw textException;
  }
}
 
Example #9
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)));
}