1 19 20 package org.netbeans.modules.properties; 21 22 import java.io.IOException ; 23 import java.io.ObjectInput ; 24 import java.io.ObjectOutput ; 25 import org.openide.filesystems.FileObject; 26 import org.openide.loaders.ExtensionList; 27 import org.openide.loaders.MultiDataObject; 28 import org.openide.loaders.MultiFileLoader; 29 import org.openide.util.NbBundle; 30 import org.openide.util.io.SafeException; 31 32 40 public final class PropertiesDataLoader extends MultiFileLoader { 41 42 43 static final String PROPERTIES_EXTENSION = "properties"; 45 46 public static final char PRB_SEPARATOR_CHAR = '_'; 47 48 49 static final long serialVersionUID =4384899552891479449L; 50 51 52 public static final String PROP_EXTENSIONS = "extensions"; 54 55 public PropertiesDataLoader() { 56 super("org.netbeans.modules.properties.PropertiesDataObject"); 58 ExtensionList extList = new ExtensionList(); 64 extList.addExtension(PROPERTIES_EXTENSION); 65 extList.addExtension("impl"); setExtensions(extList); 68 } 69 70 71 72 protected String defaultDisplayName() { 73 return NbBundle.getMessage(PropertiesDataLoader.class, 74 "PROP_PropertiesLoader_Name"); } 76 77 83 protected String actionsContext () { 84 return "Loaders/text/x-properties/Actions/"; } 86 87 91 protected MultiDataObject createMultiObject(final FileObject fo) 92 throws IOException { 93 return new PropertiesDataObject(fo, this); 94 } 95 96 97 protected FileObject findPrimaryFile (FileObject fo) { 98 if (fo.isFolder()) { 99 return null; 100 } 101 if (fo.getExt().equalsIgnoreCase(PROPERTIES_EXTENSION)) { 102 103 107 String fName = fo.getName(); 108 int index = fName.indexOf(PRB_SEPARATOR_CHAR); 109 while (index != -1) { 110 FileObject candidate = fo.getParent().getFileObject( 111 fName.substring(0, index), fo.getExt()); 112 if (candidate != null) { 113 return candidate; 114 } 115 index = fName.indexOf(PRB_SEPARATOR_CHAR, index + 1); 116 } 117 return fo; 118 } else { 119 return getExtensions().isRegistered(fo) ? fo : null; 120 } 121 } 122 123 126 protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, 127 FileObject primaryFile) { 128 return new PropertiesFileEntry(obj, primaryFile); 129 } 130 131 134 protected MultiDataObject.Entry createSecondaryEntry( 135 MultiDataObject obj, 136 FileObject secondaryFile) { 137 return new PropertiesFileEntry(obj, secondaryFile); 138 } 139 140 141 148 public void setExtensions(ExtensionList ext) { 149 putProperty(PROP_EXTENSIONS, ext, true); 150 } 151 152 158 public ExtensionList getExtensions() { 159 ExtensionList l = (ExtensionList) getProperty(PROP_EXTENSIONS); 160 if (l == null) { 161 l = new ExtensionList(); 162 putProperty(PROP_EXTENSIONS, l, false); 163 } 164 return l; 165 } 166 167 170 public void writeExternal (ObjectOutput oo) throws IOException { 171 super.writeExternal (oo); 172 173 oo.writeObject (getProperty (PROP_EXTENSIONS)); 174 } 175 176 179 public void readExternal (ObjectInput oi) 180 throws IOException , ClassNotFoundException { 181 SafeException se; 182 try { 183 super.readExternal (oi); 184 se = null; 185 } catch (SafeException se2) { 186 se = se2; 187 } 188 189 setExtensions ((ExtensionList)oi.readObject ()); 190 if (se != null) throw se; 191 } 192 193 } 194 | Popular Tags |