|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package jemmyI18NWizard.wizardSupport; import org.openide.filesystems.FileSystem; import org.openide.filesystems.Repository; import java.io.*; import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; import org.openide.cookies.SaveCookie; import org.openide.util.RequestProcessor; import java.util.Hashtable; public class Utilities { public static String getFilesystemPath() { org.openide.filesystems.FileObject fileObject = null; org.openide.filesystems.FileSystem fileSystemRoot = null; org.openide.filesystems.Repository repository; try { repository = Repository.getDefault(); fileObject = repository.find("jemmyI18NWizard.wizardSupport", "Utilities","class"); fileSystemRoot = fileObject.getFileSystem(); } catch(Exception e) { System.out.println("Exception when identifying filesystem: " + e); } return fileSystemRoot.getDisplayName(); } public static boolean compareBundles(String name1, String name2) throws Exception { BufferedReader file1 = null; BufferedReader file2 = null; try { file1 = new BufferedReader(new FileReader(new File(name1))); file2 = new BufferedReader(new FileReader(new File(name2))); } catch(Exception e) { System.out.println("Exception when opening file: " + e); throw e; } Hashtable hashtable = new Hashtable(); String line; while((line = file1.readLine())!=null) hashtable.put(line, line); while(true) { line = file2.readLine(); if(line == null) return (hashtable.size() == 0); if(hashtable.containsKey(line)) hashtable.remove(line); else return false; } } public static void saveFile(String name) throws Exception { final String extension = name.substring(name.lastIndexOf('.')+1,name.length()); final String filename; final String path; String shorter = name.substring(0, name.lastIndexOf('.')); shorter = shorter.replace('/','.'); shorter = shorter.replace('\\','.'); int lastDot = shorter.lastIndexOf('.'); if(lastDot == -1) { filename = shorter; path = ""; } else { filename = shorter.substring(lastDot+1, shorter.length()); if(shorter.startsWith(".")) shorter = shorter.substring(1); path = shorter.substring(0, lastDot); } final FileObject fObject = Repository.getDefault().find(path, filename, extension); if(fObject == null) throw new Exception("Error finding fileobject"); final DataObject dObject = DataObject.find(fObject); Thread waitForSave = new Thread() { public void run() { SaveCookie sc = (SaveCookie)dObject.getCookie(SaveCookie.class); try { if(sc != null) sc.save(); } catch(Exception e) { System.out.println("Error when saving file."); } } }; RequestProcessor.Task task = RequestProcessor.postRequest(waitForSave); task.waitFinished(); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.