+ public static String getMediaFileref(Node node) {
+ try {
+ Node mediadata;
+ if (node.hasNode(DbkType.imageobject.get())) {
+ mediadata = node.getNode(DbkType.imageobject.get()).getNode(DbkType.imagedata.get());
+ } else if (node.hasNode(DbkType.videoobject.get())) {
+ mediadata = node.getNode(DbkType.videoobject.get()).getNode(DbkType.videodata.get());
+ } else {
+ throw new IllegalArgumentException("Fileref not found in " + node);
+ }
+
+ if (mediadata.hasProperty(DbkAttr.fileref.name())) {
+ return mediadata.getProperty(DbkAttr.fileref.name()).getString();
+ } else {
+ return null;
+ }
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot retrieve file ref from " + node, e);
+ }
+ }
+
+ public static void exportXml(Node node, OutputStream out) throws IOException {
+ try {
+ node.getSession().exportDocumentView(node.getPath(), out, false, false);
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot export " + node + " to XML", e);
+ }
+ }
+
+ public static void exportToFs(Node baseNode, DbkType type, Path directory) {
+ String fileName = Jcr.getName(baseNode) + ".dbk.xml";
+ Path filePath = directory.resolve(fileName);
+ Node docBookNode = Jcr.getNode(baseNode, type.get());
+ if (docBookNode == null)
+ throw new IllegalArgumentException("No " + type.get() + " under " + baseNode);
+ try {
+ Files.createDirectories(directory);
+ try (OutputStream out = Files.newOutputStream(filePath)) {
+ exportXml(docBookNode, out);
+ }
+ JcrUtils.copyFilesToFs(baseNode, directory, true);
+ if (log.isDebugEnabled())
+ log.debug("DocBook " + baseNode + " exported to " + filePath.toAbsolutePath());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static void importXml(Node baseNode, InputStream in) throws IOException {
+ try {
+ baseNode.getSession().importXML(baseNode.getPath(), in,
+ ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot import XML to " + baseNode, e);
+ }
+
+ }
+