001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package jemmyI18NWizard.wizardSupport;
043:
044: import org.openide.filesystems.FileSystem;
045: import org.openide.filesystems.Repository;
046:
047: import java.io.*;
048: import org.openide.filesystems.FileObject;
049: import org.openide.loaders.DataObject;
050: import org.openide.cookies.SaveCookie;
051: import org.openide.util.RequestProcessor;
052: import java.util.Hashtable;
053:
054: public class Utilities {
055:
056: public static String getFilesystemPath() {
057:
058: org.openide.filesystems.FileObject fileObject = null;
059: org.openide.filesystems.FileSystem fileSystemRoot = null;
060: org.openide.filesystems.Repository repository;
061: try {
062: repository = Repository.getDefault();
063: fileObject = repository.find(
064: "jemmyI18NWizard.wizardSupport", "Utilities",
065: "class");
066: fileSystemRoot = fileObject.getFileSystem();
067:
068: } catch (Exception e) {
069: System.out
070: .println("Exception when identifying filesystem: "
071: + e);
072: }
073: return fileSystemRoot.getDisplayName();
074: }
075:
076: public static boolean compareBundles(String name1, String name2)
077: throws Exception {
078: BufferedReader file1 = null;
079: BufferedReader file2 = null;
080:
081: try {
082: file1 = new BufferedReader(new FileReader(new File(name1)));
083: file2 = new BufferedReader(new FileReader(new File(name2)));
084: } catch (Exception e) {
085: System.out.println("Exception when opening file: " + e);
086: throw e;
087: }
088:
089: Hashtable hashtable = new Hashtable();
090: String line;
091: while ((line = file1.readLine()) != null)
092: hashtable.put(line, line);
093:
094: while (true) {
095: line = file2.readLine();
096:
097: if (line == null)
098: return (hashtable.size() == 0);
099:
100: if (hashtable.containsKey(line))
101: hashtable.remove(line);
102: else
103: return false;
104: }
105: }
106:
107: public static void saveFile(String name) throws Exception {
108:
109: final String extension = name.substring(
110: name.lastIndexOf('.') + 1, name.length());
111: final String filename;
112: final String path;
113:
114: String shorter = name.substring(0, name.lastIndexOf('.'));
115: shorter = shorter.replace('/', '.');
116: shorter = shorter.replace('\\', '.');
117:
118: int lastDot = shorter.lastIndexOf('.');
119: if (lastDot == -1) {
120: filename = shorter;
121: path = "";
122: } else {
123: filename = shorter.substring(lastDot + 1, shorter.length());
124: if (shorter.startsWith("."))
125: shorter = shorter.substring(1);
126: path = shorter.substring(0, lastDot);
127: }
128:
129: final FileObject fObject = Repository.getDefault().find(path,
130: filename, extension);
131: if (fObject == null)
132: throw new Exception("Error finding fileobject");
133: final DataObject dObject = DataObject.find(fObject);
134:
135: Thread waitForSave = new Thread() {
136: public void run() {
137: SaveCookie sc = (SaveCookie) dObject
138: .getCookie(SaveCookie.class);
139: try {
140: if (sc != null)
141: sc.save();
142: } catch (Exception e) {
143: System.out.println("Error when saving file.");
144: }
145: }
146: };
147:
148: RequestProcessor.Task task = RequestProcessor
149: .postRequest(waitForSave);
150: task.waitFinished();
151: }
152:
153: }
|