Author: sohil.shah(a)jboss.com
Date: 2009-01-28 20:25:15 -0500 (Wed, 28 Jan 2009)
New Revision: 12695
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/ContentImpl.java
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/commands/TestFileCreate.java
Log:
Oracle workaround for usecase where content is empty during file creation
Modified:
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/ContentImpl.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/ContentImpl.java 2009-01-29
00:30:45 UTC (rev 12694)
+++
modules/cms/trunk/cms-jackrabbit/src/main/java/org/jboss/portal/cms/impl/ContentImpl.java 2009-01-29
01:25:15 UTC (rev 12695)
@@ -108,13 +108,21 @@
/** @return Returns the content. */
public InputStream getStream()
{
- return new ByteArrayInputStream(bytes);
+ return new ByteArrayInputStream(this.getBytes());
}
/** @return Returns the content. */
public byte[] getBytes()
{
- return bytes;
+ //Code Around for issues with Oracle JDBC Driver. An empty byte array translates into
a NULL Blob which blows up since
+ //The column is NON-NULLABLE. All other tested database drivers mysql5, postgresql8,
hsqldb etc are just fine since they translate into an
+ //empty BLOB object
+ if(this.bytes == null || this.bytes.length==0)
+ {
+ this.bytes = " ".getBytes();
+ }
+
+ return this.bytes;
}
public String getContentAsString()
@@ -123,19 +131,19 @@
{
try
{
- return new String(bytes, encoding);
+ return new String(this.getBytes(), encoding);
}
catch (UnsupportedEncodingException e)
{
}
}
- return new String(bytes);
+ return new String(this.getBytes());
}
/** @param stream The content to set. */
public void setStream(InputStream stream)
{
- bytes = FileUtil.getBytes(stream);
+ this.bytes = FileUtil.getBytes(stream);
}
/** @param bytes The content to set. */
Modified:
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/commands/TestFileCreate.java
===================================================================
---
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/commands/TestFileCreate.java 2009-01-29
00:30:45 UTC (rev 12694)
+++
modules/cms/trunk/cms-jackrabbit/src/test/java/org/jboss/portal/cms/test/commands/TestFileCreate.java 2009-01-29
01:25:15 UTC (rev 12695)
@@ -187,6 +187,36 @@
assertEquals("Content Incorrect", new
String(cour.getContent().getBytes()), "1234567890");
}
+ @Test
+ public void testEmptyFileCreate() throws Exception
+ {
+ String path = "/emptyfile.gif";
+
+ //create file english
+ File file = new FileImpl();
+ file.setBasePath(path);
+
+ Content content = new ContentImpl();
+ content.setEncoding("UTF-8");
+ content.setTitle("English Title");
+ content.setDescription("English Description");
+ content.setBasePath(path + "/" + Locale.ENGLISH.getLanguage());
+ content.setBytes("".getBytes());
+ content.setMimeType("image/gif");
+ file.setContent(Locale.ENGLISH, content);
+
+ Command createFileCMD = service.getCommandFactory().createNewFileCommand(file,
content);
+ service.execute(createFileCMD);
+
+ //Assert the state of the newly created file
+ Command readFileCmd = service.getCommandFactory().createFileGetCommand(path,
Locale.ENGLISH);
+ File storedFile = (File)service.execute(readFileCmd);
+
+ assertNotNull("File not successfully stored!!", storedFile);
+ assertEquals("Encoding does not match!!",
file.getContent().getEncoding(), "UTF-8");
+ assertEquals("Bytes Check",
file.getContent().getContentAsString().trim(), "");
+ }
+
/**
*
* @param path
@@ -208,5 +238,5 @@
Command createFileCMD = service.getCommandFactory().createNewFileCommand(file,
content);
service.execute(createFileCMD);
- }
+ }
}