[Bedework-commit] bwcalfacade r48 - in
trunk/src/org/bedework/calfacade: . svc
svnadmin at bedework.org
svnadmin at bedework.org
Sat Apr 21 23:00:03 EDT 2012
Author: douglm
Date: 2012-04-21 23:00:01 -0400 (Sat, 21 Apr 2012)
New Revision: 48
Modified:
trunk/src/org/bedework/calfacade/BwResource.java
trunk/src/org/bedework/calfacade/BwResourceContent.java
trunk/src/org/bedework/calfacade/svc/BwView.java
Log:
Dump and restore resources - dumped as Base64 encoded values in the file.
Modified: trunk/src/org/bedework/calfacade/BwResource.java
===================================================================
--- trunk/src/org/bedework/calfacade/BwResource.java 2012-03-27 20:26:15 UTC (rev 47)
+++ trunk/src/org/bedework/calfacade/BwResource.java 2012-04-22 03:00:01 UTC (rev 48)
@@ -6,9 +6,9 @@
Version 2.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a
copy of the License at:
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,6 +18,8 @@
*/
package org.bedework.calfacade;
+import org.bedework.calfacade.annotations.Dump;
+import org.bedework.calfacade.annotations.NoDump;
import org.bedework.calfacade.base.BwShareableContainedDbentity;
import edu.rpi.sss.util.DateTimeUtil;
@@ -34,6 +36,7 @@
*
* @author Mike Douglass douglm - rpi.edu
*/
+ at Dump(elementName="resource", keyFields={"name"})
public class BwResource extends BwShareableContainedDbentity<BwResource> {
private String name;
@@ -213,6 +216,7 @@
*
* @param val lastmod
*/
+ @NoDump
public void setPrevLastmod(final String val) {
prevLastmod = val;
}
@@ -237,6 +241,7 @@
*
* @return the event's seq
*/
+ @NoDump
public int getPrevSeq() {
return prevSeq;
}
@@ -253,6 +258,7 @@
*
* @return BwResourceContent content
*/
+ @Dump(compound = true)
public BwResourceContent getContent() {
return content;
}
Modified: trunk/src/org/bedework/calfacade/BwResourceContent.java
===================================================================
--- trunk/src/org/bedework/calfacade/BwResourceContent.java 2012-03-27 20:26:15 UTC (rev 47)
+++ trunk/src/org/bedework/calfacade/BwResourceContent.java 2012-04-22 03:00:01 UTC (rev 48)
@@ -18,12 +18,18 @@
*/
package org.bedework.calfacade;
+import org.bedework.calfacade.annotations.Dump;
+import org.bedework.calfacade.annotations.NoDump;
import org.bedework.calfacade.base.BwDbentity;
import org.bedework.calfacade.exc.CalFacadeException;
import org.bedework.calfacade.util.CalFacadeUtil;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Base64OutputStream;
import org.hibernate.Hibernate;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
import java.sql.Blob;
/** Represent the content for a resource stored within the system, e.g an attachment or an
@@ -32,6 +38,7 @@
*
* @author Mike Douglass douglm - rpi.edu
*/
+ at Dump(elementName="resourceContent", keyFields={"colPath", "name", "encodedContent"})
public class BwResourceContent extends BwDbentity<BwResourceContent> {
/* The collection this belongs to
*/
@@ -95,6 +102,7 @@
*
* @return Blob
*/
+ @NoDump
public Blob getValue() {
return value;
}
@@ -107,6 +115,7 @@
* @param val
* @throws CalFacadeException
*/
+ @NoDump
public void setContent(final byte[] val) throws CalFacadeException {
try {
setValue(Hibernate.createBlob(val));
@@ -115,6 +124,43 @@
}
}
+ /** Used during dump and restore
+ * @param val base64 encoded value
+ * @throws CalFacadeException
+ */
+ public void setEncodedContent(final String val) throws CalFacadeException {
+ try {
+ setContent(Base64.decodeBase64(val.getBytes()));
+ } catch (Throwable t) {
+ throw new CalFacadeException(t);
+ }
+ }
+
+ /**
+ * @return base64 encoded value
+ * @throws CalFacadeException
+ */
+ public String getEncodedContent() throws CalFacadeException {
+ try {
+ int len = -1;
+ int chunkSize = 1024;
+
+ byte buffer[] = new byte[chunkSize];
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Base64OutputStream b64out = new Base64OutputStream(baos);
+ InputStream str = getValue().getBinaryStream();
+
+ while((len = str.read(buffer)) != -1) {
+ b64out.write(buffer, 0, len);
+ }
+
+ return new String(baos.toByteArray());
+ } catch (Throwable t) {
+ throw new CalFacadeException(t);
+ }
+ }
+
/** Copy this objects values into the parameter
*
* @param val
Modified: trunk/src/org/bedework/calfacade/svc/BwView.java
===================================================================
--- trunk/src/org/bedework/calfacade/svc/BwView.java 2012-03-27 20:26:15 UTC (rev 47)
+++ trunk/src/org/bedework/calfacade/svc/BwView.java 2012-04-22 03:00:01 UTC (rev 48)
@@ -123,7 +123,6 @@
*
* @param val
*/
- @NoDump
public void setConjunction(final boolean val) {
conjunction = val;
}
@@ -131,6 +130,7 @@
/**
* @return true if we AND the expressions for each path
*/
+ @NoDump
public boolean getConjunction() {
return conjunction;
}
More information about the Bedework-commit
mailing list