Created
April 23, 2018 13:33
-
-
Save anupammaiti/969fb89e99f9ca1b315d12ba7ba88cda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.jcr.*; | |
import java.io.FileInputStream; | |
import org.apache.jackrabbit.commons.JcrUtils; | |
/** | |
* ImportXml Jackrabbit example application. Imports an example XML file | |
* and outputs the contents of the entire workspace. | |
*/ | |
public class ImportXml { | |
/** | |
* The main entry point of the example application. | |
* | |
* @param args command line arguments (ignored) | |
* @throws Exception if an error occurs | |
*/ | |
public static void main(String[] args) throws Exception { | |
Repository repository = JcrUtils.getRepository(); | |
Session session = repository.login( | |
new SimpleCredentials("admin", "admin".toCharArray())); | |
try { | |
Node root = session.getRootNode(); | |
// Import the XML file unless already imported | |
if (!root.hasNode("importxml")) { | |
System.out.print("Importing xml... "); | |
// Create an unstructured node under which to import the XML | |
Node node = root.addNode("importxml", "nt:unstructured"); | |
// Import the file "test.xml" under the created node | |
FileInputStream xml = new FileInputStream("test.xml"); | |
session.importXML( | |
node.getPath(), xml, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); | |
xml.close(); | |
session.save(); | |
System.out.println("done."); | |
} | |
//output the repository content | |
dump(root); | |
} finally { | |
session.logout(); | |
} | |
} | |
/** Recursively outputs the contents of the given node. */ | |
private static void dump(Node node) throws RepositoryException { | |
// First output the node path | |
System.out.println(node.getPath()); | |
// Skip the virtual (and large!) jcr:system subtree | |
if (node.getName().equals("jcr:system")) { | |
return; | |
} | |
// Then output the properties | |
PropertyIterator properties = node.getProperties(); | |
while (properties.hasNext()) { | |
Property property = properties.nextProperty(); | |
if (property.getDefinition().isMultiple()) { | |
// A multi-valued property, print all values | |
Value[] values = property.getValues(); | |
for (int i = 0; i < values.length; i++) { | |
System.out.println( | |
property.getPath() + " = " + values[i] .getString()); | |
} | |
} else { | |
// A single-valued property | |
System.out.println( | |
property.getPath() + " = " + property.getString()); | |
} | |
} | |
// Finally output all the child nodes recursively | |
NodeIterator nodes = node.getNodes(); | |
while (nodes.hasNext()) { | |
dump(nodes.nextNode()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.jcr.Repository; | |
import javax.jcr.Session; | |
import javax.jcr.SimpleCredentials; | |
import javax.jcr.Node; | |
import org.apache.jackrabbit.commons.JcrUtils; | |
/** | |
* JCRCreateContent example. Stores, retrieves, and removes example content. | |
*/ | |
public class JCRCreateContent { | |
/** | |
* The main entry point of the example application. | |
* | |
* @param args command line arguments (ignored) | |
* @throws Exception if an error occurs | |
*/ | |
public static void main(String[] args) throws Exception { | |
Repository repository = JcrUtils.getRepository(); | |
Session session = repository.login( | |
new SimpleCredentials("admin", "admin".toCharArray())); | |
try { | |
Node root = session.getRootNode(); | |
// Store content | |
Node hello = root.addNode("hello"); | |
Node world = hello.addNode("world"); | |
world.setProperty("message", "Hello, World!"); | |
session.save(); | |
// Retrieve content | |
Node node = root.getNode("hello/world"); | |
System.out.println(node.getPath()); | |
System.out.println(node.getProperty("message").getString()); | |
// Remove content | |
root.getNode("hello").remove(); | |
session.save(); | |
} finally { | |
session.logout(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.jcr.GuestCredentials; | |
import javax.jcr.Repository; | |
import javax.jcr.Session; | |
import org.apache.jackrabbit.commons.JcrUtils; | |
/** | |
* JCRLogin example. Logs in to a content repository and prints a | |
* status message. | |
*/ | |
public class JCRLogin { | |
/** | |
* The main entry point of the example application. | |
* | |
* @param args command line arguments (ignored) | |
* @throws Exception if an error occurs | |
*/ | |
public static void main(String[] args) throws Exception { | |
Repository repository = JcrUtils.getRepository(); | |
Session session = repository.login(new GuestCredentials()); | |
try { | |
String user = session.getUserID(); | |
String name = repository.getDescriptor(Repository.REP_NAME_DESC); | |
System.out.println( | |
"Logged in as " + user + " to a " + name + " repository."); | |
} finally { | |
session.logout(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" | |
xmlns:mathml="http://www.w3.org/1998/Math/MathML"> | |
<xhtml:head><xhtml:title>Three Namespaces</xhtml:title></xhtml:head> | |
<xhtml:body> | |
<xhtml:h1 align="center">An Ellipse and a Rectangle</xhtml:h1> | |
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" | |
width="12cm" height="10cm"> | |
<svg:ellipse rx="110" ry="130" /> | |
<svg:rect x="4cm" y="1cm" width="3cm" height="6cm" /> | |
</svg:svg> | |
<xhtml:p>The equation for ellipses</xhtml:p> | |
<mathml:math> | |
<mathml:apply> | |
<mathml:eq/> | |
<mathml:cn> 1 </mathml:cn> | |
<mathml:apply> | |
<mathml:plus/> | |
<mathml:apply> | |
<mathml:divide/> | |
<mathml:apply> | |
<mathml:power/> | |
<mathml:ci> x </mathml:ci> | |
<mathml:cn> 2 </mathml:cn> | |
</mathml:apply> | |
<mathml:apply> | |
<mathml:power/> | |
<mathml:ci> a </mathml:ci> | |
<mathml:cn> 2 </mathml:cn> | |
</mathml:apply> | |
</mathml:apply> | |
<mathml:apply> | |
<mathml:divide/> | |
<mathml:apply> | |
<mathml:power/> | |
<mathml:ci> y </mathml:ci> | |
<mathml:cn> 2 </mathml:cn> | |
</mathml:apply> | |
<mathml:apply> | |
<mathml:power/> | |
<mathml:ci> b </mathml:ci> | |
<mathml:cn> 2 </mathml:cn> | |
</mathml:apply> | |
</mathml:apply> | |
</mathml:apply> | |
</mathml:apply> | |
</mathml:math> | |
<xhtml:hr/> | |
<xhtml:p>Last Modified January 10, 2002</xhtml:p> | |
</xhtml:body> | |
</xhtml:html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment