You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2015/01/26 15:07:22 UTC
svn commit: r1654807 - in /chemistry/opencmis/trunk:
chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/
chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/ap...
Author: fmui
Date: Mon Jan 26 14:07:21 2015
New Revision: 1654807
URL: http://svn.apache.org/r1654807
Log:
added file name to temp stream
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/TempStoreOutputStream.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/TempStoreOutputStream.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/TempStoreOutputStream.java?rev=1654807&r1=1654806&r2=1654807&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/TempStoreOutputStream.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/TempStoreOutputStream.java Mon Jan 26 14:07:21 2015
@@ -54,6 +54,18 @@ public abstract class TempStoreOutputStr
public abstract void setMimeType(String mimeType);
/**
+ * Sets the file name.
+ *
+ * This method is usually be called once before {@link #getInputStream()} is
+ * called. It might never be called if the file name is unknown.
+ *
+ * @param filename
+ * the file name or {@code null} if the file name is unknown or
+ * should be reset to unknown
+ */
+ public abstract void setFileName(String filename);
+
+ /**
* Returns an {@link InputStream} that serves the content that has been
* provided to this {@link TempStoreOutputStream} instance.
*
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java?rev=1654807&r1=1654806&r2=1654807&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java Mon Jan 26 14:07:21 2015
@@ -391,7 +391,7 @@ public final class AtomEntryParser {
tsos = readContentBytes(parser, mimeType);
} else {
mimeType = type;
- tsos = readBase64(parser, mimeType);
+ tsos = readBase64(parser, mimeType, null);
}
atomContentStream.setMimeType(mimeType);
@@ -431,7 +431,8 @@ public final class AtomEntryParser {
if (TAG_MEDIATYPE.equals(name.getLocalPart())) {
cmisContentStream.setMimeType(XMLUtils.readText(parser, XMLConstraints.MAX_STRING_LENGTH));
} else if (TAG_BASE64.equals(name.getLocalPart())) {
- TempStoreOutputStream tsos = readBase64(parser, cmisContentStream.getMimeType());
+ TempStoreOutputStream tsos = readBase64(parser, cmisContentStream.getMimeType(),
+ cmisContentStream.getFileName());
try {
cmisContentStream.setStream(tsos.getInputStream());
cmisContentStream.setLength(BigInteger.valueOf(tsos.getLength()));
@@ -512,10 +513,11 @@ public final class AtomEntryParser {
/**
* Parses a tag that contains base64 encoded content.
*/
- private TempStoreOutputStream readBase64(XMLStreamReader parser, String mimeType) throws XMLStreamException,
- IOException {
+ private TempStoreOutputStream readBase64(XMLStreamReader parser, String mimeType, String filename)
+ throws XMLStreamException, IOException {
TempStoreOutputStream bufferStream = streamFactory.newOutputStream();
bufferStream.setMimeType(mimeType);
+ bufferStream.setFileName(filename);
Base64.OutputStream b64stream = new Base64.OutputStream(bufferStream, Base64.DECODE);
XMLUtils.next(parser);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.java?rev=1654807&r1=1654806&r2=1654807&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/browser/MultipartParser.java Mon Jan 26 14:07:21 2015
@@ -413,9 +413,10 @@ public class MultipartParser {
}
}
- private void readBodyAsStream(String contentType) throws IOException {
+ private void readBodyAsStream(String contentType, String filename) throws IOException {
TempStoreOutputStream stream = streamFactory.newOutputStream();
stream.setMimeType(contentType);
+ stream.setFileName(filename);
try {
while (true) {
@@ -486,7 +487,7 @@ public class MultipartParser {
contentType = Constants.MEDIATYPE_OCTETSTREAM;
}
- readBodyAsStream(contentType);
+ readBodyAsStream(contentType, filename);
} else {
String name = params.get(MimeHelper.DISPOSITION_NAME);
byte[] rawValue = readBodyBytes();
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java?rev=1654807&r1=1654806&r2=1654807&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java Mon Jan 26 14:07:21 2015
@@ -75,6 +75,7 @@ public class ThresholdOutputStream exten
private Key key;
private byte[] iv;
private String mimeType;
+ private String filename;
/**
* Constructor.
@@ -210,6 +211,14 @@ public class ThresholdOutputStream exten
return mimeType;
}
+ public void setFileName(String filename) {
+ this.filename = filename;
+ }
+
+ public String getFileName() {
+ return filename;
+ }
+
public long getLength() {
return length;
}
@@ -418,6 +427,15 @@ public class ThresholdOutputStream exten
}
/**
+ * Returns the file name of the stream.
+ *
+ * @return the file name or {@code null} if the file name is unknown
+ */
+ public String getFileName() {
+ return filename;
+ }
+
+ /**
* Returns the length of the stream.
*
* @return the length of the stream in bytes
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java?rev=1654807&r1=1654806&r2=1654807&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/test/java/org/apache/chemistry/opencmis/server/impl/ThresholdOutputStreamTest.java Mon Jan 26 14:07:21 2015
@@ -38,6 +38,8 @@ public class ThresholdOutputStreamTest {
private static final String MIME_TYPE_1 = "some/type";
private static final String MIME_TYPE_2 = "another/type";
+ private static final String FILE_NAME_1 = "file1.txt";
+ private static final String FILE_NAME_2 = "the_other_file";
private static final byte[] CONTENT = "Hello".getBytes();
@Test
@@ -46,6 +48,7 @@ public class ThresholdOutputStreamTest {
TempStoreOutputStream tempStream = streamFactory.newOutputStream();
tempStream.setMimeType(MIME_TYPE_1);
+ tempStream.setFileName(FILE_NAME_1);
assertTrue(tempStream instanceof ThresholdOutputStream);
// set content
@@ -62,6 +65,7 @@ public class ThresholdOutputStreamTest {
assertEquals(CONTENT.length, tis.getLength());
assertArrayEquals(CONTENT, getBytesFromArray(tis.getBytes(), (int) tis.getLength()));
assertEquals(MIME_TYPE_1, tis.getMimeType());
+ assertEquals(FILE_NAME_1, tis.getFileName());
// read stream
byte[] buffer = new byte[CONTENT.length];
@@ -104,6 +108,7 @@ public class ThresholdOutputStreamTest {
TempStoreOutputStream tempStream = streamFactory.newOutputStream();
tempStream.setMimeType(MIME_TYPE_2);
+ tempStream.setFileName(FILE_NAME_2);
assertTrue(tempStream instanceof ThresholdOutputStream);
// set content
@@ -119,6 +124,7 @@ public class ThresholdOutputStreamTest {
assertNull(tis.getBytes());
assertEquals(CONTENT.length, tis.getLength());
assertEquals(MIME_TYPE_2, tis.getMimeType());
+ assertEquals(FILE_NAME_2, tis.getFileName());
assertTrue(tis.getTemporaryFile().exists());
assertEquals(CONTENT.length, tis.getTemporaryFile().length());