You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by Apache Wiki <wi...@apache.org> on 2005/09/09 19:01:49 UTC
[Jakarta-slide Wiki] Update of "Sample API application" by James Kelly
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Jakarta-slide Wiki" for change notification.
The following page has been changed by James Kelly:
http://wiki.apache.org/jakarta-slide/Sample_API_application
The comment on the change is:
Added properties example
------------------------------------------------------------------------------
- Sample application sent by Stefan Fromm which was found in mailing-list archives (jakarta-slide-user, Mon, 06 Sep 2004 12:29:35 GMT)
+ = Creating File Revisions =
- It shows how to create revisions for file.
+ Sample application sent by Stefan Fromm which was found in mailing-list archives (jakarta-slide-user, Mon, 06 Sep 2004 12:29:35 GMT) It shows how to create revisions for file.
+
{{{
import java.io.ByteArrayInputStream;
import java.util.Date;
@@ -157, +158 @@
}
}}}
+ = Getting Properties =
+
+ This example demonstrates how to access file contents and properties from the SlideAPI.
+
+ {{{
+ import java.util.Enumeration;
+
+ import javax.transaction.NotSupportedException;
+ import javax.transaction.SystemException;
+
+ import org.apache.slide.authenticate.CredentialsToken;
+ import org.apache.slide.authenticate.SecurityToken;
+ import org.apache.slide.common.Domain;
+ import org.apache.slide.common.NamespaceAccessToken;
+ import org.apache.slide.common.SlideToken;
+ import org.apache.slide.common.SlideTokenImpl;
+ import org.apache.slide.content.Content;
+ import org.apache.slide.content.NodeProperty;
+ import org.apache.slide.content.NodeRevisionContent;
+ import org.apache.slide.content.NodeRevisionDescriptor;
+ import org.apache.slide.content.NodeRevisionDescriptors;
+
+ /**
+ * An example the Slide API that demonstrates fetching the properties
+ * enumeration from a NodeRevisionDescriptor. This example assumes the existance
+ * of "/files/test.txt" in the store (this file can be generated by the
+ * SlideVersionsTest in the example above.)
+ *
+ * @author James Kelly
+ */
+ public class SlideTest2 {
+
+ /**
+ * Prints the contents and properties for "/files/test.txt"
+ *
+ * @param args
+ */
+ public static void main(String[] args) {
+ SlideTest2 client = new SlideTest2();
+ try {
+ client.printContent("/files/test.txt");
+ client.printProperties("/files/test.txt");
+ } catch (NotSupportedException e) {
+
+ e.printStackTrace();
+ } catch (SystemException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /** Default Namespace */
+ private NamespaceAccessToken namespace;
+
+ /** Security Token */
+ private SlideToken token;
+
+ /**
+ * Loads the default namespace and creates a new security token for "root"
+ */
+ public SlideTest2() {
+ this.namespace = Domain.accessNamespace(new SecurityToken(""), Domain
+ .getDefaultNamespace());
+ this.token = new SlideTokenImpl(new CredentialsToken("root"));
+ this.token.setForceStoreEnlistment(true);
+ }
+
+ /**
+ * Fetches a file from the store and prints its content to STOUT.
+ *
+ * @param path
+ * the path to the file
+ * @throws NotSupportedException
+ * @throws SystemException
+ */
+ public void printContent(String path) throws NotSupportedException,
+ SystemException {
+ this.namespace.begin();
+ try {
+ Content c = this.namespace.getContentHelper();
+ NodeRevisionDescriptors revs = c.retrieve(this.token, path);
+ NodeRevisionDescriptor rev = c.retrieve(this.token, revs, revs
+ .getLatestRevision());
+ NodeRevisionContent nrc = c.retrieve(this.token, path, rev);
+ System.out.print(nrc.getContent());
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ this.namespace.rollback();
+ }
+ }
+
+ /**
+ * Fetches and prints the properties enumeration to STDOUT.
+ *
+ * @param path
+ * the file URI
+ * @throws IllegalStateException
+ * @throws SecurityException
+ * @throws SystemException
+ * @throws NotSupportedException
+ */
+ @SuppressWarnings("unchecked")
+ public void printProperties(String path) throws IllegalStateException,
+ SecurityException, SystemException, NotSupportedException {
+ this.namespace.begin();
+ try {
+ Content c = this.namespace.getContentHelper();
+ NodeRevisionDescriptors revs = c.retrieve(this.token, path);
+ NodeRevisionDescriptor rev = c.retrieve(this.token, revs, revs
+ .getLatestRevision());
+ Enumeration e = rev.enumerateProperties();
+ while (e.hasMoreElements()) {
+ NodeProperty p = (NodeProperty) e.nextElement();
+ System.out.println(String.format("%s = %s", p.getName(), p
+ .getValue()));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ this.namespace.rollback();
+ }
+ }
+ }
+ }}}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org