KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > persistence > WindowManagerParser


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.core.windows.persistence;
21
22 import java.util.logging.Level JavaDoc;
23 import org.netbeans.core.windows.Constants;
24 import org.netbeans.core.windows.Debug;
25 import org.netbeans.core.windows.SplitConstraint;
26 import org.openide.filesystems.FileLock;
27 import org.openide.filesystems.FileObject;
28 import org.openide.filesystems.FileUtil;
29 import org.openide.modules.ModuleInfo;
30 import org.openide.modules.SpecificationVersion;
31 import org.openide.util.NbBundle;
32 import org.xml.sax.*;
33 import org.xml.sax.helpers.DefaultHandler JavaDoc;
34
35 import java.awt.*;
36 import java.io.*;
37 import java.util.*;
38 import java.util.List JavaDoc;
39 import java.util.logging.Logger JavaDoc;
40
41 /**
42  * Handle loading/saving of WindowManager configuration data.
43  *
44  * @author Marek Slama
45  */

46
47 public class WindowManagerParser {
48     
49     public static final String JavaDoc INSTANCE_DTD_ID_1_0
50         = "-//NetBeans//DTD Window Manager Properties 1.0//EN"; // NOI18N
51
public static final String JavaDoc INSTANCE_DTD_ID_1_1
52         = "-//NetBeans//DTD Window Manager Properties 1.1//EN"; // NOI18N
53
public static final String JavaDoc INSTANCE_DTD_ID_2_0
54         = "-//NetBeans//DTD Window Manager Properties 2.0//EN"; // NOI18N
55
public static final String JavaDoc INSTANCE_DTD_ID_2_1
56         = "-//NetBeans//DTD Window Manager Properties 2.1//EN"; // NOI18N
57

58     private static final boolean DEBUG = Debug.isLoggable(WindowManagerParser.class);
59     
60     /** Unique wm name */
61     private String JavaDoc wmName;
62     
63     private PersistenceManager pm;
64     
65     private InternalConfig internalConfig;
66     
67     private Map<String JavaDoc, ModeParser> modeParserMap = new HashMap<String JavaDoc, ModeParser>(19);
68     
69     private Map<String JavaDoc, GroupParser> groupParserMap = new HashMap<String JavaDoc, GroupParser>(19);
70     
71     //Used to collect names of all localy stored wstcref files.
72
private Set<String JavaDoc> tcRefNameLocalSet = new HashSet<String JavaDoc>(101);
73     
74     private static Object JavaDoc SAVING_LOCK = new Object JavaDoc();
75     
76     public WindowManagerParser(PersistenceManager pm, String JavaDoc wmName) {
77         this.pm = pm;
78         this.wmName = wmName;
79     }
80
81     /** Load window manager configuration including all modes and tcrefs. */
82     WindowManagerConfig load() throws IOException {
83         synchronized (SAVING_LOCK) {
84             WindowManagerConfig wmc = new WindowManagerConfig();
85             readProperties(wmc);
86             readModes(wmc);
87             readGroups(wmc);
88             return wmc;
89         }
90     }
91     
92     /** Save window manager configuration including all modes and tcrefs. */
93     void save (WindowManagerConfig wmc) throws IOException {
94         synchronized (SAVING_LOCK) {
95             writeProperties(wmc);
96             writeModes(wmc);
97             writeGroups(wmc);
98         }
99     }
100     
101     /** Called from ModuleChangeHandler when wsmode file is deleted from module folder.
102      * Do not remove ModeParser. Only set that it is not present in module folder.
103      * @param modeName unique name of mode
104      */

105     void removeMode (String JavaDoc modeName) {
106         synchronized (SAVING_LOCK) {
107             if (DEBUG) Debug.log(WindowManagerParser.class, "removeMode" + " mo:" + modeName);
108             ModeParser modeParser = (ModeParser) modeParserMap.get(modeName);
109             if (modeParser != null) {
110                 modeParser.setInModuleFolder(false);
111             }
112             //deleteLocalMode(modeName);
113
}
114     }
115     
116     /** Called from ModuleChangeHandler when wsmode file is added to module folder.
117      * Adds ModeParser.
118      * @param modeName unique name of mode
119      */

120     ModeConfig addMode (String JavaDoc modeName) {
121         synchronized (SAVING_LOCK) {
122             if (DEBUG) Debug.log(WindowManagerParser.class, "addMode ENTER" + " mo:" + modeName);
123             ModeParser modeParser = (ModeParser) modeParserMap.get(modeName);
124             if (modeParser == null) {
125                 //Create new ModeParser if it does not exist.
126
modeParser = new ModeParser(modeName,tcRefNameLocalSet);
127                 modeParserMap.put(modeName, modeParser);
128             }
129             FileObject modesModuleFolder = null;
130             try {
131                 pm.getModesModuleFolder();
132             } catch (IOException exc) {
133                 PersistenceManager.LOG.log(Level.WARNING,
134                     "[WinSys.WindowManagerParser.addMode]" // NOI18N
135
+ " Cannot get modes folder", exc); // NOI18N
136
return null;
137             }
138             modeParser.setModuleParentFolder(modesModuleFolder);
139             modeParser.setInModuleFolder(true);
140             ModeConfig modeConfig = null;
141             try {
142                 modeConfig = modeParser.load();
143             } catch (IOException exc) {
144                 PersistenceManager.LOG.log(Level.WARNING,
145                 "[WinSys.WindowManagerParser.addMode]" // NOI18N
146
+ " Warning: Cannot load mode " + modeName, exc); // NOI18N
147
}
148             return modeConfig;
149         }
150     }
151     
152     /** Called from ModuleChangeHandler when wsgrp file is deleted from module folder.
153      * Removes GroupParser and cleans wsgrp file from local folder
154      * @param groupName unique name of group
155      */

156     void removeGroup (String JavaDoc groupName) {
157         synchronized (SAVING_LOCK) {
158             if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.removeGroup" + " group:" + groupName);
159             groupParserMap.remove(groupName);
160             deleteLocalGroup(groupName);
161         }
162     }
163     
164     /** Called from ModuleChangeHandler when wsgrp file is added to module folder.
165      * Adds GroupParser.
166      * @param groupName unique name of group
167      */

168     GroupConfig addGroup (String JavaDoc groupName) {
169         synchronized (SAVING_LOCK) {
170             if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.addGroup ENTER" + " group:" + groupName);
171             GroupParser groupParser = (GroupParser) groupParserMap.get(groupName);
172             if (groupParser != null) {
173                 PersistenceManager.LOG.log(Level.WARNING,
174                 "[WinSys.WindowManagerParser.addGroup]" // NOI18N
175
+ " Warning: GroupParser " + groupName // NOI18N
176
+ " exists but it should not."); // NOI18N
177
groupParserMap.remove(groupName);
178             }
179             groupParser = new GroupParser(groupName);
180             FileObject groupsModuleFolder = null;
181             try {
182                 pm.getGroupsModuleFolder();
183             } catch (IOException exc) {
184                 PersistenceManager.LOG.log(Level.WARNING,
185                     "[WinSys.WindowManagerParser.addGroup]" // NOI18N
186
+ " Cannot get groups folder", exc); // NOI18N
187
return null;
188             }
189             groupParser.setModuleParentFolder(groupsModuleFolder);
190             groupParser.setInModuleFolder(true);
191             //FileObject setsLocalFolder = pm.getGroupsLocalFolder();
192
//groupParser.setLocalParentFolder(groupsLocalFolder);
193
groupParserMap.put(groupName, groupParser);
194             GroupConfig groupConfig = null;
195             try {
196                 groupConfig = groupParser.load();
197             } catch (IOException exc) {
198                 PersistenceManager.LOG.log(Level.WARNING,
199                 "[WinSys.WindowManagerParser.addGroup]" // NOI18N
200
+ " Warning: Cannot load group " + groupName, exc); // NOI18N
201
}
202             return groupConfig;
203         }
204     }
205     
206     /** Called from ModuleChangeHandler when wstcref file is deleted from module folder
207      * or from package convert when some imported TCRef is deleted from imported module folder.
208      * Removes TCRefParser from ModeParser and cleans wstcref file from local folder
209      * @param tcRefName unique name of tcRef
210      */

211     public boolean removeTCRef (String JavaDoc tcRefName) {
212         synchronized (SAVING_LOCK) {
213             if (DEBUG) Debug.log(WindowManagerParser.class, "removeTCRef ENTER" + " tcRef:" + tcRefName);
214             ModeParser modeParser = findModeParser(tcRefName);
215             if (modeParser == null) {
216                 //modeParser was already removed -> its local folder was cleaned
217
if (DEBUG) Debug.log(WindowManagerParser.class, "removeTCRef LEAVE 1" + " tcRef:" + tcRefName);
218                 return false;
219             }
220             if (DEBUG) Debug.log(WindowManagerParser.class, "removeTCRef REMOVING tcRef:" + tcRefName
221             + " FROM mo:" + modeParser.getName()); // NOI18N
222
modeParser.removeTCRef(tcRefName);
223             if (DEBUG) Debug.log(WindowManagerParser.class, "removeTCRef LEAVE 2" + " tcRef:" + tcRefName);
224             return true;
225         }
226     }
227     
228     /** Called from ModuleChangeHandler when wstcref file is added to module folder.
229      * Adds TCRefParser to ModeParser.
230      * @param tcRefName unique name of tcRef
231      */

232     TCRefConfig addTCRef (String JavaDoc modeName, String JavaDoc tcRefName, List JavaDoc<String JavaDoc> tcRefNameList) {
233         synchronized (SAVING_LOCK) {
234             if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.addTCRef ENTER" + " mo:" + modeName
235             + " tcRef:" + tcRefName); // NOI18N
236
ModeParser modeParser = (ModeParser) modeParserMap.get(modeName);
237             if (modeParser == null) {
238                 if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.addTCRef LEAVE 1" + " mo:" + modeName
239                 + " tcRef:" + tcRefName);
240                 PersistenceManager.LOG.log(Level.WARNING,
241                 "[WinSys.WindowManagerParser.addTCRef]" // NOI18N
242
+ " Warning: Cannot add tcRef " + tcRefName + ". ModeParser " + modeName + " not found."); // NOI18N
243
return null;
244             }
245             TCRefConfig tcRefConfig = modeParser.addTCRef(tcRefName, tcRefNameList);
246             if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.addTCRef LEAVE 2" + " mo:" + modeName
247             + " tcRef:" + tcRefName); // NOI18N
248
return tcRefConfig;
249         }
250     }
251     
252     /** Called from ModuleChangeHandler when wstcgrp file is deleted from module folder.
253      * Removes TCGroupParser from GroupParser and cleans wstcgrp file from local folder
254      * @param tcGroupName unique name of tcGroup
255      */

256     boolean removeTCGroup (String JavaDoc groupName, String JavaDoc tcGroupName) {
257         synchronized (SAVING_LOCK) {
258             if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.removeTCGroup ENTER" + " group:" + groupName
259             + " tcGroup:" + tcGroupName); // NOI18N
260
GroupParser groupParser = (GroupParser) groupParserMap.get(groupName);
261             if (groupParser == null) {
262                 //groupParser was already removed -> its local folder was cleaned
263
if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.removeTCGroup LEAVE 1" + " group:" + groupName
264                 + " tcGroup:" + tcGroupName); // NOI18N
265
return false;
266             }
267             groupParser.removeTCGroup(tcGroupName);
268             if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.removeTCGroup LEAVE 2" + " group:" + groupName
269             + " tcGroup:" + tcGroupName); // NOI18N
270
return true;
271         }
272     }
273     
274     /** Called from ModuleChangeHandler when wstcgrp file is added to module folder.
275      * Adds TCGroupParser to GroupParser.
276      * @param tcGroupName unique name of tcGroup
277      */

278     TCGroupConfig addTCGroup (String JavaDoc groupName, String JavaDoc tcGroupName) {
279         synchronized (SAVING_LOCK) {
280             if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.addTCGroup ENTER" + " group:" + groupName
281             + " tcGroup:" + tcGroupName); // NOI18N
282
GroupParser groupParser = (GroupParser) groupParserMap.get(groupName);
283             if (groupParser == null) {
284                 if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.addTCGroup LEAVE 1" + " group:" + groupName
285                 + " tcGroup:" + tcGroupName); // NOI18N
286
PersistenceManager.LOG.log(Level.WARNING,
287                 "[WinSys.WindowManagerParser.addTCGroup]" // NOI18N
288
+ " Warning: Cannot add tcGroup " + tcGroupName + ". GroupParser " + groupName + " not found."); // NOI18N
289
return null;
290             }
291             TCGroupConfig tcGroupConfig = groupParser.addTCGroup(tcGroupName);
292             if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.addTCGroup LEAVE 2" + " group:" + groupName
293             + " tcGroup:" + tcGroupName); // NOI18N
294
return tcGroupConfig;
295         }
296     }
297     
298     /** Called from import to pass module info to new parser.
299      * Adds TCRefParser to ModeParser.
300      * @param tcRefName unique name of tcRef
301      */

302     public void addTCRefImport (String JavaDoc modeName, String JavaDoc tcRefName, InternalConfig internalCfg) {
303         if (DEBUG) Debug.log(WindowManagerParser.class, "addTCRefImport ENTER" + " mo:" + modeName
304         + " tcRef:" + tcRefName); // NOI18N
305
ModeParser modeParser = (ModeParser) modeParserMap.get(modeName);
306         if (modeParser == null) {
307             if (DEBUG) Debug.log(WindowManagerParser.class, "addTCRefImport LEAVE 1" + " mo:" + modeName
308             + " tcRef:" + tcRefName); // NOI18N
309
PersistenceManager.LOG.log(Level.WARNING,
310             "[WinSys.WindowManagerParser.addTCRef]" // NOI18N
311
+ " Warning: Cannot add tcRef " + tcRefName // NOI18N
312
+ ". ModeParser " + modeName + " not found."); // NOI18N
313
return;
314         }
315         modeParser.addTCRefImport(tcRefName, internalCfg);
316         if (DEBUG) Debug.log(WindowManagerParser.class, "addTCRefImport LEAVE 2" + " mo:" + modeName
317         + " tcRef:" + tcRefName); // NOI18N
318
}
319     
320     /** Finds ModeParser containing TCRef with given ID. Returns null if such ModeParser
321      * is not found.
322      * @param tcRefName unique name of tcRef
323      */

324     ModeParser findModeParser (String JavaDoc tcRefName) {
325         if (DEBUG) Debug.log(WindowManagerParser.class, "findModeParser ENTER" + " tcRef:" + tcRefName);
326         for (Iterator it = modeParserMap.keySet().iterator(); it.hasNext(); ) {
327             ModeParser modeParser = (ModeParser) modeParserMap.get(it.next());
328             TCRefParser tcRefParser = modeParser.findTCRefParser(tcRefName);
329             if (tcRefParser != null) {
330                 return modeParser;
331             }
332         }
333         return null;
334     }
335     
336     private void readProperties (WindowManagerConfig wmc) throws IOException {
337         if (DEBUG) Debug.log(WindowManagerParser.class, "readProperties ENTER");
338         PropertyHandler propertyHandler = new PropertyHandler();
339         internalConfig = new InternalConfig();
340         propertyHandler.readData(wmc, internalConfig);
341         if (DEBUG) Debug.log(WindowManagerParser.class, "readProperties LEAVE");
342     }
343     
344     private void readModes (WindowManagerConfig wmc) throws IOException {
345         if (DEBUG) Debug.log(WindowManagerParser.class, "readModes ENTER");
346         
347         for (Iterator it = modeParserMap.keySet().iterator(); it.hasNext(); ) {
348             ModeParser modeParser = (ModeParser) modeParserMap.get(it.next());
349             modeParser.setInModuleFolder(false);
350             modeParser.setInLocalFolder(false);
351         }
352         
353         FileObject modesModuleFolder = pm.getRootModuleFolder().getFileObject(PersistenceManager.MODES_FOLDER);
354         //if (DEBUG) Debug.log(WindowManagerParser.class, "modesModuleFolder: " + modesModuleFolder);
355
if (modesModuleFolder != null) {
356             FileObject [] files = modesModuleFolder.getChildren();
357             for (int i = 0; i < files.length; i++) {
358                 //if (DEBUG) Debug.log(WindowManagerParser.class, "fo[" + i + "]: " + files[i]);
359
if (!files[i].isFolder() && PersistenceManager.MODE_EXT.equals(files[i].getExt())) {
360                     //wsmode file
361
ModeParser modeParser = (ModeParser) modeParserMap.get(files[i].getName());
362                     if (modeParser == null) {
363                         modeParser = new ModeParser(files[i].getName(),tcRefNameLocalSet);
364                         modeParserMap.put(files[i].getName(), modeParser);
365                     }
366                     modeParser.setInModuleFolder(true);
367                     modeParser.setModuleParentFolder(modesModuleFolder);
368                 }
369             }
370         }
371         
372         FileObject modesLocalFolder = pm.getRootLocalFolder().getFileObject(PersistenceManager.MODES_FOLDER);
373         //if (DEBUG) Debug.log(WindowManagerParser.class, " modesLocalFolder: " + modesLocalFolder);
374
tcRefNameLocalSet.clear();
375         if (modesLocalFolder != null) {
376             FileObject [] files = modesLocalFolder.getChildren();
377             for (int i = 0; i < files.length; i++) {
378                 //if (DEBUG) Debug.log(WindowManagerParser.class, "fo[" + i + "]: " + files[i]);
379
if (!files[i].isFolder() && PersistenceManager.MODE_EXT.equals(files[i].getExt())) {
380                     //wsmode file
381
ModeParser modeParser;
382                     if (modeParserMap.containsKey(files[i].getName())) {
383                         modeParser = (ModeParser) modeParserMap.get(files[i].getName());
384                     } else {
385                         modeParser = new ModeParser(files[i].getName(),tcRefNameLocalSet);
386                         modeParserMap.put(files[i].getName(), modeParser);
387                     }
388                     modeParser.setInLocalFolder(true);
389                     modeParser.setLocalParentFolder(modesLocalFolder);
390                 }
391                 //Look for wstcref file in local folder
392
if (files[i].isFolder()) {
393                     FileObject [] subFiles = files[i].getChildren();
394                     for (int j = 0; j < subFiles.length; j++) {
395                         if (!subFiles[j].isFolder() && PersistenceManager.TCREF_EXT.equals(subFiles[j].getExt())) {
396                             //if (DEBUG) Debug.log(WindowManagerParser.class, "-- name: [" + files[i].getName() + "][" + subFiles[j].getName() + "]");
397
tcRefNameLocalSet.add(subFiles[j].getName());
398                         }
399                     }
400                 }
401             }
402         }
403         
404         /*for (Iterator it = modeParserMap.keySet().iterator(); it.hasNext(); ) {
405             ModeParser modeParser = (ModeParser) modeParserMap.get(it.next());
406             if (DEBUG) Debug.log(WindowManagerParser.class, "modeParser: " + modeParser.getName()
407             + " isInModuleFolder:" + modeParser.isInModuleFolder()
408             + " isInLocalFolder:" + modeParser.isInLocalFolder());
409         }*/

410         
411         //Check if corresponding module is present and enabled.
412
//We must load configuration data first because module info is stored in XML.
413
List JavaDoc<ModeConfig> modeCfgList = new ArrayList<ModeConfig>(modeParserMap.size());
414         List JavaDoc<ModeParser> toRemove = new ArrayList<ModeParser>(modeParserMap.size());
415         for (Iterator it = modeParserMap.keySet().iterator(); it.hasNext(); ) {
416             ModeParser modeParser = (ModeParser) modeParserMap.get(it.next());
417             ModeConfig modeCfg;
418             try {
419                 modeCfg = modeParser.load();
420             } catch (IOException exc) {
421                 //If reading of one Mode fails we want to log message
422
//and continue.
423
Logger.getLogger(WindowManagerParser.class.getName()).log(Level.WARNING, null, exc);
424                 continue;
425             }
426             boolean modeAccepted = acceptMode(modeParser, modeCfg);
427             if (modeAccepted) {
428                 modeCfgList.add(modeCfg);
429             } else {
430                 toRemove.add(modeParser);
431                 deleteLocalMode(modeParser.getName());
432             }
433         }
434         for (int i = 0; i < toRemove.size(); i++) {
435             ModeParser modeParser = (ModeParser) toRemove.get(i);
436             modeParserMap.remove(modeParser.getName());
437         }
438         
439         wmc.modes = modeCfgList.toArray(new ModeConfig[modeCfgList.size()]);
440         
441         if (DEBUG) Debug.log(WindowManagerParser.class, "readModes LEAVE");
442     }
443     
444     /** Checks if module for given mode exists.
445      * @return true if mode is valid - its module exists
446      */

447     private boolean acceptMode (ModeParser modeParser, ModeConfig config) {
448         InternalConfig cfg = modeParser.getInternalConfig();
449         //Check module info
450
if (cfg.moduleCodeNameBase != null) {
451             ModuleInfo curModuleInfo = PersistenceManager.findModule
452             (cfg.moduleCodeNameBase, cfg.moduleCodeNameRelease,
453              cfg.moduleSpecificationVersion);
454             if (curModuleInfo == null) {
455                 PersistenceManager.LOG.info("Cannot find module \'" +
456                           cfg.moduleCodeNameBase + " " + cfg.moduleCodeNameRelease + " " +
457                           cfg.moduleSpecificationVersion + "\' for wsmode with name \'" + config.name + "\'"); // NOI18N
458
}
459             if ((curModuleInfo != null) && curModuleInfo.isEnabled()) {
460                 //Module is present and is enabled
461
return true;
462             } else {
463                 //Module is NOT present (it could be deleted offline)
464
//or is NOT enabled
465
return false;
466             }
467         } else {
468             //No module info
469
return true;
470         }
471     }
472     
473     private void readGroups (WindowManagerConfig wmc) throws IOException {
474         if (DEBUG) Debug.log(WindowManagerParser.class, "readGroups ENTER");
475         
476         for (Iterator it = groupParserMap.keySet().iterator(); it.hasNext(); ) {
477             GroupParser groupParser = (GroupParser) groupParserMap.get(it.next());
478             groupParser.setInModuleFolder(false);
479             groupParser.setInLocalFolder(false);
480         }
481         
482         FileObject groupsModuleFolder = pm.getRootModuleFolder().getFileObject(PersistenceManager.GROUPS_FOLDER);
483         //if (DEBUG) Debug.log(WindowManagerParser.class, "readGroups groupsModuleFolder: " + groupsModuleFolder);
484

485         if (groupsModuleFolder != null) {
486             FileObject [] files;
487             files = groupsModuleFolder.getChildren();
488             for (int i = 0; i < files.length; i++) {
489                 //if (DEBUG) Debug.log(WindowManagerParser.class, "readGroups fo[" + i + "]: " + files[i]);
490
if (!files[i].isFolder() && PersistenceManager.GROUP_EXT.equals(files[i].getExt())) {
491                     GroupParser groupParser;
492                     //wsgrp file
493
if (groupParserMap.containsKey(files[i].getName())) {
494                         groupParser = (GroupParser) groupParserMap.get(files[i].getName());
495                     } else {
496                         groupParser = new GroupParser(files[i].getName());
497                         groupParserMap.put(files[i].getName(), groupParser);
498                     }
499                     groupParser.setInModuleFolder(true);
500                     groupParser.setModuleParentFolder(groupsModuleFolder);
501                 }
502             }
503         }
504         
505         FileObject groupsLocalFolder = pm.getRootLocalFolder().getFileObject(PersistenceManager.GROUPS_FOLDER);
506         if (groupsLocalFolder != null) {
507             //if (DEBUG) Debug.log(WindowManagerParser.class, "readGroups groupsLocalFolder: " + groupsLocalFolder);
508
FileObject [] files = groupsLocalFolder.getChildren();
509             for (int i = 0; i < files.length; i++) {
510                 //if (DEBUG) Debug.log(WindowManagerParser.class, "readGroups fo[" + i + "]: " + files[i]);
511
if (!files[i].isFolder() && PersistenceManager.GROUP_EXT.equals(files[i].getExt())) {
512                     //wsgrp file
513
GroupParser groupParser;
514                     if (groupParserMap.containsKey(files[i].getName())) {
515                         groupParser = (GroupParser) groupParserMap.get(files[i].getName());
516                     } else {
517                         groupParser = new GroupParser(files[i].getName());
518                         groupParserMap.put(files[i].getName(), groupParser);
519                     }
520                     groupParser.setInLocalFolder(true);
521                     groupParser.setLocalParentFolder(groupsLocalFolder);
522                 }
523             }
524         }
525         
526         /*for (Iterator it = groupParserMap.keySet().iterator(); it.hasNext(); ) {
527             GroupParser groupParser = (GroupParser) groupParserMap.get(it.next());
528             if (DEBUG) Debug.log(WindowManagerParser.class, "readGroups groupParser: " + groupParser.getName()
529             + " isInModuleFolder:" + groupParser.isInModuleFolder()
530             + " isInLocalFolder:" + groupParser.isInLocalFolder());
531         }*/

532         
533         //Check if corresponding module is present and enabled.
534
//We must load configuration data first because module info is stored in XML.
535
List JavaDoc<GroupConfig> groupCfgList = new ArrayList<GroupConfig>(groupParserMap.size());
536         List JavaDoc<GroupParser> toRemove = new ArrayList<GroupParser>(groupParserMap.size());
537         for (Iterator it = groupParserMap.keySet().iterator(); it.hasNext(); ) {
538             GroupParser groupParser = (GroupParser) groupParserMap.get(it.next());
539             GroupConfig groupCfg;
540             try {
541                 groupCfg = groupParser.load();
542             } catch (IOException exc) {
543                 //If reading of one group fails we want to log message
544
//and continue.
545
Logger.getLogger(WindowManagerParser.class.getName()).log(Level.WARNING, null, exc);
546                 continue;
547             }
548             boolean groupAccepted = acceptGroup(groupParser, groupCfg);
549             if (groupAccepted) {
550                 groupCfgList.add(groupCfg);
551             } else {
552                 toRemove.add(groupParser);
553                 deleteLocalGroup(groupParser.getName());
554             }
555         }
556         for (int i = 0; i < toRemove.size(); i++) {
557             GroupParser groupParser = (GroupParser) toRemove.get(i);
558             groupParserMap.remove(groupParser.getName());
559         }
560         
561         wmc.groups = groupCfgList.toArray(new GroupConfig[groupCfgList.size()]);
562         
563         if (DEBUG) Debug.log(WindowManagerParser.class, "readGroups LEAVE");
564     }
565     
566     /** Checks if module for given group exists.
567      * @return true if group is valid - its module exists
568      */

569     private boolean acceptGroup (GroupParser groupParser, GroupConfig config) {
570         InternalConfig cfg = groupParser.getInternalConfig();
571         //Check module info
572
if (cfg.moduleCodeNameBase != null) {
573             ModuleInfo curModuleInfo = PersistenceManager.findModule
574                                         (cfg.moduleCodeNameBase, cfg.moduleCodeNameRelease,
575                                          cfg.moduleSpecificationVersion);
576             if (curModuleInfo == null) {
577                 
578                 PersistenceManager.LOG.log(Level.FINE, "Cannot find module \'" +
579                           cfg.moduleCodeNameBase + " " + cfg.moduleCodeNameRelease + " " +
580                           cfg.moduleSpecificationVersion + "\' for group with name \'" + config.name + "\'"); // NOI18N
581

582             }
583             if ((curModuleInfo != null) && curModuleInfo.isEnabled()) {
584                 //Module is present and is enabled
585
return true;
586             } else {
587                 return false;
588             }
589         } else {
590             //No module info
591
return true;
592         }
593     }
594     
595     private void writeProperties (WindowManagerConfig wmc) throws IOException {
596         if (DEBUG) Debug.log(WindowManagerParser.class, "writeProperties ENTER");
597         PropertyHandler propertyHandler = new PropertyHandler();
598         propertyHandler.writeData(wmc);
599         if (DEBUG) Debug.log(WindowManagerParser.class, "writeProperties LEAVE");
600     }
601     
602     private void writeModes (WindowManagerConfig wmc) throws IOException {
603         if (DEBUG) Debug.log(WindowManagerParser.class, "writeModes ENTER");
604         //Step 1: Clean obsolete mode parsers
605
Map<String JavaDoc, ModeConfig> modeConfigMap = new HashMap<String JavaDoc, ModeConfig>();
606         for (int i = 0; i < wmc.modes.length; i++) {
607             modeConfigMap.put(wmc.modes[i].name, wmc.modes[i]);
608         }
609         List JavaDoc<String JavaDoc> toDelete = new ArrayList<String JavaDoc>(10);
610         for (String JavaDoc s: modeParserMap.keySet()) {
611             ModeParser modeParser = modeParserMap.get(s);
612             if (!modeConfigMap.containsKey(modeParser.getName())) {
613                 toDelete.add(modeParser.getName());
614             }
615         }
616         for (int i = 0; i < toDelete.size(); i++) {
617             //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.writeModes ** REMOVE FROM MAP modeParser: " + toDelete.get(i));
618
modeParserMap.remove(toDelete.get(i));
619             //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.writeModes ** DELETE modeParser: " + toDelete.get(i));
620
deleteLocalMode(toDelete.get(i));
621         }
622         
623         //Step 2: Create missing mode parsers
624
for (int i = 0; i < wmc.modes.length; i++) {
625             if (!modeParserMap.containsKey(wmc.modes[i].name)) {
626                 ModeParser modeParser = new ModeParser(wmc.modes[i].name,tcRefNameLocalSet);
627                 modeParserMap.put(wmc.modes[i].name, modeParser);
628                 //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.writeModes ** CREATE modeParser:" + modeParser.getName());
629
}
630         }
631         
632         FileObject modesLocalFolder = pm.getRootLocalFolder().getFileObject(PersistenceManager.MODES_FOLDER);
633         if ((modesLocalFolder == null) && (modeParserMap.size() > 0)) {
634             modesLocalFolder = pm.getModesLocalFolder();
635         }
636         //Step 3: Save all modes
637
for (Iterator it = modeParserMap.keySet().iterator(); it.hasNext(); ) {
638             ModeParser modeParser = (ModeParser) modeParserMap.get(it.next());
639             modeParser.setLocalParentFolder(modesLocalFolder);
640             modeParser.setInLocalFolder(true);
641             modeParser.save((ModeConfig) modeConfigMap.get(modeParser.getName()));
642         }
643         
644         if (DEBUG) Debug.log(WindowManagerParser.class, "writeModes LEAVE");
645     }
646     
647     private void writeGroups (WindowManagerConfig wmc) throws IOException {
648         if (DEBUG) Debug.log(WindowManagerParser.class, "writeGroups ENTER");
649         //Step 1: Clean obsolete group parsers
650
Map<String JavaDoc, GroupConfig> groupConfigMap = new HashMap<String JavaDoc, GroupConfig>();
651         //if (DEBUG) Debug.log(WindowManagerParser.class, "writeGroups List of groups to be saved:");
652
for (int i = 0; i < wmc.groups.length; i++) {
653             //if (DEBUG) Debug.log(WindowManagerParser.class, "writeGroups group[" + i + "]: " + wmc.groups[i].name);
654
groupConfigMap.put(wmc.groups[i].name, wmc.groups[i]);
655         }
656         List JavaDoc<String JavaDoc> toDelete = new ArrayList<String JavaDoc>(10);
657         for (String JavaDoc s: groupParserMap.keySet()) {
658             GroupParser groupParser = groupParserMap.get(s);
659             if (!groupConfigMap.containsKey(groupParser.getName())) {
660                 toDelete.add(groupParser.getName());
661             }
662         }
663         for (int i = 0; i < toDelete.size(); i++) {
664             //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.writeGroups ** REMOVE FROM MAP groupParser: " + toDelete.get(i));
665
groupParserMap.remove(toDelete.get(i));
666             //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.writeGroups ** DELETE groupParser: " + toDelete.get(i));
667
deleteLocalGroup(toDelete.get(i));
668         }
669         //Step 2: Create missing group parsers
670
for (int i = 0; i < wmc.groups.length; i++) {
671             if (!groupParserMap.containsKey(wmc.groups[i].name)) {
672                 GroupParser groupParser = new GroupParser(wmc.groups[i].name);
673                 groupParserMap.put(wmc.groups[i].name, groupParser);
674                 //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.writeGroups ** CREATE groupParser:" + groupParser.getName());
675
}
676         }
677         //Step 3: Save all groups
678
FileObject groupsLocalFolder = pm.getRootLocalFolder().getFileObject(PersistenceManager.GROUPS_FOLDER);
679         if ((groupsLocalFolder == null) && (groupParserMap.size() > 0)) {
680             groupsLocalFolder = pm.getGroupsLocalFolder();
681         }
682         //if (DEBUG) Debug.log(WindowManagerParser.class, "writeGroups groupsLocalFolder:" + groupsLocalFolder);
683
for (Iterator it = groupParserMap.keySet().iterator(); it.hasNext(); ) {
684             GroupParser groupParser = (GroupParser) groupParserMap.get(it.next());
685             groupParser.setLocalParentFolder(groupsLocalFolder);
686             groupParser.setInLocalFolder(true);
687             //if (DEBUG) Debug.log(WindowManagerParser.class, "writeGroups save group:" + groupParser.getName());
688
groupParser.save((GroupConfig) groupConfigMap.get(groupParser.getName()));
689         }
690         
691         if (DEBUG) Debug.log(WindowManagerParser.class, "writeGroups LEAVE");
692     }
693     
694     private void deleteLocalMode (String JavaDoc modeName) {
695         if (DEBUG) Debug.log(WindowManagerParser.class, "deleteLocalMode" + " mo:" + modeName);
696         FileObject rootFO = null;
697         try {
698             rootFO = pm.getRootLocalFolder();
699         } catch (IOException exc) {
700             PersistenceManager.LOG.log(Level.WARNING,
701                 "[WinSys.WindowManagerParser.deleteLocalMode]" // NOI18N
702
+ " Cannot get root local folder", exc); // NOI18N
703
return;
704         }
705         FileObject modesLocalFolder = rootFO.getFileObject(PersistenceManager.MODES_FOLDER);
706         if (modesLocalFolder == null) {
707             return;
708         }
709         FileObject modeFO;
710         modeFO = modesLocalFolder.getFileObject(modeName);
711         if (modeFO != null) {
712             PersistenceManager.deleteOneFO(modeFO);
713         }
714         modeFO = modesLocalFolder.getFileObject(modeName, PersistenceManager.MODE_EXT);
715         if (modeFO != null) {
716             PersistenceManager.deleteOneFO(modeFO);
717         }
718     }
719     
720     private void deleteLocalGroup (String JavaDoc groupName) {
721         if (DEBUG) Debug.log(WindowManagerParser.class, "deleteLocalGroup" + " groupName:" + groupName);
722         FileObject rootFO = null;
723         try {
724             rootFO = pm.getRootLocalFolder();
725         } catch (IOException exc) {
726             PersistenceManager.LOG.log(Level.WARNING,
727                 "[WinSys.WindowManagerParser.deleteLocalGroup]" // NOI18N
728
+ " Cannot get root local folder", exc); // NOI18N
729
return;
730         }
731         FileObject groupsLocalFolder = rootFO.getFileObject(PersistenceManager.GROUPS_FOLDER);
732         if (groupsLocalFolder == null) {
733             return;
734         }
735         FileObject groupFO;
736         groupFO = groupsLocalFolder.getFileObject(groupName);
737         if (groupFO != null) {
738             PersistenceManager.deleteOneFO(groupFO);
739         }
740         groupFO = groupsLocalFolder.getFileObject(groupName, PersistenceManager.GROUP_EXT);
741         if (groupFO != null) {
742             PersistenceManager.deleteOneFO(groupFO);
743         }
744     }
745     
746     String JavaDoc getName () {
747         return wmName;
748     }
749     
750     void log (String JavaDoc s) {
751         if (DEBUG) {
752             Debug.log(WindowManagerParser.class, s);
753         }
754     }
755     
756     private final class PropertyHandler extends DefaultHandler JavaDoc {
757         
758         /** WindowManager configuration data */
759         private WindowManagerConfig winMgrConfig = null;
760         
761         /** Internal configuration data */
762         private InternalConfig internalConfig = null;
763         
764         /** List to store parsed path items */
765         private List JavaDoc<SplitConstraint> itemList = new ArrayList<SplitConstraint>(10);
766         
767         /** List to store parsed tc-ids */
768         private List JavaDoc<String JavaDoc> tcIdList = new ArrayList<String JavaDoc>(10);
769         
770         /** Lock to prevent mixing readData and writeData */
771         private final Object JavaDoc RW_LOCK = new Object JavaDoc();
772         
773         public PropertyHandler () {
774         }
775         
776         private FileObject getConfigFOInput () throws IOException {
777             FileObject rootFolder;
778
779             rootFolder = pm.getRootLocalFolder();
780
781             //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.getConfigFOInput" + " rootFolder:" + rootFolder);
782

783             FileObject wmConfigFO;
784             //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.getConfigFOInput" + " looking for LOCAL");
785
wmConfigFO = rootFolder.getFileObject
786             (WindowManagerParser.this.getName(), PersistenceManager.WINDOWMANAGER_EXT);
787             if (wmConfigFO != null) {
788                 //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.getConfigFOInput" + " wmConfigFO LOCAL:" + wmConfigFO);
789
return wmConfigFO;
790             } else {
791                 //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.getConfigFOInput" + " LOCAL not found");
792
//if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.getConfigFOInput" + " looking for MODULE");
793
//Local data not found, try module
794
rootFolder = pm.getRootModuleFolder();
795                 wmConfigFO = rootFolder.getFileObject
796                 (WindowManagerParser.this.getName(), PersistenceManager.WINDOWMANAGER_EXT);
797
798                 //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.getConfigFOInput" + " wmConfigFO MODULE:" + wmConfigFO);
799

800                 return wmConfigFO;
801             }
802         }
803
804         private FileObject getConfigFOOutput () throws IOException {
805             FileObject rootFolder;
806             rootFolder = pm.getRootLocalFolder();
807             
808             //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.getConfigFOOutput" + " rootFolder:" + rootFolder);
809

810             FileObject wmConfigFO;
811             //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.getConfigFOOutput" + " looking for LOCAL");
812
wmConfigFO = rootFolder.getFileObject
813             (WindowManagerParser.this.getName(), PersistenceManager.WINDOWMANAGER_EXT);
814             if (wmConfigFO != null) {
815                 //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.getConfigFOOutput" + " wmConfigFO LOCAL:" + wmConfigFO);
816
return wmConfigFO;
817             } else {
818                 StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
819                 buffer.append(WindowManagerParser.this.getName());
820                 buffer.append('.');
821                 buffer.append(PersistenceManager.WINDOWMANAGER_EXT);
822                 wmConfigFO = FileUtil.createData(rootFolder, buffer.toString());
823                 //if (DEBUG) Debug.log(WindowManagerParser.class, "-- WMParser.getConfigFOOutput" + " LOCAL not found CREATE");
824
return wmConfigFO;
825             }
826         }
827         
828         /**
829          Reads window manager configuration data from XML file.
830          Data are returned in output params.
831          */

832         void readData (WindowManagerConfig winMgrCfg, InternalConfig internalCfg)
833         throws IOException {
834             winMgrConfig = winMgrCfg;
835             internalConfig = internalCfg;
836             itemList.clear();
837             tcIdList.clear();
838             
839             FileObject cfgFOInput = getConfigFOInput();
840             if (cfgFOInput == null) {
841                 throw new FileNotFoundException("[WinSys] Missing Window Manager configuration file");
842             }
843             InputStream is = null;
844             try {
845                 synchronized (RW_LOCK) {
846                     //DUMP BEGIN
847
/*InputStream is = cfgFOInput.getInputStream();
848                     byte [] arr = new byte [is.available()];
849                     is.read(arr);
850                     if (DEBUG) Debug.log(WindowManagerParser.class, "DUMP WindowManager:");
851                     String s = new String(arr);
852                     if (DEBUG) Debug.log(WindowManagerParser.class, s);*/

853                     //DUMP END
854
// long time = System.currentTimeMillis();
855
is = cfgFOInput.getInputStream();
856                     PersistenceManager.getDefault().getXMLParser(this).parse(new InputSource(is));
857 // System.out.println("WindowManagerParser.readData "+(System.currentTimeMillis()-time));
858
}
859             } catch (SAXException exc) {
860                 // Turn into annotated IOException
861
String JavaDoc msg = NbBundle.getMessage(WindowManagerParser.class,
862                                                  "EXC_WindowManagerParse",
863                                                  cfgFOInput);
864
865                 throw (IOException) new IOException(msg).initCause(exc);
866             } finally {
867                 try {
868                     if (is != null) {
869                         is.close();
870                     }
871                 } catch (IOException exc) {
872                     Logger.getLogger(WindowManagerParser.class.getName()).log(Level.WARNING, null, exc);
873                 }
874             }
875             
876             winMgrConfig.editorAreaConstraints =
877                 itemList.toArray(new SplitConstraint[itemList.size()]);
878             winMgrConfig.tcIdViewList =
879                 tcIdList.toArray(new String JavaDoc[tcIdList.size()]);
880             winMgrCfg = winMgrConfig;
881             internalCfg = internalConfig;
882             
883             winMgrConfig = null;
884             internalConfig = null;
885         }
886         
887         public void startElement (String JavaDoc nameSpace, String JavaDoc name, String JavaDoc qname, Attributes attrs) throws SAXException {
888             if ("windowmanager".equals(qname)) { // NOI18N
889
handleWindowManager(attrs);
890             } else if (internalConfig.specVersion.compareTo(new SpecificationVersion("2.0")) >= 0) { //NOI18N
891
//Parse version 2.0 and 2.1
892
if ("main-window".equals(qname)) { // NOI18N
893
handleMainWindow(attrs);
894                 } else if ("joined-properties".equals(qname)) { // NOI18N
895
handleJoinedProperties(attrs);
896                 } else if ("separated-properties".equals(qname)) { // NOI18N
897
handleSeparatedProperties(attrs);
898                 } else if ("editor-area".equals(qname)) { // NOI18N
899
handleEditorArea(attrs);
900                 } else if ("constraints".equals(qname)) { // NOI18N
901
handleConstraints(attrs);
902                 } else if ("path".equals(qname)) { // NOI18N
903
handlePath(attrs);
904                 } else if ("bounds".equals(qname)) { // NOI18N
905
handleEditorAreaBounds(attrs);
906                 } else if ("relative-bounds".equals(qname)) { // NOI18N
907
handleEditorAreaRelativeBounds(attrs);
908                 } else if ("screen".equals(qname)) { // NOI18N
909
handleScreen(attrs);
910                 } else if ("active-mode".equals(qname)) { // NOI18N
911
handleActiveMode(attrs);
912                 } else if ("maximized-mode".equals(qname)) { // NOI18N
913
handleMaximizedMode(attrs);
914                 } else if ("toolbar".equals(qname)) { // NOI18N
915
handleToolbar(attrs);
916                 } else if ("tc-id".equals(qname)) { // NOI18N
917
handleTcId(attrs);
918                 } else if ("tcref-item".equals(qname)) { // NOI18N
919
handleTCRefItem(attrs);
920                 }
921             } else {
922                 if (DEBUG) Debug.log(WindowManagerParser.class, "WMP.startElement PARSING OLD");
923                 //Parse version < 2.0
924
}
925         }
926
927         public void error(SAXParseException ex) throws SAXException {
928             throw ex;
929         }
930
931         /** Reads element "windowmanager" */
932         private void handleWindowManager (Attributes attrs) {
933             String JavaDoc version = attrs.getValue("version"); // NOI18N
934
if (version != null) {
935                 internalConfig.specVersion = new SpecificationVersion(version);
936             } else {
937                 PersistenceManager.LOG.log(Level.WARNING,
938                 "[WinSys.WindowManagerParser.handleWindowManager]" // NOI18N
939
+ " Missing attribute \"version\" of element \"windowmanager\"."); // NOI18N
940
internalConfig.specVersion = new SpecificationVersion("2.0"); // NOI18N
941
}
942         }
943         
944         /** Reads element "main-window" and updates window manager config content */
945         private void handleMainWindow (Attributes attrs) {
946         }
947         
948         /** Reads element "joined-properties" and updates window manager config content */
949         private void handleJoinedProperties (Attributes attrs) {
950             String JavaDoc s;
951             try {
952                 s = attrs.getValue("x"); // NOI18N
953
if (s != null) {
954                     winMgrConfig.xJoined = Integer.parseInt(s);
955                 } else {
956                     winMgrConfig.xJoined = -1;
957                 }
958             } catch (NumberFormatException JavaDoc exc) {
959                 
960                 PersistenceManager.LOG.log(Level.WARNING,
961                 "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
962
+ " Warning: Cannot read attribute \"x\"" // NOI18N
963
+ " of element \"joined-properties\".", exc); // NOI18N
964
winMgrConfig.xJoined = -1;
965             }
966             
967             try {
968                 s = attrs.getValue("y"); // NOI18N
969
if (s != null) {
970                     winMgrConfig.yJoined = Integer.parseInt(s);
971                 } else {
972                     winMgrConfig.yJoined = -1;
973                 }
974             } catch (NumberFormatException JavaDoc exc) {
975                 
976                 PersistenceManager.LOG.log(Level.WARNING,
977                 "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
978
+ " Warning: Cannot read attribute \"y\"" // NOI18N
979
+ " of element \"joined-properties\".", exc); // NOI18N
980
winMgrConfig.yJoined = -1;
981             }
982             
983             try {
984                 s = attrs.getValue("width"); // NOI18N
985
if (s != null) {
986                     winMgrConfig.widthJoined = Integer.parseInt(s);
987                 } else {
988                     winMgrConfig.widthJoined = -1;
989                 }
990             } catch (NumberFormatException JavaDoc exc) {
991                 
992                 PersistenceManager.LOG.log(Level.WARNING,
993                 "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
994
+ " Warning: Cannot read attribute \"width\"" // NOI18N
995
+ " of element \"joined-properties\".", exc); // NOI18N
996
winMgrConfig.widthJoined = -1;
997             }
998             
999             try {
1000                s = attrs.getValue("height"); // NOI18N
1001
if (s != null) {
1002                    winMgrConfig.heightJoined = Integer.parseInt(s);
1003                } else {
1004                    winMgrConfig.heightJoined = -1;
1005                }
1006            } catch (NumberFormatException JavaDoc exc) {
1007                
1008                PersistenceManager.LOG.log(Level.WARNING,
1009                "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
1010
+ " Warning: Cannot read attribute \"height\"" // NOI18N
1011
+ " of element \"joined-properties\".", exc); // NOI18N
1012
winMgrConfig.heightJoined = -1;
1013            }
1014            
1015            try {
1016                s = attrs.getValue("relative-x"); // NOI18N
1017
if (s != null) {
1018                    winMgrConfig.relativeXJoined = floatParse(s);
1019                } else {
1020                    winMgrConfig.relativeXJoined = -1;
1021                }
1022            } catch (NumberFormatException JavaDoc exc) {
1023                
1024                PersistenceManager.LOG.log(Level.WARNING,
1025                "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
1026
+ " Warning: Cannot read attribute \"relative-x\"" // NOI18N
1027
+ " of element \"joined-properties\".", exc); // NOI18N
1028
winMgrConfig.relativeXJoined = -1;
1029            }
1030            
1031            try {
1032                s = attrs.getValue("relative-y"); // NOI18N
1033

1034                if (s != null) {
1035                    winMgrConfig.relativeYJoined = floatParse(s);
1036                } else {
1037                    winMgrConfig.relativeYJoined = -1;
1038                }
1039            } catch (NumberFormatException JavaDoc exc) {
1040                
1041                PersistenceManager.LOG.log(Level.WARNING,
1042                "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
1043
+ " Warning: Cannot read attribute \"relative-y\"" // NOI18N
1044
+ " of element \"joined-properties\".", exc); // NOI18N
1045
winMgrConfig.relativeYJoined = -1;
1046            }
1047            
1048            try {
1049                s = attrs.getValue("relative-width"); // NOI18N
1050
if (s != null) {
1051                    winMgrConfig.relativeWidthJoined = floatParse(s);
1052                } else {
1053                    winMgrConfig.relativeWidthJoined = -1;
1054                }
1055            } catch (NumberFormatException JavaDoc exc) {
1056                
1057                PersistenceManager.LOG.log(Level.WARNING,
1058                "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
1059
+ " Warning: Cannot read attribute \"relative-width\"" // NOI18N
1060
+ " of element \"joined-properties\".", exc); // NOI18N
1061
winMgrConfig.relativeWidthJoined = -1;
1062            }
1063            
1064            try {
1065                s = attrs.getValue("relative-height"); // NOI18N
1066
if (s != null) {
1067                    winMgrConfig.relativeHeightJoined = floatParse(s);
1068                } else {
1069                    winMgrConfig.relativeHeightJoined = -1;
1070                }
1071            } catch (NumberFormatException JavaDoc exc) {
1072                
1073                PersistenceManager.LOG.log(Level.WARNING,
1074                "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
1075
+ " Warning: Cannot read attribute \"relative-height\"" // NOI18N
1076
+ " of element \"joined-properties\".",exc); // NOI18N
1077
winMgrConfig.relativeHeightJoined = -1;
1078            }
1079            
1080            s = attrs.getValue("centered-horizontally"); // NOI18N
1081
if (s != null) {
1082                if ("true".equals(s)) { // NOI18N
1083
winMgrConfig.centeredHorizontallyJoined = true;
1084                } else if ("false".equals(s)) { // NOI18N
1085
winMgrConfig.centeredHorizontallyJoined = false;
1086                } else {
1087                    PersistenceManager.LOG.log(Level.WARNING,
1088                    "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
1089
+ " Warning: Invalid value of attribute \"centered-horizontally\"" // NOI18N
1090
+ " of element \"joined-properties\"."); // NOI18N
1091
winMgrConfig.centeredHorizontallyJoined = false;
1092                }
1093            } else {
1094                winMgrConfig.centeredHorizontallyJoined = false;
1095            }
1096            
1097            s = attrs.getValue("centered-vertically"); // NOI18N
1098
if (s != null) {
1099                if ("true".equals(s)) { // NOI18N
1100
winMgrConfig.centeredVerticallyJoined = true;
1101                } else if ("false".equals(s)) { // NOI18N
1102
winMgrConfig.centeredVerticallyJoined = false;
1103                } else {
1104                    PersistenceManager.LOG.log(Level.WARNING,
1105                    "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
1106
+ " Warning: Invalid value of attribute \"centered-vertically\"" // NOI18N
1107
+ " of element \"joined-properties\"."); // NOI18N
1108
winMgrConfig.centeredVerticallyJoined = false;
1109                }
1110            } else {
1111                winMgrConfig.centeredVerticallyJoined = false;
1112            }
1113            
1114            try {
1115                s = attrs.getValue("maximize-if-width-below"); // NOI18N
1116
if (s != null) {
1117                    winMgrConfig.maximizeIfWidthBelowJoined = Integer.parseInt(s);
1118                } else {
1119                    winMgrConfig.maximizeIfWidthBelowJoined = -1;
1120                }
1121            } catch (NumberFormatException JavaDoc exc) {
1122                
1123                PersistenceManager.LOG.log(Level.WARNING,
1124                "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
1125
+ " Warning: Cannot read attribute \"maximize-if-width-below\"" // NOI18N
1126
+ " of element \"joined-properties\".", exc); // NOI18N
1127
winMgrConfig.maximizeIfWidthBelowJoined = -1;
1128            }
1129            
1130            try {
1131                s = attrs.getValue("maximize-if-height-below"); // NOI18N
1132
if (s != null) {
1133                    winMgrConfig.maximizeIfHeightBelowJoined = Integer.parseInt(s);
1134                } else {
1135                    winMgrConfig.maximizeIfHeightBelowJoined = -1;
1136                }
1137            } catch (NumberFormatException JavaDoc exc) {
1138                
1139                PersistenceManager.LOG.log(Level.WARNING,
1140                "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
1141
+ " Warning: Cannot read attribute \"maximize-if-height-below\"" // NOI18N
1142
+ " of element \"joined-properties\".", exc);
1143                winMgrConfig.maximizeIfHeightBelowJoined = -1;
1144            }
1145            
1146            String JavaDoc frameState = attrs.getValue("frame-state"); // NOI18N
1147
if (frameState != null) {
1148                try {
1149                    winMgrConfig.mainWindowFrameStateJoined = Integer.parseInt(frameState);
1150                } catch (NumberFormatException JavaDoc exc) {
1151                    
1152                    PersistenceManager.LOG.log(Level.WARNING,
1153                    "[WinSys.WindowManagerParser.handleJoinedProperties]" // NOI18N
1154
+ " Warning: Cannot read attribute \"frame-state\"" // NOI18N
1155
+ " of element \"joined-properties\".", exc); // NOI18N
1156
winMgrConfig.mainWindowFrameStateJoined = Frame.NORMAL;
1157                }
1158            } else {
1159                winMgrConfig.mainWindowFrameStateJoined = Frame.NORMAL;
1160            }
1161        }
1162        
1163        /** Reads element "separated-properties" and updates window manager config content */
1164        private void handleSeparatedProperties (Attributes attrs) {
1165            String JavaDoc s;
1166            try {
1167                s = attrs.getValue("x"); // NOI18N
1168
if (s != null) {
1169                    winMgrConfig.xSeparated = Integer.parseInt(s);
1170                } else {
1171                    winMgrConfig.xSeparated = -1;
1172                }
1173            } catch (NumberFormatException JavaDoc exc) {
1174                
1175                PersistenceManager.LOG.log(Level.WARNING,
1176                "[WinSys.WindowManagerParser.handleSeparatedProperties]" // NOI18N
1177
+ " Warning: Cannot read attribute \"x\"" // NOI18N
1178
+ " of element \"separated-properties\".", exc); // NOI18N
1179
winMgrConfig.xSeparated = -1;
1180            }
1181            
1182            try {
1183                s = attrs.getValue("y"); // NOI18N
1184
if (s != null) {
1185                    winMgrConfig.ySeparated = Integer.parseInt(s);
1186                } else {
1187                    winMgrConfig.ySeparated = -1;
1188                }
1189            } catch (NumberFormatException JavaDoc exc) {
1190                
1191                PersistenceManager.LOG.log(Level.WARNING,
1192                "[WinSys.WindowManagerParser.handleSeparatedProperties]" // NOI18N
1193
+ " Warning: Cannot read attribute \"y\"" // NOI18N
1194
+ " of element \"separated-properties\".", exc); // NOI18N
1195
winMgrConfig.ySeparated = -1;
1196            }
1197            
1198            try {
1199                s = attrs.getValue("width"); // NOI18N
1200
if (s != null) {
1201                    winMgrConfig.widthSeparated = Integer.parseInt(s);
1202                } else {
1203                    winMgrConfig.widthSeparated = -1;
1204                }
1205            } catch (NumberFormatException JavaDoc exc) {
1206                
1207                PersistenceManager.LOG.log(Level.WARNING,
1208                "[WinSys.WindowManagerParser.handleSeparatedProperties]" // NOI18N
1209
+ " Warning: Cannot read attribute \"width\"" // NOI18N
1210
+ " of element \"separated-properties\".", exc); // NOI18N
1211
winMgrConfig.widthSeparated = -1;
1212            }
1213            
1214            try {
1215                s = attrs.getValue("height"); // NOI18N
1216
if (s != null) {
1217                    winMgrConfig.heightSeparated = Integer.parseInt(s);
1218                } else {
1219                    winMgrConfig.heightSeparated = -1;
1220                }
1221            } catch (NumberFormatException JavaDoc exc) {
1222                
1223                PersistenceManager.LOG.log(Level.WARNING,
1224                "[WinSys.WindowManagerParser.handleSeparatedProperties]" // NOI18N
1225
+ " Warning: Cannot read attribute \"height\"" // NOI18N
1226
+ " of element \"separated-properties\".", exc); // NOI18N
1227
winMgrConfig.heightSeparated = -1;
1228            }
1229            
1230            try {
1231                s = attrs.getValue("relative-x"); // NOI18N
1232
if (s != null) {
1233                    winMgrConfig.relativeXSeparated = floatParse(s);
1234                } else {
1235                    winMgrConfig.relativeXSeparated = -1;
1236                }
1237            } catch (NumberFormatException JavaDoc exc) {
1238                
1239                PersistenceManager.LOG.log(Level.WARNING,
1240                "[WinSys.WindowManagerParser.handleSeparatedProperties]" // NOI18N
1241
+ " Warning: Cannot read attribute \"relative-x\"" // NOI18N
1242
+ " of element \"separated-properties\".", exc); // NOI18N
1243
winMgrConfig.relativeXSeparated = -1;
1244            }
1245            
1246            try {
1247                s = attrs.getValue("relative-y"); // NOI18N
1248
if (s != null) {
1249                    winMgrConfig.relativeYSeparated = floatParse(s);
1250                } else {
1251                    winMgrConfig.relativeYSeparated = -1;
1252                }
1253            } catch (NumberFormatException JavaDoc exc) {
1254                
1255                PersistenceManager.LOG.log(Level.WARNING,
1256                "[WinSys.WindowManagerParser.handleSeparatedProperties]" // NOI18N
1257
+ " Warning: Cannot read attribute \"relative-y\"" // NOI18N
1258
+ " of element \"separated-properties\".", exc); // NOI18N
1259
winMgrConfig.relativeYSeparated = -1;
1260            }
1261            
1262            try {
1263                s = attrs.getValue("relative-width"); // NOI18N
1264
if (s != null) {
1265                    winMgrConfig.relativeWidthSeparated = floatParse(s);
1266                } else {
1267                    winMgrConfig.relativeWidthSeparated = -1;
1268                }
1269            } catch (NumberFormatException JavaDoc exc) {
1270                
1271                PersistenceManager.LOG.log(Level.WARNING,
1272                "[WinSys.WindowManagerParser.handleSeparatedProperties]" // NOI18N
1273
+ " Warning: Cannot read attribute \"relative-width\"" // NOI18N
1274
+ " of element \"separated-properties\".", exc); // NOI18N
1275
winMgrConfig.relativeWidthSeparated = -1;
1276            }
1277            
1278            try {
1279                s = attrs.getValue("relative-height"); // NOI18N
1280
if (s != null) {
1281                    winMgrConfig.relativeHeightSeparated = floatParse(s);
1282                } else {
1283                    winMgrConfig.relativeHeightSeparated = -1;
1284                }
1285            } catch (NumberFormatException JavaDoc exc) {
1286                
1287                PersistenceManager.LOG.log(Level.WARNING,
1288                "[WinSys.WindowManagerParser.handleSeparatedProperties]" // NOI18N
1289
+ " Warning: Cannot read attribute \"relative-height\"" // NOI18N
1290
+ " of element \"separated-properties\".", exc); // NOI18N
1291
winMgrConfig.relativeHeightSeparated = -1;
1292            }
1293            
1294            s = attrs.getValue("centered-horizontally"); // NOI18N
1295
if (s != null) {
1296                if ("true".equals(s)) { // NOI18N
1297
winMgrConfig.centeredHorizontallySeparated = true;
1298                } else if ("false".equals(s)) { // NOI18N
1299
winMgrConfig.centeredHorizontallySeparated = false;
1300                } else {
1301                    PersistenceManager.LOG.log(Level.WARNING,
1302                    "[WinSys.WindowManagerParser.handleSeparatedProperties]" // NOI18N
1303
+ " Warning: Invalid value of attribute \"centered-horizontally\"" // NOI18N
1304
+ " of element \"separated-properties\"."); // NOI18N
1305
winMgrConfig.centeredHorizontallySeparated = false;
1306                }
1307            } else {
1308                winMgrConfig.centeredHorizontallySeparated = false;
1309            }
1310            
1311            s = attrs.getValue("centered-vertically"); // NOI18N
1312
if (s != null) {
1313                if ("true".equals(s)) { // NOI18N
1314
winMgrConfig.centeredVerticallySeparated = true;
1315                } else if ("false".equals(s)) { // NOI18N
1316
winMgrConfig.centeredVerticallySeparated = false;
1317                } else {
1318                    PersistenceManager.LOG.log(Level.WARNING,
1319                    "[WinSys.WindowManagerParser.handleSeparatedProperties]" // NOI18N
1320
+ " Warning: Invalid value of attribute \"centered-vertically\"" // NOI18N
1321
+ " of element \"separated-properties\"."); // NOI18N
1322
winMgrConfig.centeredVerticallySeparated = false;
1323                }
1324            } else {
1325                winMgrConfig.centeredVerticallySeparated = false;
1326            }
1327            
1328            String JavaDoc frameState = attrs.getValue("frame-state"); // NOI18N
1329
if (frameState != null) {
1330                try {
1331                    winMgrConfig.mainWindowFrameStateSeparated = Integer.parseInt(frameState);
1332                } catch (NumberFormatException JavaDoc exc) {
1333                    
1334                    PersistenceManager.LOG.log(Level.WARNING,
1335                    "[WinSys.WindowManagerParser.handleSeparatedProperties]" // NOI18N
1336
+ " Warning: Cannot read attribute \"frame-state\"" // NOI18N
1337
+ " of element \"separated-properties\".", exc); // NOI18N
1338
winMgrConfig.mainWindowFrameStateSeparated = Frame.NORMAL;
1339                }
1340            } else {
1341                winMgrConfig.mainWindowFrameStateSeparated = Frame.NORMAL;
1342            }
1343        }
1344        
1345        /** Reads element "editor-area" */
1346        private void handleEditorArea (Attributes attrs) {
1347            String JavaDoc state = attrs.getValue("state"); // NOI18N
1348
if (state != null) {
1349                if ("joined".equals(state)) {
1350                    winMgrConfig.editorAreaState = Constants.EDITOR_AREA_JOINED;
1351                } else if ("separated".equals(state)) {
1352                    winMgrConfig.editorAreaState = Constants.EDITOR_AREA_SEPARATED;
1353                } else {
1354                    PersistenceManager.LOG.log(Level.WARNING,
1355                    "[WinSys.WindowManagerParser.handleEditorArea]" // NOI18N
1356
+ " Warning: Invalid value of attribute \"state\"" // NOI18N
1357
+ " of element \"editor-area\"."); // NOI18N
1358
winMgrConfig.editorAreaState = Constants.EDITOR_AREA_JOINED;
1359                }
1360            } else {
1361                PersistenceManager.LOG.log(Level.WARNING,
1362                "[WinSys.WindowManagerParser.handleEditorArea]" // NOI18N
1363
+ " Warning: Missing value of attribute \"state\"" // NOI18N
1364
+ " of element \"editor-area\"."); // NOI18N
1365
winMgrConfig.editorAreaState = Constants.EDITOR_AREA_JOINED;
1366            }
1367            String JavaDoc frameState = attrs.getValue("frame-state"); // NOI18N
1368
if (frameState != null) {
1369                try {
1370                    winMgrConfig.editorAreaFrameState = Integer.parseInt(frameState);
1371                } catch (NumberFormatException JavaDoc exc) {
1372                    
1373                    PersistenceManager.LOG.log(Level.WARNING,
1374                    "[WinSys.WindowManagerParser.handleEditorArea]" // NOI18N
1375
+ " Warning: Cannot read attribute \"frame-state\"" // NOI18N
1376
+ " of element \"editor-area\".", exc); // NOI18N
1377
winMgrConfig.editorAreaFrameState = Frame.NORMAL;
1378                }
1379            } else {
1380                winMgrConfig.editorAreaFrameState = Frame.NORMAL;
1381            }
1382        }
1383        
1384        /** Reads element "constraints" */
1385        private void handleConstraints (Attributes attrs) {
1386        }
1387        
1388        /** Reads element "path" */
1389        private void handlePath (Attributes attrs) {
1390            String JavaDoc s = attrs.getValue("orientation"); // NOI18N
1391
int orientation;
1392            if ("horizontal".equals(s)) { // NOI18N
1393
orientation = Constants.HORIZONTAL;
1394            } else if ("vertical".equals(s)) { // NOI18N
1395
orientation = Constants.VERTICAL;
1396            } else {
1397                PersistenceManager.LOG.log(Level.WARNING,
1398                "[WinSys.WindowManagerParser.handlePath]" // NOI18N
1399
+ " Invalid or missing value of attribute \"orientation\"."); // NOI18N
1400
orientation = Constants.VERTICAL;
1401            }
1402            
1403            int number;
1404            try {
1405                s = attrs.getValue("number"); // NOI18N
1406
if (s != null) {
1407                    number = Integer.parseInt(s);
1408                } else {
1409                    PersistenceManager.LOG.log(Level.WARNING,
1410                    "[WinSys.WindowManagerParser.handlePath]" // NOI18N
1411
+ " Missing value of attribute \"number\"."); // NOI18N
1412
number = 0;
1413                }
1414            } catch (NumberFormatException JavaDoc exc) {
1415                
1416                PersistenceManager.LOG.log(Level.WARNING,
1417                    "[WinSys.WindowManagerParser.handlePath]" // NOI18N
1418
+ " Cannot read element \"path\", attribute \"number\"", exc); // NOI18N
1419
number = 0;
1420            }
1421            
1422            double weight;
1423            try {
1424                s = attrs.getValue("weight"); // NOI18N
1425
if (s != null) {
1426                    weight = Double.parseDouble(s);
1427                } else {
1428                    //Not required attribute, provide default value
1429
weight = 0.5;
1430                }
1431            } catch (NumberFormatException JavaDoc exc) {
1432                
1433                PersistenceManager.LOG.log(Level.WARNING,
1434                "[WinSys.WindowManagerParser.handlePath]" // NOI18N
1435
+ " Warning: Cannot read element \"path\", attribute \"weight\".", exc); // NOI18N
1436
weight = 0.5;
1437            }
1438            SplitConstraint item = new SplitConstraint(orientation, number, weight);
1439            itemList.add(item);
1440        }
1441        
1442        /** Reads element "screen" and updates window manager config content */
1443        private void handleScreen (Attributes attrs) {
1444            try {
1445                String JavaDoc s;
1446                winMgrConfig.screenSize = null;
1447                int width, height;
1448                s = attrs.getValue("width"); // NOI18N
1449
if (s != null) {
1450                    width = Integer.parseInt(s);
1451                } else {
1452                    PersistenceManager.LOG.log(Level.WARNING,
1453                    "[WinSys.WindowManagerParser.handleScreen]" // NOI18N
1454
+ " Warning: Missing attribute \"width\" of element \"screen\"."); // NOI18N
1455
return;
1456                }
1457                s = attrs.getValue("height"); // NOI18N
1458
if (s != null) {
1459                    height = Integer.parseInt(s);
1460                } else {
1461                    PersistenceManager.LOG.log(Level.WARNING,
1462                        "[WinSys.WindowManagerParser.handleScreen]" // NOI18N
1463
+ " Warning: Missing attribute \"height\" of element \"screen\"."); // NOI18N
1464
return;
1465                }
1466                winMgrConfig.screenSize = new Dimension(width, height);
1467            } catch (NumberFormatException JavaDoc exc) {
1468                
1469                PersistenceManager.LOG.log(Level.WARNING,
1470                "[WinSys.WindowManagerParser.handleScreen]" // NOI18N
1471
+ " Warning: Cannot read element \"screen\".", exc); // NOI18N
1472
}
1473        }
1474        
1475        /** Reads element "bounds" of editor area and updates window manager config content */
1476        private void handleEditorAreaBounds (Attributes attrs) {
1477            try {
1478                String JavaDoc s;
1479                int x, y, width, height;
1480                
1481                winMgrConfig.editorAreaBounds = null;
1482                s = attrs.getValue("x"); // NOI18N
1483
if (s != null) {
1484                    x = Integer.parseInt(s);
1485                } else {
1486                    PersistenceManager.LOG.log(Level.WARNING,
1487                    "[WinSys.WindowManagerParser.handleEditorAreaBounds]" // NOI18N
1488
+ " Warning: Missing attribute \"x\" of element \"bounds\"."); // NOI18N
1489
return;
1490                }
1491                s = attrs.getValue("y"); // NOI18N
1492
if (s != null) {
1493                    y = Integer.parseInt(s);
1494                } else {
1495                    PersistenceManager.LOG.log(Level.WARNING,
1496                    "[WinSys.WindowManagerParser.handleEditorAreaBounds]" // NOI18N
1497
+ " Warning: Missing attribute \"y\" of element \"bounds\"."); // NOI18N
1498
return;
1499                }
1500                s = attrs.getValue("width"); // NOI18N
1501
if (s != null) {
1502                    width = Integer.parseInt(s);
1503                } else {
1504                    PersistenceManager.LOG.log(Level.WARNING,
1505                    "[WinSys.WindowManagerParser.handleEditorAreaBounds]" // NOI18N
1506
+ " Warning: Missing attribute \"width\" of element \"bounds\"."); // NOI18N
1507
return;
1508                }
1509                s = attrs.getValue("height"); // NOI18N
1510
if (s != null) {
1511                    height = Integer.parseInt(s);
1512                } else {
1513                    PersistenceManager.LOG.log(Level.WARNING,
1514                    "[WinSys.WindowManagerParser.handleEditorAreaBounds]" // NOI18N
1515
+ " Warning: Missing attribute \"height\" of element \"bounds\"."); // NOI18N
1516
return;
1517                }
1518                winMgrConfig.editorAreaBounds = new Rectangle(x, y, width, height);
1519            } catch (NumberFormatException JavaDoc exc) {
1520                PersistenceManager.LOG.log(Level.WARNING,
1521                "[WinSys.WindowManagerParser.handleEditorAreaBounds]" // NOI18N
1522
+ " Warning: Cannot read element \"bounds\".", exc); // NOI18N
1523
}
1524        }
1525        
1526        /** Reads element "relative-bounds" of editor area and updates window manager config content */
1527        private void handleEditorAreaRelativeBounds (Attributes attrs) {
1528            try {
1529                String JavaDoc s;
1530                int x, y, width, height;
1531                
1532                winMgrConfig.editorAreaRelativeBounds = null;
1533                s = attrs.getValue("x"); // NOI18N
1534
if (s != null) {
1535                    x = Integer.parseInt(s);
1536                } else {
1537                    PersistenceManager.LOG.log(Level.WARNING,
1538                    "[WinSys.WindowManagerParser.handleEditorAreaRelativeBounds]" // NOI18N
1539
+ " Warning: Missing attribute \"x\" of element \"relative-bounds\"."); // NOI18N
1540
return;
1541                }
1542                s = attrs.getValue("y"); // NOI18N
1543
if (s != null) {
1544                    y = Integer.parseInt(s);
1545                } else {
1546                    PersistenceManager.LOG.log(Level.WARNING,
1547                    "[WinSys.WindowManagerParser.handleEditorAreaRelativeBounds]" // NOI18N
1548
+ " Warning: Missing attribute \"y\" of element \"relative-bounds\"."); // NOI18N
1549
return;
1550                }
1551                s = attrs.getValue("width"); // NOI18N
1552
if (s != null) {
1553                    width = Integer.parseInt(s);
1554                } else {
1555                    PersistenceManager.LOG.log(Level.WARNING,
1556                    "[WinSys.WindowManagerParser.handleEditorAreaRelativeBounds]" // NOI18N
1557
+ " Warning: Missing attribute \"width\" of element \"relative-bounds\"."); // NOI18N
1558
return;
1559                }
1560                s = attrs.getValue("height"); // NOI18N
1561
if (s != null) {
1562                    height = Integer.parseInt(s);
1563                } else {
1564                    PersistenceManager.LOG.log(Level.WARNING,
1565                    "[WinSys.WindowManagerParser.handleEditorAreaRelativeBounds]" // NOI18N
1566
+ " Warning: Missing attribute \"height\" of element \"relative-bounds\"."); // NOI18N
1567
return;
1568                }
1569                winMgrConfig.editorAreaRelativeBounds = new Rectangle(x, y, width, height);
1570            } catch (NumberFormatException JavaDoc exc) {
1571                
1572                PersistenceManager.LOG.log(Level.WARNING,
1573                "[WinSys.WindowManagerParser.handleEditorAreaRelativeBounds]" // NOI18N
1574
+ " Warning: Cannot read element \"relative-bounds\".", exc); // NOI18N
1575
}
1576        }
1577        
1578        /** Reads element "active-mode" and updates window manager config content */
1579        private void handleActiveMode (Attributes attrs) {
1580            String JavaDoc name = attrs.getValue("name"); // NOI18N
1581
if (name != null) {
1582                winMgrConfig.activeModeName = name;
1583            } else {
1584                winMgrConfig.activeModeName = ""; // NOI18N
1585
}
1586        }
1587        
1588        /** Reads element "maximized-mode" and updates window manager config content */
1589        private void handleMaximizedMode (Attributes attrs) {
1590            String JavaDoc name = attrs.getValue("editor"); // NOI18N
1591
if (name != null) {
1592                winMgrConfig.editorMaximizedModeName = name;
1593            } else {
1594                winMgrConfig.editorMaximizedModeName = ""; // NOI18N
1595
}
1596            
1597            name = attrs.getValue("view"); // NOI18N
1598
if (name != null) {
1599                winMgrConfig.viewMaximizedModeName = name;
1600            } else {
1601                winMgrConfig.viewMaximizedModeName = ""; // NOI18N
1602
}
1603        }
1604        
1605        /** Reads element "toolbar" and updates window manager config content */
1606        private void handleToolbar (Attributes attrs) {
1607            String JavaDoc configuration = attrs.getValue("configuration"); // NOI18N
1608
if (configuration != null) {
1609                winMgrConfig.toolbarConfiguration = configuration;
1610            } else {
1611                winMgrConfig.toolbarConfiguration = ""; // NOI18N
1612
}
1613            String JavaDoc prefIconSize = attrs.getValue("preferred-icon-size"); // NOI18N
1614
if (prefIconSize != null) {
1615                try {
1616                    winMgrConfig.preferredToolbarIconSize = Integer.parseInt(prefIconSize);
1617                    if ((winMgrConfig.preferredToolbarIconSize != 16) &&
1618                        (winMgrConfig.preferredToolbarIconSize != 24)) {
1619                        
1620                        PersistenceManager.LOG.log(Level.WARNING,
1621                        "[WinSys.WindowManagerParser.handleToolbar]" // NOI18N
1622
+ " Warning: Invalid value of attribute \"preferred-icon-size\"" //NOI18N
1623
+ " of element \"toolbar\": " + winMgrConfig.preferredToolbarIconSize //NOI18N
1624
+ ". Fixed to default value 24."); // NOI18N
1625
winMgrConfig.preferredToolbarIconSize = 24;
1626                    }
1627                } catch (NumberFormatException JavaDoc exc) {
1628                    
1629                    PersistenceManager.LOG.log(Level.WARNING,
1630                    "[WinSys.WindowManagerParser.handleToolbar]" // NOI18N
1631
+ " Warning: Cannot read attribute \"preferred-icon-size\"" //NOI18N
1632
+ " of element \"toolbar\"." // NOI18N
1633
+ " Fixed to default value 24.", exc); // NOI18N
1634
winMgrConfig.preferredToolbarIconSize = 24;
1635                }
1636            } else {
1637                winMgrConfig.preferredToolbarIconSize = 24;
1638            }
1639        }
1640        
1641        /** Reads element "tc-id" and updates window manager config content */
1642        private void handleTcId (Attributes attrs) {
1643            String JavaDoc id = attrs.getValue("id"); // NOI18N
1644
if (id != null) {
1645                if (!"".equals(id)) {
1646                    tcIdList.add(id);
1647                } else {
1648                    PersistenceManager.LOG.log(Level.WARNING,
1649                    "[WinSys.WindowManagerParser.handleTcId]" // NOI18N
1650
+ " Warning: Empty required attribute \"id\" of element \"tc-id\"."); // NOI18N
1651
}
1652            } else {
1653                PersistenceManager.LOG.log(Level.WARNING,
1654                "[WinSys.WindowManagerParser.handleTcId]" // NOI18N
1655
+ " Warning: Missing required attribute \"id\" of element \"tc-id\"."); // NOI18N
1656
}
1657        }
1658        
1659        /** Reads element "tcref-item" */
1660        private void handleTCRefItem (Attributes attrs) {
1661            String JavaDoc workspaceName = attrs.getValue("workspace"); // NOI18N
1662
String JavaDoc modeName = attrs.getValue("mode"); // NOI18N
1663
String JavaDoc tc_id = attrs.getValue("id"); // NOI18N
1664

1665            if (workspaceName != null) {
1666                if ("".equals(workspaceName)) {
1667                    PersistenceManager.LOG.log(Level.WARNING,
1668                    "[WinSys.WindowManagerParser.handleTCRefItem]" // NOI18N
1669
+ " Warning: Empty required attribute \"workspace\" of element \"tcref-item\"."); // NOI18N
1670
return;
1671                }
1672            } else {
1673                PersistenceManager.LOG.log(Level.WARNING,
1674                "[WinSys.WindowManagerParser.handleTCRefItem]" // NOI18N
1675
+ " Warning: Missing required attribute \"workspace\" of element \"tcref-item\"."); // NOI18N
1676
return;
1677            }
1678            if (modeName != null) {
1679                if ("".equals(modeName)) {
1680                    PersistenceManager.LOG.log(Level.WARNING,
1681                    "[WinSys.WindowManagerParser.handleTCRefItem]" // NOI18N
1682
+ " Warning: Empty required attribute \"mode\" of element \"tcref-item\"."); // NOI18N
1683
return;
1684                }
1685            } else {
1686                PersistenceManager.LOG.log(Level.WARNING,
1687                "[WinSys.WindowManagerParser.handleTCRefItem]" // NOI18N
1688
+ " Warning: Missing required attribute \"mode\" of element \"tcref-item\"."); // NOI18N
1689
return;
1690            }
1691            if (tc_id != null) {
1692                if ("".equals(tc_id)) {
1693                    PersistenceManager.LOG.log(Level.WARNING,
1694                    "[WinSys.WindowManagerParser.handleTCRefItem]" // NOI18N
1695
+ " Warning: Empty required attribute \"id\" of element \"tcref-item\"."); // NOI18N
1696
return;
1697                }
1698            } else {
1699                PersistenceManager.LOG.log(Level.WARNING,
1700                "[WinSys.WindowManagerParser.handleTCRefItem]" // NOI18N
1701
+ " Warning: Missing required attribute \"id\" of element \"tcref-item\"."); // NOI18N
1702
return;
1703            }
1704        }
1705        
1706        /** Writes data from asociated window manager to the xml representation */
1707        void writeData (WindowManagerConfig wmc) throws IOException {
1708            final StringBuffer JavaDoc buff = fillBuffer(wmc);
1709            synchronized (RW_LOCK) {
1710                FileObject cfgFOOutput = getConfigFOOutput();
1711                FileLock lock = null;
1712                OutputStream os = null;
1713                OutputStreamWriter osw = null;
1714                try {
1715                    lock = cfgFOOutput.lock();
1716                    os = cfgFOOutput.getOutputStream(lock);
1717                    osw = new OutputStreamWriter(os, "UTF-8"); // NOI18N
1718
osw.write(buff.toString());
1719                    //if (DEBUG) Debug.log(WindowManagerParser.class, "-- DUMP WindowManager:");
1720
//if (DEBUG) Debug.log(WindowManagerParser.class, buff.toString());
1721
} finally {
1722                    try {
1723                        if (osw != null) {
1724                            osw.close();
1725                        }
1726                    } catch (IOException exc) {
1727                        Logger.getLogger(WindowManagerParser.class.getName()).log(Level.WARNING, null, exc);
1728                    }
1729                    if (lock != null) {
1730                        lock.releaseLock();
1731                    }
1732                }
1733            }
1734        }
1735        
1736        /** Returns xml content in StringBuffer
1737         */

1738        private StringBuffer JavaDoc fillBuffer (WindowManagerConfig wmc) throws IOException {
1739            StringBuffer JavaDoc buff = new StringBuffer JavaDoc(800);
1740            String JavaDoc curValue = null;
1741            // header
1742
buff.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"). // NOI18N
1743
/*buff.append("<!DOCTYPE windowmanager PUBLIC\n"); // NOI18N
1744            buff.append(" \"-//NetBeans//DTD Window Manager Properties 2.0//EN\"\n"); // NOI18N
1745            buff.append(" \"http://www.netbeans.org/dtds/windowmanager-properties2_0.dtd\">\n\n"); // NOI18N*/

1746                append("<windowmanager version=\"2.1\">\n"); // NOI18N
1747

1748            appendMainWindow(wmc, buff);
1749            appendEditorArea(wmc, buff);
1750            appendScreen(wmc, buff);
1751            appendActiveMode(wmc, buff);
1752            appendMaximizedMode(wmc, buff);
1753            appendToolbar(wmc, buff);
1754            appendRecentViewList(wmc, buff);
1755            
1756            buff.append("</windowmanager>\n"); // NOI18N
1757
return buff;
1758        }
1759        
1760
1761        private void appendMainWindow (WindowManagerConfig wmc, StringBuffer JavaDoc buff) {
1762            buff.append(" <main-window>\n <joined-properties\n"). // NOI18N
1763
append(" x=\"").append(wmc.xJoined).append("\"\n"). // NOI18N
1764
append(" y=\"").append(wmc.yJoined).append("\"\n"). // NOI18N
1765
append(" width=\"").append(wmc.widthJoined).append("\"\n"). // NOI18N
1766
append(" height=\"").append(wmc.heightJoined).append("\"\n"). // NOI18N
1767
append(" relative-x=\"").append(wmc.relativeXJoined).append("\"\n"). // NOI18N
1768
append(" relative-y=\"").append(wmc.relativeYJoined).append("\"\n"). // NOI18N
1769
append(" relative-width=\"").append(wmc.relativeWidthJoined).append("\"\n"). // NOI18N
1770
append(" relative-height=\"").append(wmc.relativeHeightJoined).append("\"\n"). // NOI18N
1771
append(" centered-horizontally=\"").append(wmc.centeredHorizontallyJoined).append("\"\n"). // NOI18N
1772
append(" centered-vertically=\"").append(wmc.centeredVerticallyJoined).append("\"\n"). // NOI18N
1773
append(" maximize-if-width-below=\"").append(wmc.maximizeIfWidthBelowJoined).append("\"\n"). // NOI18N
1774
append(" maximize-if-height-below=\"").append(wmc.maximizeIfHeightBelowJoined).append("\"\n"). // NOI18N
1775
append(" frame-state=\"").append(wmc.mainWindowFrameStateJoined).append("\"\n/>\n"). // NOI18N
1776

1777            //SEPARATED
1778
append(" <separated-properties\n"). // NOI18N
1779
append(" x=\"").append(wmc.xSeparated).append("\"\n"). // NOI18N
1780
append(" y=\"").append(wmc.ySeparated).append("\"\n"). // NOI18N
1781
append(" width=\"").append(wmc.widthSeparated).append("\"\n"). // NOI18N
1782
append(" height=\"").append(wmc.heightSeparated).append("\"\n"). // NOI18N
1783
append(" relative-x=\"").append(wmc.relativeXSeparated).append("\"\n"). // NOI18N
1784
append(" relative-y=\"").append(wmc.relativeYSeparated).append("\"\n"). // NOI18N
1785
append(" relative-width=\"").append(wmc.relativeWidthSeparated).append("\"\n"). // NOI18N
1786
append(" relative-height=\"").append(wmc.relativeHeightSeparated).append("\"\n"). // NOI18N
1787
append(" centered-horizontally=\"").append(wmc.centeredHorizontallySeparated).append("\"\n"). // NOI18N
1788
append(" centered-vertically=\"").append(wmc.centeredVerticallySeparated).append("\"\n"). // NOI18N
1789
append(" frame-state=\"").append(wmc.mainWindowFrameStateSeparated).append("\"\n"). // NOI18N
1790
append("/>\n </main-window>\n"); // NOI18N
1791
}
1792        
1793        private void appendEditorArea (WindowManagerConfig wmc, StringBuffer JavaDoc buff) {
1794            buff.append(" <editor-area state=\""); // NOI18N
1795
if (wmc.editorAreaState == Constants.EDITOR_AREA_JOINED) {
1796                buff.append("joined"); // NOI18N
1797
} else {
1798                buff.append("separated"); // NOI18N
1799
}
1800            buff.append("\" frame-state=\"").append(wmc.editorAreaFrameState).append("\">\n"); // NOI18N
1801

1802            //BEGIN Write constraints
1803
buff.append(" <constraints>\n"); // NOI18N
1804
for (int i = 0; i < wmc.editorAreaConstraints.length; i++) {
1805                SplitConstraint item = wmc.editorAreaConstraints[i];
1806                buff.append(" <path orientation=\""); // NOI18N
1807
if (item.orientation == Constants.HORIZONTAL) {
1808                    buff.append("horizontal"); // NOI18N
1809
} else {
1810                    buff.append("vertical"); // NOI18N
1811
}
1812                buff.append("\" number=\"").append(item.index).append("\" weight=\"").append(item.splitWeight).append("\" />\n"); // NOI18N
1813
}
1814            buff.append(" </constraints>\n"); // NOI18N
1815
//END Write constraints
1816
//BEGIN bounds or relative bounds
1817
if (wmc.editorAreaBounds != null) {
1818                buff.append(" <bounds x=\"").append(wmc.editorAreaBounds.x).
1819                    append("\" y=\"").append(wmc.editorAreaBounds.y).
1820                    append("\" width=\"").append(wmc.editorAreaBounds.width).append("\" height=\""); // NOI18N
1821
buff.append(wmc.editorAreaBounds.height).append("\" />\n"); // NOI18N
1822
} else if (wmc.editorAreaRelativeBounds != null) {
1823                buff.append(" <relative-bounds x=\"").append(wmc.editorAreaRelativeBounds.x).
1824                    append("\" y=\"").append(wmc.editorAreaRelativeBounds.y).
1825                    append("\" width=\"").append(wmc.editorAreaRelativeBounds.width).
1826                    append("\" height=\"").append(wmc.editorAreaRelativeBounds.height).append("\"/>\n"); // NOI18N
1827
}
1828            //END
1829
buff.append(" </editor-area>\n"); // NOI18N
1830
}
1831        
1832        private void appendScreen (WindowManagerConfig wmc, StringBuffer JavaDoc buff) {
1833            buff.append(" <screen width=\"").append(wmc.screenSize.width). // NOI18N
1834
append("\" height=\"").append(wmc.screenSize.height).append("\"/>\n"); // NOI18N
1835
}
1836        
1837        private void appendActiveMode (WindowManagerConfig wmc, StringBuffer JavaDoc buff) {
1838            if ((wmc.activeModeName != null) && !"".equals(wmc.activeModeName)) {
1839                buff.append(" <active-mode name=\"").append(wmc.activeModeName).append("\"/>\n"); // NOI18N
1840
}
1841        }
1842        
1843        private void appendMaximizedMode (WindowManagerConfig wmc, StringBuffer JavaDoc buff) {
1844            if ((wmc.editorMaximizedModeName != null && !"".equals(wmc.editorMaximizedModeName))
1845                || (wmc.viewMaximizedModeName != null && !"".equals(wmc.viewMaximizedModeName))) {
1846                buff.append(" <maximized-mode");
1847                if (wmc.editorMaximizedModeName != null && !"".equals(wmc.editorMaximizedModeName))
1848                    buff.append( " editor=\"").append(wmc.editorMaximizedModeName).append("\""); // NOI18N
1849
if (wmc.viewMaximizedModeName != null && !"".equals(wmc.viewMaximizedModeName))
1850                    buff.append( " view=\"").append(wmc.viewMaximizedModeName).append("\""); // NOI18N
1851
buff.append("/>\n"); // NOI18N
1852
}
1853        }
1854        
1855        private void appendToolbar (WindowManagerConfig wmc, StringBuffer JavaDoc buff) {
1856            buff.append(" <toolbar"); //NOI18N
1857
if ((wmc.toolbarConfiguration != null) && !"".equals(wmc.toolbarConfiguration)) { //NOI18N
1858
buff.append(" configuration=\"").append(wmc.toolbarConfiguration).append("\""); // NOI18N
1859
}
1860            buff.append(" preferred-icon-size=\"").append(wmc.preferredToolbarIconSize).append("\"/>\n"); //NOI18N
1861
}
1862        
1863        private void appendRecentViewList (WindowManagerConfig wmc, StringBuffer JavaDoc buff) {
1864            if (wmc.tcIdViewList.length == 0) {
1865                return;
1866            }
1867            buff.append(" <tc-list>\n"); // NOI18N
1868
for (int i = 0; i < wmc.tcIdViewList.length; i++) {
1869                buff.append(" <tc-id id=\"").append(wmc.tcIdViewList[i]).append("\"/>\n"); // NOI18N
1870
}
1871            buff.append(" </tc-list>\n"); // NOI18N
1872
}
1873        
1874    }
1875    
1876    /** Float.parseFloat() shows up as a startup hotspot (classloading?), so this uses a
1877     * lookup table for common values */

1878    private static final float floatParse (String JavaDoc s) throws NumberFormatException JavaDoc {
1879        int i = Arrays.binarySearch(floatStrings, s);
1880        if (i >= 0) {
1881            return floatVals[i];
1882        }
1883        return Float.parseFloat(s);
1884    }
1885    
1886    private static final String JavaDoc[] floatStrings = new String JavaDoc[] {
1887        "0", "0.0", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", // NOI18N
1888
"0.9","1","1.0" // NOI18N
1889
};
1890    
1891    private static final float[] floatVals = new float[] {
1892        0f, 0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f,
1893        1f, 1f
1894    };
1895}
1896
Popular Tags