diff --git a/properties/src/org/netbeans/modules/properties/MultiBundleStructure.java b/properties/src/org/netbeans/modules/properties/MultiBundleStructure.java --- a/properties/src/org/netbeans/modules/properties/MultiBundleStructure.java +++ b/properties/src/org/netbeans/modules/properties/MultiBundleStructure.java @@ -60,6 +60,7 @@ private transient FileObject parent; private transient PropertiesFileEntry primaryEntry; private String baseName; + private String extension; /** Generated Serialized Version UID. */ static final long serialVersionUID = 7501232754255253334L; @@ -80,6 +81,7 @@ // super(obj); this.obj = obj; baseName = Util.getBaseName(obj.getName()); + extension = PropertiesDataLoader.PROPERTIES_EXTENSION; } /** @@ -104,6 +106,10 @@ } if (primaryEntry != null) { FileObject primary = primaryEntry.getFile(); + if(!primary.hasExt(extension)) { + if (primary.getMIMEType().equalsIgnoreCase(PropertiesDataLoader.PROPERTIES_MIME_TYPE)) + extension = primary.getExt(); + } parent = primary.getParent(); } else { if (parent == null) { @@ -114,7 +120,7 @@ String fName; FileObject oldCandidate; for (FileObject file : parent.getChildren()) { - if (!file.hasExt(PropertiesDataLoader.PROPERTIES_EXTENSION)) { + if (!file.hasExt(extension) || !file.getMIMEType().equalsIgnoreCase(PropertiesDataLoader.PROPERTIES_MIME_TYPE)) { continue; } fName = file.getName(); @@ -136,12 +142,20 @@ } } } + if (listFileObjects.isEmpty()) { + files = null; + return; + } files = listFileObjects.toArray(new FileObject[listFileObjects.size()]); if (primaryEntry != getNthEntry(0)) { //TODO XXX This means that primaryEntry has changed, so need to notify openSupport primaryEntry = getNthEntry(0); if (primaryEntry != null) { notifyOneFileChanged(primaryEntry.getFile()); + if(!primaryEntry.getFile().hasExt(extension)) { + if (primaryEntry.getFile().getMIMEType().equalsIgnoreCase(PropertiesDataLoader.PROPERTIES_MIME_TYPE)) + extension = primaryEntry.getFile().getExt(); + } parent = primaryEntry.getFile().getParent(); obj = (PropertiesDataObject) primaryEntry.getDataObject(); baseName = Util.getBaseName(obj.getName()); @@ -192,7 +206,8 @@ @Override public int getEntryIndexByFileName(String fileName) { if (files == null) { - notifyEntriesNotInitialized(); +// notifyEntriesNotInitialized(); + return -1; } for (int i = 0; i < getEntryCount(); i++) { if (files[i].getName().equals(fileName)) { diff --git a/properties/src/org/netbeans/modules/properties/PropertiesDataLoader.java b/properties/src/org/netbeans/modules/properties/PropertiesDataLoader.java --- a/properties/src/org/netbeans/modules/properties/PropertiesDataLoader.java +++ b/properties/src/org/netbeans/modules/properties/PropertiesDataLoader.java @@ -69,6 +69,9 @@ /** Extension for properties files. */ static final String PROPERTIES_EXTENSION = "properties"; // NOI18N + + /** Properties MIME type*/ + static final String PROPERTIES_MIME_TYPE = "text/x-properties"; //NOI18N /** Character used to separate parts of bundle properties file name */ public static final char PRB_SEPARATOR_CHAR = '_'; @@ -167,6 +170,9 @@ index = fName.indexOf(PRB_SEPARATOR_CHAR, index + 1); } } + return fo; + } else if(fo.getMIMEType().equalsIgnoreCase(PROPERTIES_MIME_TYPE)) { +// getExtensions().addExtension(fo.getExt()); return fo; } else { return getExtensions().isRegistered(fo) ? fo : null; diff --git a/properties/src/org/netbeans/modules/properties/Util.java b/properties/src/org/netbeans/modules/properties/Util.java --- a/properties/src/org/netbeans/modules/properties/Util.java +++ b/properties/src/org/netbeans/modules/properties/Util.java @@ -470,6 +470,11 @@ if(propertiesDataObject != null) { // FileObject file = propertiesDataObject.getPrimaryFile(); FileObject file = propertiesDataObject.getBundleStructure().getNthEntry(0).getFile(); + String extension = PropertiesDataLoader.PROPERTIES_EXTENSION; + if (!file.hasExt(extension)) { + if (file.getMIMEType().equalsIgnoreCase(PropertiesDataLoader.PROPERTIES_MIME_TYPE)) + extension = file.getExt(); + } //Default locale may be deleted final String newName = getBaseName(file.getName()) + PropertiesDataLoader.PRB_SEPARATOR_CHAR + locale; final FileObject folder = file.getParent(); @@ -485,32 +490,33 @@ } if (copyInitialContent) { - if (folder.getFileObject(newName, PropertiesDataLoader.PROPERTIES_EXTENSION) == null) { + if (folder.getFileObject(newName, extension) == null) { SaveCookie save = (SaveCookie) propertiesDataObject.getCookie(SaveCookie.class); if (save != null) { save.save(); } final FileObject templateFile = file; + final String ext = extension; folder.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { public void run() throws IOException { - templateFile.copy(folder, newName, PropertiesDataLoader.PROPERTIES_EXTENSION); + templateFile.copy(folder, newName, ext); } }); //find just created DataObject - PropertiesDataObject dataObject = (PropertiesDataObject) DataObject.find(folder.getFileObject(newName, PropertiesDataLoader.PROPERTIES_EXTENSION)); + PropertiesDataObject dataObject = (PropertiesDataObject) DataObject.find(folder.getFileObject(newName, extension)); dataObject.setBundleStructure(propertiesDataObject.getBundleStructure()); //update entries in BundleStructure propertiesDataObject.getBundleStructure().updateEntries(); //Add it to OpenSupport propertiesDataObject.getOpenSupport().addDataObject(dataObject); //Notify BundleStructure that one file changed - propertiesDataObject.getBundleStructure().notifyOneFileChanged(folder.getFileObject(newName, PropertiesDataLoader.PROPERTIES_EXTENSION)); + propertiesDataObject.getBundleStructure().notifyOneFileChanged(folder.getFileObject(newName, extension)); } } else { // Create an empty file - creating from template via DataObject // API would create a separate DataObject for the locale file. // After creation force the DataObject to refresh its entries. - DataObject.find(folder.createData(newName, PropertiesDataLoader.PROPERTIES_EXTENSION)); + DataObject.find(folder.createData(newName, extension)); } } } catch(IOException ioe) { @@ -569,10 +575,15 @@ */ static BundleStructure findBundleStructure (FileObject f, FileObject parent, String baseName) throws DataObjectNotFoundException{ String fName; - PropertiesDataObject dataObject; + PropertiesDataObject dataObject = null; BundleStructure structure; + String extension = PropertiesDataLoader.PROPERTIES_EXTENSION; + if (!f.hasExt(extension)) { + if (f.getMIMEType().equalsIgnoreCase(PropertiesDataLoader.PROPERTIES_MIME_TYPE)) + extension = f.getExt(); + } for (FileObject file : parent.getChildren()) { - if (!file.hasExt(PropertiesDataLoader.PROPERTIES_EXTENSION) || file.equals(f)) { + if (!file.hasExt(extension) || file.equals(f)) { continue; } fName = file.getName(); @@ -592,7 +603,12 @@ while (index != -1) { FileObject candidate = file; if (candidate != null && isValidLocaleSuffix(fName.substring(index)) && file.isValid()) { - dataObject = (PropertiesDataObject) DataObject.find(candidate); + DataObject defaultDataObject = DataObject.find(candidate); + if (defaultDataObject instanceof PropertiesDataObject) { + dataObject = (PropertiesDataObject) DataObject.find(candidate); + } else { + index = -1; + } if (dataObject == null) continue; structure = dataObject.getBundleStructureOrNull(); if (structure != null)