1 5 6 package org.exoplatform.services.jcr.impl.util; 7 8 import javax.jcr.RepositoryException; 9 10 11 import java.util.Properties ; 12 import java.util.List ; 13 14 15 import javax.jcr.PropertyType; 16 17 import org.apache.commons.codec.binary.Base64; 18 import org.exoplatform.services.jcr.impl.Constants; 19 import org.exoplatform.services.jcr.impl.core.NodeImpl; 20 import org.exoplatform.services.jcr.impl.core.PropertyImpl; 21 import org.exoplatform.services.jcr.impl.core.WorkspaceImpl; 22 import org.exoplatform.services.jcr.storage.Container; 23 24 import javax.jcr.PropertyIterator; 25 26 32 33 public class DocNodeExporter { 34 35 36 public static void export(Container container, NodeImpl node, XMLWriter writer, 37 boolean binaryAsLink, boolean noRecurse) throws RepositoryException { 38 39 String name = node.getName(); 40 41 if (name.length() == 0) name = "root"; 43 44 Properties attrs = new Properties (); 46 50 PropertyIterator props = node.getProperties(); 51 while (props.hasNext()) { 52 PropertyImpl prop = (PropertyImpl) props.next(); 53 String strPropVal = getStrPropValue(prop, binaryAsLink); 54 attrs.setProperty(prop.getName(), strPropVal); 56 } 57 writer.startElement(name, attrs); 58 59 List nodes = container.getChildren(node.getPath()); 60 for (int i = 0; i < nodes.size(); i++) { 61 NodeImpl child = (NodeImpl) nodes.get(i); 62 if (!noRecurse) 64 export(container, child, writer, binaryAsLink, noRecurse); 65 } 66 67 writer.endElement(); 68 69 } 70 106 public static String getStrPropValue(PropertyImpl prop, boolean binaryAsLink) { 107 108 if (prop.getType() == PropertyType.BINARY) { 109 if (binaryAsLink) 110 return prop.getPath(); 111 else { 112 String str = new String (Base64.encodeBase64(prop.toString().getBytes())); 113 return str; 114 } 115 116 } else 117 return StringConverter.normalizeString(prop.toString(), false); 118 } 119 120 } 121 | Popular Tags |