User: kz Date: 2008-03-05 17:28:10+0000 Modified: dba/reportdesign/java/com/sun/star/report/StorageRepository.java
Log: INTEGRATION: CWS rptchart01_DEV300 (1.3.62); FILE MERGED 2008/02/21 09:57:23 oj 1.3.62.3: #i85225# fixes found with PMD 2008/02/20 10:52:55 oj 1.3.62.2: format changes 2008/02/13 07:04:21 oj 1.3.62.1: #i85225# impl chart readhandler and oleproducer File Changes: Directory: /dba/reportdesign/java/com/sun/star/report/ ====================================================== File [changed]: StorageRepository.java Url: http://dba.openoffice.org/source/browse/dba/reportdesign/java/com/sun/star/report/StorageRepository.java?r1=1.3&r2=1.4 Delta lines: +224 -50 ---------------------- --- StorageRepository.java 2007-08-03 09:48:16+0000 1.3 +++ StorageRepository.java 2008-03-05 17:28:08+0000 1.4 @@ -32,18 +32,18 @@ * MA 02111-1307 USA * ************************************************************************/ - package com.sun.star.report; import com.sun.star.beans.XPropertySet; import com.sun.star.container.NoSuchElementException; import com.sun.star.embed.ElementModes; import com.sun.star.embed.InvalidStorageException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import com.sun.star.embed.StorageWrappedTargetException; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.WrappedTargetException; import java.io.*; import com.sun.star.embed.XStorage; +import com.sun.star.embed.XTransactedObject; import com.sun.star.uno.UnoRuntime; import com.sun.star.io.XStream; import com.sun.star.lib.uno.adapter.XInputStreamToInputStreamAdapter; @@ -55,7 +55,9 @@ * * @author Ocke Janssen */ -public class StorageRepository implements InputRepository, OutputRepository { +public class StorageRepository implements InputRepository, OutputRepository +{ + private XStorage input; private XStorage output; @@ -65,18 +67,37 @@ * @param output * @throws java.io.IOException */ - public StorageRepository(final XStorage input,final XStorage output) throws IOException { + public StorageRepository(final XStorage input, final XStorage output) + { this.input = input; this.output = output; - if ( output == null || input == null ) - throw new IOException("Need a valid storage not NULL."); } - public InputStream createInputStream(String name) throws IOException { - try{ - final XStream xStream = (XStream) UnoRuntime.queryInterface(XStream.class,input.openStreamElement(name,ElementModes.READ)); - return new BufferedInputStream(new XInputStreamToInputStreamAdapter(xStream.getInputStream()),102400); - }catch(com.sun.star.uno.Exception e){ + public StorageRepository(final XStorage storage, final boolean isOutput) + { + if (isOutput) + { + this.output = storage; + } + else + { + this.input = storage; + } + } + + public InputStream createInputStream(String name) throws IOException + { + if (input == null) + { + throw new IOException("input is NULL"); + } + try + { + final XStream xStream = (XStream) UnoRuntime.queryInterface(XStream.class, input.openStreamElement(name, ElementModes.READ)); + return new BufferedInputStream(new XInputStreamToInputStreamAdapter(xStream.getInputStream()), 102400); + } + catch (com.sun.star.uno.Exception e) + { throw new IOException("createInputStream"); } } @@ -90,58 +111,211 @@ * @return the outputstream * @throws IOException if opening the stream fails */ - public OutputStream createOutputStream(String name, String mimeType) throws IOException { - try{ - final XStream stream = (XStream) UnoRuntime.queryInterface(XStream.class,output.openStreamElement(name,ElementModes.WRITE|ElementModes.TRUNCATE)); + public OutputStream createOutputStream(String name, String mimeType) throws IOException + { + if (output == null) + { + throw new IOException("output is NULL"); + } + try + { + final XStream stream = (XStream) UnoRuntime.queryInterface(XStream.class, output.openStreamElement(name, ElementModes.WRITE | ElementModes.TRUNCATE)); stream.getInputStream().closeInput(); if (mimeType != null) { - final XPropertySet prop = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,stream); - prop.setPropertyValue("MediaType",mimeType); + final XPropertySet prop = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, stream); + prop.setPropertyValue("MediaType", mimeType); } - return new BufferedOutputStream(new XOutputStreamToOutputStreamAdapter(stream.getOutputStream()),204800); - }catch(com.sun.star.uno.Exception e){ + return new BufferedOutputStream(new XOutputStreamToOutputStreamAdapter(stream.getOutputStream()), 204800); + } + catch (com.sun.star.uno.Exception e) + { throw new IOException("createOutputStream"); } } - public boolean exists(String name) { - try { - return output.isStreamElement(name); - } catch (InvalidStorageException ex) { + public boolean exists(String name) + { + boolean ret = false; + try + { + ret = output.isStreamElement(name); + } + catch (InvalidStorageException ex) + { ex.printStackTrace(); - } catch (com.sun.star.lang.IllegalArgumentException ex) { + } + catch (com.sun.star.lang.IllegalArgumentException ex) + { ex.printStackTrace(); - } catch (NoSuchElementException ex) { + } + catch (NoSuchElementException ex) + { // We expect this exception, no need to log it. } - return false; + return ret; } - public boolean isWritable(String name) { + public boolean isWritable(String name) + { return true; } - public Object getId() { + public Object getId() + { return "1"; } - public long getVersion(String name) { + public long getVersion(String name) + { return 1; } public boolean isReadable(String name) { - try { - if ( input != null ) + try + { + if (input != null) + { return input.isStreamElement(name); - } catch (InvalidStorageException ex) { + } + } + catch (InvalidStorageException ex) + { + ex.printStackTrace(); + } + catch (com.sun.star.lang.IllegalArgumentException ex) + { + ex.printStackTrace(); + } + catch (NoSuchElementException ex) + { + ex.printStackTrace(); + } + return false; + } + + public InputRepository openInputRepository(String name) throws IOException + { + try + { + String temp = name; + if (name.startsWith("./")) + { + temp = name.substring(2); + } + if (!input.isStorageElement(temp)) + { + throw new IOException(); + } + final XStorage storage = (XStorage) UnoRuntime.queryInterface(XStorage.class, input.openStorageElement(temp, ElementModes.READ)); + return new StorageRepository(storage, false); + } + catch (NoSuchElementException ex) + { + ex.printStackTrace(); + } + catch (WrappedTargetException ex) + { ex.printStackTrace(); - } catch (com.sun.star.lang.IllegalArgumentException ex) { + } + catch (InvalidStorageException ex) + { + ex.printStackTrace(); + } + catch (IllegalArgumentException ex) + { ex.printStackTrace(); - } catch (NoSuchElementException ex) { + } + catch (com.sun.star.io.IOException ex) + { ex.printStackTrace(); } + throw new IOException(); + } + + public OutputRepository openOutputRepository(String name) throws IOException + { + try + { + String temp = name; + if (name.startsWith("./")) + { + temp = name.substring(2); + } + final XStorage storage = (XStorage) UnoRuntime.queryInterface(XStorage.class, output.openStorageElement(temp, ElementModes.WRITE)); + return new StorageRepository(storage, true); + } + catch (IllegalArgumentException ex) + { + ex.printStackTrace(); + } + catch (InvalidStorageException ex) + { + ex.printStackTrace(); + } + catch (com.sun.star.io.IOException ex) + { + ex.printStackTrace(); + } + catch (StorageWrappedTargetException ex) + { + ex.printStackTrace(); + } + throw new IOException(); + } + + public void closeInputRepository() + { + if (input != null) + { + input.dispose(); + } + } + + public void closeOutputRepository() + { + if (output != null) + { + try + { + final XTransactedObject obj = (XTransactedObject) UnoRuntime.queryInterface(XTransactedObject.class, output); + if (obj != null) + { + obj.commit(); + } + } + catch (com.sun.star.io.IOException ex) + { + ex.printStackTrace(); + } + catch (WrappedTargetException ex) + { + ex.printStackTrace(); + } + output.dispose(); + } + + } + + public boolean existsStorage(String name) + { + try + { + return output.isStorageElement(name); + } + catch (InvalidStorageException ex) + { + ex.printStackTrace(); + } + catch (com.sun.star.lang.IllegalArgumentException ex) + { + ex.printStackTrace(); + } + catch (NoSuchElementException ex) + { + // We expect this exception, no need to log it. + } return false; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
