1 19 package org.netbeans.modules.mdr; 20 21 import java.util.Enumeration ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import java.io.File ; 25 import org.openide.ErrorManager; 26 import org.openide.filesystems.FileObject; 27 import org.openide.loaders.DataNode; 28 import org.openide.loaders.DataObjectExistsException; 29 import org.openide.loaders.MultiDataObject; 30 import org.openide.loaders.MultiFileLoader; 31 import org.openide.nodes.Node; 32 33 38 public class MDRDataObject extends MultiDataObject { 39 private final String name; 40 private final MDRDescriptor descriptor; 41 42 public MDRDataObject(FileObject primaryFile, MultiFileLoader fl) throws DataObjectExistsException { 43 super(primaryFile, fl); 44 45 String fileName = primaryFile.getName(); 46 int pos = fileName.indexOf('['); 47 int pos2 = fileName.indexOf(']'); 48 49 this.name = fileName.substring(0, pos); 50 String className = fileName.substring(pos + 1, pos2).replace('-', '.'); 51 Map attributes = new HashMap (); 52 53 String attrName; 54 55 for (Enumeration en = primaryFile.getAttributes(); en.hasMoreElements();) { 56 attrName = (String ) en.nextElement(); 57 attributes.put(attrName, resolveTags(primaryFile.getAttribute(attrName))); 58 } 59 60 this.descriptor = new MDRDescriptor(className, attributes); 61 } 62 63 public MDRDescriptor getDescriptor() { 64 return descriptor; 65 } 66 67 public String getName() { 68 return name; 69 } 70 71 public boolean isCopyAllowed() { 72 return false; 73 } 74 75 public boolean isDeleteAllowed() { 76 return false; 77 } 78 79 public boolean isMoveAllowed() { 80 return false; 81 } 82 83 public boolean isRenameAllowed() { 84 return false; 85 } 86 87 public boolean isShadowAllowed() { 88 return false; 89 } 90 91 public Node createNodeDelegate() { 92 DataNode dataNode = (DataNode) super.createNodeDelegate(); 93 dataNode.setIconBase("/org/netbeans/modules/mdr/resources/repository"); 94 return dataNode; 95 } 96 97 private static final String TAG_START = "{"; 98 private static final String TAG_END = "}"; 99 private static final String TAG_BODY_FOLDER = "folder."; 100 101 private Object resolveTags(Object attrValue) { 102 if (attrValue instanceof String ) { 103 String value = (String ) attrValue; 104 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "tag: " + value); 105 StringBuffer result = new StringBuffer (value.length()); 106 int pos; 107 int ppos = 0; 108 109 while ((pos = value.indexOf(TAG_START, ppos)) > -1) { 110 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "tag found at pos: " + pos); 111 result.append(value.substring(ppos, pos)); 112 ErrorManager.getDefault().log("temp. result: " + result); 113 ppos = value.indexOf(TAG_END, pos); 114 ErrorManager.getDefault().log("tag end found at: " + ppos); 115 if (ppos == -1) { 116 ppos = pos; 117 break; 118 } 119 result.append(getTagValue(value.substring(pos + 1, ppos))); 120 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "added tag value, temp. result: " + result); 121 ppos++; 122 } 123 124 result.append(value.substring(ppos)); 125 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "finished, result: " + result); 126 return result.toString(); 127 } else { 128 return attrValue; 129 } 130 } 131 132 private String getTagValue(String tagName) { 133 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "replacing tag: " + tagName); 134 if (tagName.startsWith(TAG_BODY_FOLDER)) { 135 String folder = tagName.substring(TAG_BODY_FOLDER.length()).replace('\\', '/'); 136 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "found folder: " + folder); 137 String resultFolder = System.getProperty("netbeans.user") + "/var/cache/" + folder; 138 try { 139 File result = new File (resultFolder); 140 result.mkdirs(); 141 return resultFolder; 142 } catch (Exception e) { 143 ErrorManager.getDefault().notify(e); 144 return ""; 145 } 146 } else { 147 return TAG_START + tagName + TAG_END; 148 } 149 } 150 } 151 | Popular Tags |