com.sun.star.task.ErrorCodeIOException Java Examples

The following examples show how to use com.sun.star.task.ErrorCodeIOException. 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 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 #2
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 #3
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 #4
Source File: PersistenceService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Stores document on to the location URL.
 * 
 * @throws DocumentException if the document can not be stored or no location URL is available
 * 
 * @author Andreas Bröker
 */
public void store() throws DocumentException {
  try {
    xStorable.store();
  }
  catch (Throwable throwable) {
    String message = throwable.getMessage();
    if (throwable instanceof ErrorCodeIOException) {
      if (message == null || message.length() == 0)
        message = Messages.getString("PersistenceService.error_io_message", String.valueOf(((ErrorCodeIOException) throwable).ErrCode)); //$NON-NLS-1$
    }
    else if (message == null || message.length() == 0)
      message = ERROR_MESSAGE;
    throw new DocumentException(message, throwable);
  }
}
 
Example #5
Source File: PersistenceService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Stored document in the submitted output stream. 
 * 
 * @param outputStream output stream to be used
 * 
 * @throws DocumentException if the document can not be stored
 * 
 * @author Andreas Bröker
 * @author Alessandro Conte
 * @date 07.09.2006
 */
public void store(OutputStream outputStream) throws DocumentException {
  document.fireDocumentEvent(IDocument.EVENT_ON_SAVE);
  try {
    storeInternal(outputStream);
  }
  catch (Throwable throwable) {
    String message = throwable.getMessage();
    if (throwable instanceof ErrorCodeIOException) {
      if (message == null || message.length() == 0)
        message = Messages.getString("PersistenceService.error_io_message", String.valueOf(((ErrorCodeIOException) throwable).ErrCode)); //$NON-NLS-1$
    }
    else if (message == null || message.length() == 0)
      message = ERROR_MESSAGE;
    throw new DocumentException(message, throwable);
  }
  document.fireDocumentEvent(IDocument.EVENT_ON_SAVE_DONE);
  document.fireDocumentEvent(IDocument.EVENT_ON_SAVE_FINISHED);
}
 
Example #6
Source File: PersistenceService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Stores document in the submitted output stream.
 * And fires save-as events on office document.
 * 
 * @param outputStream output stream to be used
 * 
 * @throws NOAException if the document can not be stored
 * 
 * @author Alessandro Conte
 * @date 07.09.2006
 */
public void storeAs(OutputStream outputStream) throws NOAException {
  document.fireDocumentEvent(IDocument.EVENT_ON_SAVE_AS);
  try {
    storeInternal(outputStream);
  }
  catch (Throwable throwable) {
    String message = throwable.getMessage();
    if (throwable instanceof ErrorCodeIOException) {
      if (message == null || message.length() == 0)
        message = Messages.getString("PersistenceService.error_io_message", String.valueOf(((ErrorCodeIOException) throwable).ErrCode)); //$NON-NLS-1$
    }
    else if (message == null || message.length() == 0)
      message = ERROR_MESSAGE;
    throw new NOAException(message, throwable);
  }
  document.fireDocumentEvent(IDocument.EVENT_ON_SAVE_AS_DONE);
}
 
Example #7
Source File: AbstractConversionTask.java    From kkFileViewOfficeEdit with Apache License 2.0 5 votes vote down vote up
private void storeDocument(XComponent document, File outputFile) throws OfficeException {
    Map<String,?> storeProperties = getStoreProperties(outputFile, document);
    if (storeProperties == null) {
        throw new OfficeException("unsupported conversion");
    }
    try {
        cast(XStorable.class, document).storeToURL(toUrl(outputFile), toUnoProperties(storeProperties));
    } catch (ErrorCodeIOException errorCodeIOException) {
        throw new OfficeException("could not store document: " + outputFile.getName() + "; errorCode: " + errorCodeIOException.ErrCode, errorCodeIOException);
    } catch (IOException ioException) {
        throw new OfficeException("could not store document: " + outputFile.getName(), ioException);
    }
}
 
Example #8
Source File: AbstractConversionTask.java    From kkFileView with Apache License 2.0 5 votes vote down vote up
private void storeDocument(XComponent document, File outputFile) throws OfficeException {
    Map<String,?> storeProperties = getStoreProperties(outputFile, document);
    if (storeProperties == null) {
        throw new OfficeException("unsupported conversion");
    }
    try {
        cast(XStorable.class, document).storeToURL(toUrl(outputFile), toUnoProperties(storeProperties));
    } catch (ErrorCodeIOException errorCodeIOException) {
        throw new OfficeException("could not store document: " + outputFile.getName() + "; errorCode: " + errorCodeIOException.ErrCode, errorCodeIOException);
    } catch (IOException ioException) {
        throw new OfficeException("could not store document: " + outputFile.getName(), ioException);
    }
}
 
Example #9
Source File: AbstractConversionTask.java    From wenku with MIT License 5 votes vote down vote up
private void storeDocument(XComponent document, File outputFile) throws OfficeException {
    Map<String,?> storeProperties = getStoreProperties(outputFile, document);
    if (storeProperties == null) {
        throw new OfficeException("unsupported conversion");
    }
    try {
        cast(XStorable.class, document).storeToURL(toUrl(outputFile), toUnoProperties(storeProperties));
    } catch (ErrorCodeIOException errorCodeIOException) {
        throw new OfficeException("could not store document: " + outputFile.getName() + "; errorCode: " + errorCodeIOException.ErrCode, errorCodeIOException);
    } catch (IOException ioException) {
        throw new OfficeException("could not store document: " + outputFile.getName(), ioException);
    }
}
 
Example #10
Source File: PersistenceService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Stores document to the submitted URL.
 * 
 * @param url URL to be used as location
 * 
 * @throws DocumentException if the document can not be stored
 * 
 * @author Andreas Bröker
 */
public void store(String url) throws DocumentException {
  if (url == null)
    throw new DocumentException(Messages.getString("PersistenceService.error_url_invalid_message")); //$NON-NLS-1$

  try {
    url = URLAdapter.adaptURL(url);
    PropertyValue[] initialPropertyValues = document.getInitialProperties();
    String filterDefinition = null;
    for (int i = 0; i < initialPropertyValues.length; i++) {
      if (initialPropertyValues[i].Name.equalsIgnoreCase("FilterName"))
        filterDefinition = initialPropertyValues[i].Value.toString();
    }
    boolean useFilter = filterDefinition != null && filterDefinition.length() > 0;
    if (useFilter) {
      PropertyValue[] propertyValues = new PropertyValue[1];
      propertyValues[0] = new PropertyValue();
      propertyValues[0].Name = "FilterName"; //$NON-NLS-1$    
      propertyValues[0].Value = filterDefinition;
      xStorable.storeAsURL(url, propertyValues);
    }
    else {
      xStorable.storeAsURL(url, new PropertyValue[0]);
    }
    document.setModified(false);
  }
  catch (Throwable throwable) {
    String message = throwable.getMessage();
    if (throwable instanceof ErrorCodeIOException) {
      if (message == null || message.length() == 0)
        message = Messages.getString("PersistenceService.error_io_message", String.valueOf(((ErrorCodeIOException) throwable).ErrCode)); //$NON-NLS-1$
    }
    else if (message == null || message.length() == 0)
      message = ERROR_MESSAGE;
    throw new DocumentException(message, throwable);
  }
}
 
Example #11
Source File: OOoContentTransformerHelper.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options,
                              String sourceMimetype, String sourceExtension, String targetExtension,
                              DocumentFormat sourceFormat, DocumentFormat targetFormat)
{
    // create temporary files to convert from and to
    File tempFromFile = TempFileProvider.createTempFile(
            getTempFilePrefix()+"-source-",
            "." + sourceExtension);
    File tempToFile = TempFileProvider.createTempFile(
            getTempFilePrefix()+"-target-",
            "." + targetExtension);

    // download the content from the source reader
    saveContentInFile(sourceMimetype, reader, tempFromFile);

    try
    {
        convert(tempFromFile, sourceFormat, tempToFile, targetFormat);
        writer.putContent(tempToFile);
    }
    catch (OfficeException e)
    {
        throw new ContentIOException("OpenOffice server conversion failed: \n" +
                "   reader: " + reader + "\n" +
                "   writer: " + writer + "\n" +
                "   from file: " + tempFromFile + "\n" +
                "   to file: " + tempToFile,
                e);
    }
    catch (Throwable throwable)
    {
        // Because of the known bug with empty Spreadsheets in JodConverter try to catch exception and produce empty pdf file
        if (throwable.getCause() instanceof ErrorCodeIOException &&
                ((ErrorCodeIOException) throwable.getCause()).ErrCode == JODCONVERTER_TRANSFORMATION_ERROR_CODE)
        {
            getLogger().warn("Transformation failed: \n" +
                    "from file: " + tempFromFile + "\n" +
                    "to file: " + tempToFile +
                    "Source file " + tempFromFile + " has no content");
            produceEmptyPdfFile(tempToFile);
        }
        else
        {
            throw throwable;
        }
    }
}
 
Example #12
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 #13
Source File: PersistenceService.java    From noa-libre with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Exports document to the URL on the basis of the submitted filter.
 * 
 * @param url URL to be used as location
 * @param filter filter to be used
 * 
 * @throws DocumentException if the document can not be exported
 * 
 * @author Andreas Bröker
 */
public void export(String url, IFilter filter) throws DocumentException {
  if (url == null)
    throw new DocumentException(Messages.getString("PersistenceService.error_url_invalid_message")); //$NON-NLS-1$

  if (filter == null)
    throw new DocumentException(Messages.getString("PersistenceService.error_filter_invalid_message")); //$NON-NLS-1$

  String filterDefinition = filter.getFilterDefinition(document);

  PropertyValue[] properties = filter instanceof PDFFilter ? new PropertyValue[2]
      : new PropertyValue[1];

  if (filterDefinition != null) {
    properties[0] = new PropertyValue();
    properties[0].Name = "FilterName"; //$NON-NLS-1$
    properties[0].Value = filterDefinition;

    if (filter instanceof PDFFilter) {
      properties[1] = new PropertyValue();
      properties[1].Name = "FilterData";
      properties[1].Value = ((PDFFilter) filter).getPDFFilterProperties().toPropertyValues();
    }
  }

  if (!filter.isExternalFilter())
    document.fireDocumentEvent(IDocument.EVENT_ON_SAVE_AS);
  try {
    url = URLAdapter.adaptURL(url);
    xStorable.storeToURL(url, properties);
  }
  catch (Throwable throwable) {
    String message = throwable.getMessage();
    if (throwable instanceof ErrorCodeIOException) {
      message = ErrorCodeTranslator.getErrorCodeMessage(((ErrorCodeIOException) throwable).ErrCode);
      if (message == null)
        message = Messages.getString("PersistenceService.error_io_message", String.valueOf(((ErrorCodeIOException) throwable).ErrCode)); //$NON-NLS-1$
    }
    else if (message == null || message.length() == 0)
      message = ERROR_MESSAGE;
    throw new DocumentException(message, throwable);
  }
  if (!filter.isExternalFilter())
    document.fireDocumentEvent(IDocument.EVENT_ON_SAVE_AS_DONE);
}
 
Example #14
Source File: PersistenceService.java    From noa-libre with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Exports document into the output stream on the basis of the submitted filter.
 * 
 * @param outputStream output stream to be used
 * @param filter filter to be used
 * 
 * @throws NOAException if the document can not be exported
 * 
 * @author Andreas Bröker
 * @date 25.08.2006
 */
public void export(OutputStream outputStream, IFilter filter) throws NOAException {
  if (outputStream == null)
    throw new NOAException(Messages.getString("PersistenceService_error_message_invalid_output_stream")); //$NON-NLS-1$

  if (filter == null || !filter.isSupported(document))
    throw new NOAException(Messages.getString("PersistenceService.error_filter_invalid_message")); //$NON-NLS-1$

  String filterDefinition = filter.getFilterDefinition(document);
  OutputStreamToXOutputStreamAdapter streamAdapter = new OutputStreamToXOutputStreamAdapter(outputStream);

  PropertyValue[] properties = filter instanceof PDFFilter ? new PropertyValue[3]
      : new PropertyValue[2];

  properties[0] = new PropertyValue();
  properties[0].Name = "FilterName"; //$NON-NLS-1$
  properties[0].Value = filterDefinition;
  properties[1] = new PropertyValue("OutputStream", -1, streamAdapter, PropertyState.DIRECT_VALUE); //$NON-NLS-1$
  if (filter instanceof PDFFilter) {
    properties[2] = new PropertyValue();
    properties[2].Name = "FilterData";
    properties[2].Value = ((PDFFilter) filter).getPDFFilterProperties().toPropertyValues();
  }

  if (!filter.isExternalFilter())
    document.fireDocumentEvent(IDocument.EVENT_ON_SAVE_AS);
  try {
    xStorable.storeToURL("private:stream", properties); //$NON-NLS-1$
  }
  catch (Throwable throwable) {
    String message = throwable.getMessage();
    if (throwable instanceof ErrorCodeIOException) {
      message = ErrorCodeTranslator.getErrorCodeMessage(((ErrorCodeIOException) throwable).ErrCode);
      if (message == null)
        message = Messages.getString("PersistenceService.error_io_message", String.valueOf(((ErrorCodeIOException) throwable).ErrCode)); //$NON-NLS-1$
    }
    else if (message == null || message.length() == 0)
      message = ERROR_MESSAGE;
    throw new NOAException(message, throwable);
  }
  if (!filter.isExternalFilter())
    document.fireDocumentEvent(IDocument.EVENT_ON_SAVE_AS_DONE);
}