| 1 | <!--
|
|---|
| 2 |
|
|---|
| 3 | /*******************************************************************************
|
|---|
| 4 | * Copyright (c) 2007-2009 Cambridge Semantics Incorporated.
|
|---|
| 5 | * All rights reserved. This program and the accompanying materials
|
|---|
| 6 | * are made available under the terms of the Eclipse Public License v1.0
|
|---|
| 7 | * which accompanies this distribution, and is available at
|
|---|
| 8 | * http://www.eclipse.org/legal/epl-v10.html
|
|---|
| 9 | *******************************************************************************/
|
|---|
| 10 |
|
|---|
| 11 | Author: Ben Szekely (<a href="mailto:ben@cambridgesemantics.com">ben@cambridgesemantics.com</a>)
|
|---|
| 12 |
|
|---|
| 13 | -->
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|---|
| 17 | <html>
|
|---|
| 18 | <head>
|
|---|
| 19 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|---|
| 20 | <title>Anzo.JS sample</title>
|
|---|
| 21 |
|
|---|
| 22 | <script type="text/javascript">
|
|---|
| 23 | var djConfig = {
|
|---|
| 24 | modulePaths: {'anzo': '/openanzo-js/anzo'}
|
|---|
| 25 | };
|
|---|
| 26 | </script>
|
|---|
| 27 | <script type="text/javascript" src="/openanzo-js/dojo/dojo.js"></script>
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | </head>
|
|---|
| 31 | <body>
|
|---|
| 32 |
|
|---|
| 33 | <div style='margin-bottom: 0px; padding: 0px;'>
|
|---|
| 34 | Status: <span id='statusElt'>Done</span>
|
|---|
| 35 | </div>
|
|---|
| 36 |
|
|---|
| 37 | <script type="text/javascript">
|
|---|
| 38 |
|
|---|
| 39 | function setStatus(msg, isLoading) {
|
|---|
| 40 | var x = document.getElementById("statusElt");
|
|---|
| 41 | x.innerHTML += "<br>" + msg;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | // specify what anzo libraries are needed
|
|---|
| 45 | dojo.require("anzo.client.AnzoClient");
|
|---|
| 46 | dojo.require("anzo.rdf.Statement");
|
|---|
| 47 |
|
|---|
| 48 | // UPDATE THE VALUES BELOW TO CONNECT TO YOUR SERVER
|
|---|
| 49 | var properties = {
|
|---|
| 50 | location : "/cometd/", // location of the comet service
|
|---|
| 51 | username : "sysadmin", // user name for authentication
|
|---|
| 52 | password : "123" // password for authentication
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | var anzoClient = new anzo.client.AnzoClient(properties);
|
|---|
| 56 |
|
|---|
| 57 | // connect to the server
|
|---|
| 58 | setStatus("Connecting to the server.");
|
|---|
| 59 | anzoClient.connect(function(status, message) {
|
|---|
| 60 |
|
|---|
| 61 | // check if the connect was successful
|
|---|
| 62 | if (status != anzo.messaging.CONNECTION_STATUS_CONNECTED) {
|
|---|
| 63 | setStatus("Failed to connect to the server: "+message);
|
|---|
| 64 | throw Error("Failed to connect to the server: "+message);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | setStatus("Connected to the server.");
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | // use the anzo node API to create some URIs and statements.
|
|---|
| 71 | var graphUri = anzo.createURI("http://example.org/graph1");
|
|---|
| 72 | var predUri = anzo.createURI("http://example.org/pred1");
|
|---|
| 73 | var stmt1 = anzo.createStatement(graphUri,predUri,"val1",graphUri);
|
|---|
| 74 | var stmt2 = anzo.createStatement(graphUri,predUri,"val2",graphUri);
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | // begin a transaction
|
|---|
| 78 | anzoClient.begin();
|
|---|
| 79 | // create a new graph. getReplicaGraph creates a new graph if it doesn't exist
|
|---|
| 80 | anzoClient.getReplicaGraph(graphUri, function(graph, error) {
|
|---|
| 81 | setStatus("Got replica graph: " + graphUri);
|
|---|
| 82 | // add couple statements to the graph
|
|---|
| 83 | graph.add(stmt1);
|
|---|
| 84 | graph.add(stmt2);
|
|---|
| 85 | // commit the transaction
|
|---|
| 86 | anzoClient.commit();
|
|---|
| 87 |
|
|---|
| 88 | // setup a callback for the updateRepository call.
|
|---|
| 89 | var handle = dojo.connect(anzoClient,"updateRepositoryComplete", function(success, errors) {
|
|---|
| 90 | dojo.disconnect(handle);
|
|---|
| 91 | setStatus("Repository udpate complete");
|
|---|
| 92 |
|
|---|
| 93 | // check that the statements are in the graph
|
|---|
| 94 | var stmts = graph.getStatements();
|
|---|
| 95 | for (var i=0;i<stmts.length;i++) {
|
|---|
| 96 | setStatus("Statement added: " + stmts[i]);
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | // close the graph and disconnect the client
|
|---|
| 100 | graph.close();
|
|---|
| 101 | anzoClient.close(function(status){
|
|---|
| 102 | setStatus("Disconnected from server");
|
|---|
| 103 | });
|
|---|
| 104 | });
|
|---|
| 105 | anzoClient.updateRepository();
|
|---|
| 106 |
|
|---|
| 107 | });
|
|---|
| 108 |
|
|---|
| 109 | });
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 | </script>
|
|---|
| 114 |
|
|---|
| 115 | </body>
|
|---|
| 116 | </html>
|
|---|