1 19 20 package org.netbeans.core.windows.persistence; 21 22 import java.util.logging.Level ; 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 ; 34 35 import java.awt.*; 36 import java.io.*; 37 import java.util.*; 38 import java.util.List ; 39 import java.util.logging.Logger ; 40 41 46 47 public class WindowManagerParser { 48 49 public static final String INSTANCE_DTD_ID_1_0 50 = "-//NetBeans//DTD Window Manager Properties 1.0//EN"; public static final String INSTANCE_DTD_ID_1_1 52 = "-//NetBeans//DTD Window Manager Properties 1.1//EN"; public static final String INSTANCE_DTD_ID_2_0 54 = "-//NetBeans//DTD Window Manager Properties 2.0//EN"; public static final String INSTANCE_DTD_ID_2_1 56 = "-//NetBeans//DTD Window Manager Properties 2.1//EN"; 58 private static final boolean DEBUG = Debug.isLoggable(WindowManagerParser.class); 59 60 61 private String wmName; 62 63 private PersistenceManager pm; 64 65 private InternalConfig internalConfig; 66 67 private Map<String , ModeParser> modeParserMap = new HashMap<String , ModeParser>(19); 68 69 private Map<String , GroupParser> groupParserMap = new HashMap<String , GroupParser>(19); 70 71 private Set<String > tcRefNameLocalSet = new HashSet<String >(101); 73 74 private static Object SAVING_LOCK = new Object (); 75 76 public WindowManagerParser(PersistenceManager pm, String wmName) { 77 this.pm = pm; 78 this.wmName = wmName; 79 } 80 81 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 93 void save (WindowManagerConfig wmc) throws IOException { 94 synchronized (SAVING_LOCK) { 95 writeProperties(wmc); 96 writeModes(wmc); 97 writeGroups(wmc); 98 } 99 } 100 101 105 void removeMode (String 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 } 114 } 115 116 120 ModeConfig addMode (String 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 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]" + " Cannot get modes folder", exc); 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]" + " Warning: Cannot load mode " + modeName, exc); } 148 return modeConfig; 149 } 150 } 151 152 156 void removeGroup (String 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 168 GroupConfig addGroup (String 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]" + " Warning: GroupParser " + groupName + " exists but it should not."); 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]" + " Cannot get groups folder", exc); return null; 188 } 189 groupParser.setModuleParentFolder(groupsModuleFolder); 190 groupParser.setInModuleFolder(true); 191 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]" + " Warning: Cannot load group " + groupName, exc); } 202 return groupConfig; 203 } 204 } 205 206 211 public boolean removeTCRef (String 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 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()); modeParser.removeTCRef(tcRefName); 223 if (DEBUG) Debug.log(WindowManagerParser.class, "removeTCRef LEAVE 2" + " tcRef:" + tcRefName); 224 return true; 225 } 226 } 227 228 232 TCRefConfig addTCRef (String modeName, String tcRefName, List <String > tcRefNameList) { 233 synchronized (SAVING_LOCK) { 234 if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.addTCRef ENTER" + " mo:" + modeName 235 + " tcRef:" + tcRefName); 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]" + " Warning: Cannot add tcRef " + tcRefName + ". ModeParser " + modeName + " not found."); 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); return tcRefConfig; 249 } 250 } 251 252 256 boolean removeTCGroup (String groupName, String tcGroupName) { 257 synchronized (SAVING_LOCK) { 258 if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.removeTCGroup ENTER" + " group:" + groupName 259 + " tcGroup:" + tcGroupName); GroupParser groupParser = (GroupParser) groupParserMap.get(groupName); 261 if (groupParser == null) { 262 if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.removeTCGroup LEAVE 1" + " group:" + groupName 264 + " tcGroup:" + tcGroupName); return false; 266 } 267 groupParser.removeTCGroup(tcGroupName); 268 if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.removeTCGroup LEAVE 2" + " group:" + groupName 269 + " tcGroup:" + tcGroupName); return true; 271 } 272 } 273 274 278 TCGroupConfig addTCGroup (String groupName, String tcGroupName) { 279 synchronized (SAVING_LOCK) { 280 if (DEBUG) Debug.log(WindowManagerParser.class, "WMParser.addTCGroup ENTER" + " group:" + groupName 281 + " tcGroup:" + tcGroupName); 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); PersistenceManager.LOG.log(Level.WARNING, 287 "[WinSys.WindowManagerParser.addTCGroup]" + " Warning: Cannot add tcGroup " + tcGroupName + ". GroupParser " + groupName + " not found."); 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); return tcGroupConfig; 295 } 296 } 297 298 302 public void addTCRefImport (String modeName, String tcRefName, InternalConfig internalCfg) { 303 if (DEBUG) Debug.log(WindowManagerParser.class, "addTCRefImport ENTER" + " mo:" + modeName 304 + " tcRef:" + tcRefName); 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); PersistenceManager.LOG.log(Level.WARNING, 310 "[WinSys.WindowManagerParser.addTCRef]" + " Warning: Cannot add tcRef " + tcRefName + ". ModeParser " + modeName + " not found."); return; 314 } 315 modeParser.addTCRefImport(tcRefName, internalCfg); 316 if (DEBUG) Debug.log(WindowManagerParser.class, "addTCRefImport LEAVE 2" + " mo:" + modeName 317 + " tcRef:" + tcRefName); } 319 320 324 ModeParser findModeParser (String 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 (modesModuleFolder != null) { 356 FileObject [] files = modesModuleFolder.getChildren(); 357 for (int i = 0; i < files.length; i++) { 358 if (!files[i].isFolder() && PersistenceManager.MODE_EXT.equals(files[i].getExt())) { 360 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 tcRefNameLocalSet.clear(); 375 if (modesLocalFolder != null) { 376 FileObject [] files = modesLocalFolder.getChildren(); 377 for (int i = 0; i < files.length; i++) { 378 if (!files[i].isFolder() && PersistenceManager.MODE_EXT.equals(files[i].getExt())) { 380 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 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 tcRefNameLocalSet.add(subFiles[j].getName()); 398 } 399 } 400 } 401 } 402 } 403 404 410 411 List <ModeConfig> modeCfgList = new ArrayList<ModeConfig>(modeParserMap.size()); 414 List <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 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 447 private boolean acceptMode (ModeParser modeParser, ModeConfig config) { 448 InternalConfig cfg = modeParser.getInternalConfig(); 449 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 + "\'"); } 459 if ((curModuleInfo != null) && curModuleInfo.isEnabled()) { 460 return true; 462 } else { 463 return false; 466 } 467 } else { 468 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 485 if (groupsModuleFolder != null) { 486 FileObject [] files; 487 files = groupsModuleFolder.getChildren(); 488 for (int i = 0; i < files.length; i++) { 489 if (!files[i].isFolder() && PersistenceManager.GROUP_EXT.equals(files[i].getExt())) { 491 GroupParser groupParser; 492 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 FileObject [] files = groupsLocalFolder.getChildren(); 509 for (int i = 0; i < files.length; i++) { 510 if (!files[i].isFolder() && PersistenceManager.GROUP_EXT.equals(files[i].getExt())) { 512 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 532 533 List <GroupConfig> groupCfgList = new ArrayList<GroupConfig>(groupParserMap.size()); 536 List <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 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 569 private boolean acceptGroup (GroupParser groupParser, GroupConfig config) { 570 InternalConfig cfg = groupParser.getInternalConfig(); 571 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 + "\'"); 582 } 583 if ((curModuleInfo != null) && curModuleInfo.isEnabled()) { 584 return true; 586 } else { 587 return false; 588 } 589 } else { 590 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 Map<String , ModeConfig> modeConfigMap = new HashMap<String , ModeConfig>(); 606 for (int i = 0; i < wmc.modes.length; i++) { 607 modeConfigMap.put(wmc.modes[i].name, wmc.modes[i]); 608 } 609 List <String > toDelete = new ArrayList<String >(10); 610 for (String 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 modeParserMap.remove(toDelete.get(i)); 619 deleteLocalMode(toDelete.get(i)); 621 } 622 623 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 } 630 } 631 632 FileObject modesLocalFolder = pm.getRootLocalFolder().getFileObject(PersistenceManager.MODES_FOLDER); 633 if ((modesLocalFolder == null) && (modeParserMap.size() > 0)) { 634 modesLocalFolder = pm.getModesLocalFolder(); 635 } 636 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 Map<String , GroupConfig> groupConfigMap = new HashMap<String , GroupConfig>(); 651 for (int i = 0; i < wmc.groups.length; i++) { 653 groupConfigMap.put(wmc.groups[i].name, wmc.groups[i]); 655 } 656 List <String > toDelete = new ArrayList<String >(10); 657 for (String 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 groupParserMap.remove(toDelete.get(i)); 666 deleteLocalGroup(toDelete.get(i)); 668 } 669 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 } 676 } 677 FileObject groupsLocalFolder = pm.getRootLocalFolder().getFileObject(PersistenceManager.GROUPS_FOLDER); 679 if ((groupsLocalFolder == null) && (groupParserMap.size() > 0)) { 680 groupsLocalFolder = pm.getGroupsLocalFolder(); 681 } 682 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 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 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]" + " Cannot get root local folder", exc); 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 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]" + " Cannot get root local folder", exc); 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 getName () { 747 return wmName; 748 } 749 750 void log (String s) { 751 if (DEBUG) { 752 Debug.log(WindowManagerParser.class, s); 753 } 754 } 755 756 private final class PropertyHandler extends DefaultHandler { 757 758 759 private WindowManagerConfig winMgrConfig = null; 760 761 762 private InternalConfig internalConfig = null; 763 764 765 private List <SplitConstraint> itemList = new ArrayList<SplitConstraint>(10); 766 767 768 private List <String > tcIdList = new ArrayList<String >(10); 769 770 771 private final Object RW_LOCK = new Object (); 772 773 public PropertyHandler () { 774 } 775 776 private FileObject getConfigFOInput () throws IOException { 777 FileObject rootFolder; 778 779 rootFolder = pm.getRootLocalFolder(); 780 781 783 FileObject wmConfigFO; 784 wmConfigFO = rootFolder.getFileObject 786 (WindowManagerParser.this.getName(), PersistenceManager.WINDOWMANAGER_EXT); 787 if (wmConfigFO != null) { 788 return wmConfigFO; 790 } else { 791 rootFolder = pm.getRootModuleFolder(); 795 wmConfigFO = rootFolder.getFileObject 796 (WindowManagerParser.this.getName(), PersistenceManager.WINDOWMANAGER_EXT); 797 798 800 return wmConfigFO; 801 } 802 } 803 804 private FileObject getConfigFOOutput () throws IOException { 805 FileObject rootFolder; 806 rootFolder = pm.getRootLocalFolder(); 807 808 810 FileObject wmConfigFO; 811 wmConfigFO = rootFolder.getFileObject 813 (WindowManagerParser.this.getName(), PersistenceManager.WINDOWMANAGER_EXT); 814 if (wmConfigFO != null) { 815 return wmConfigFO; 817 } else { 818 StringBuffer buffer = new StringBuffer (); 819 buffer.append(WindowManagerParser.this.getName()); 820 buffer.append('.'); 821 buffer.append(PersistenceManager.WINDOWMANAGER_EXT); 822 wmConfigFO = FileUtil.createData(rootFolder, buffer.toString()); 823 return wmConfigFO; 825 } 826 } 827 828 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 853 is = cfgFOInput.getInputStream(); 856 PersistenceManager.getDefault().getXMLParser(this).parse(new InputSource(is)); 857 } 859 } catch (SAXException exc) { 860 String 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 [tcIdList.size()]); 880 winMgrCfg = winMgrConfig; 881 internalCfg = internalConfig; 882 883 winMgrConfig = null; 884 internalConfig = null; 885 } 886 887 public void startElement (String nameSpace, String name, String qname, Attributes attrs) throws SAXException { 888 if ("windowmanager".equals(qname)) { handleWindowManager(attrs); 890 } else if (internalConfig.specVersion.compareTo(new SpecificationVersion("2.0")) >= 0) { if ("main-window".equals(qname)) { handleMainWindow(attrs); 894 } else if ("joined-properties".equals(qname)) { handleJoinedProperties(attrs); 896 } else if ("separated-properties".equals(qname)) { handleSeparatedProperties(attrs); 898 } else if ("editor-area".equals(qname)) { handleEditorArea(attrs); 900 } else if ("constraints".equals(qname)) { handleConstraints(attrs); 902 } else if ("path".equals(qname)) { handlePath(attrs); 904 } else if ("bounds".equals(qname)) { handleEditorAreaBounds(attrs); 906 } else if ("relative-bounds".equals(qname)) { handleEditorAreaRelativeBounds(attrs); 908 } else if ("screen".equals(qname)) { handleScreen(attrs); 910 } else if ("active-mode".equals(qname)) { handleActiveMode(attrs); 912 } else if ("maximized-mode".equals(qname)) { handleMaximizedMode(attrs); 914 } else if ("toolbar".equals(qname)) { handleToolbar(attrs); 916 } else if ("tc-id".equals(qname)) { handleTcId(attrs); 918 } else if ("tcref-item".equals(qname)) { handleTCRefItem(attrs); 920 } 921 } else { 922 if (DEBUG) Debug.log(WindowManagerParser.class, "WMP.startElement PARSING OLD"); 923 } 925 } 926 927 public void error(SAXParseException ex) throws SAXException { 928 throw ex; 929 } 930 931 932 private void handleWindowManager (Attributes attrs) { 933 String version = attrs.getValue("version"); if (version != null) { 935 internalConfig.specVersion = new SpecificationVersion(version); 936 } else { 937 PersistenceManager.LOG.log(Level.WARNING, 938 "[WinSys.WindowManagerParser.handleWindowManager]" + " Missing attribute \"version\" of element \"windowmanager\"."); internalConfig.specVersion = new SpecificationVersion("2.0"); } 942 } 943 944 945 private void handleMainWindow (Attributes attrs) { 946 } 947 948 949 private void handleJoinedProperties (Attributes attrs) { 950 String s; 951 try { 952 s = attrs.getValue("x"); if (s != null) { 954 winMgrConfig.xJoined = Integer.parseInt(s); 955 } else { 956 winMgrConfig.xJoined = -1; 957 } 958 } catch (NumberFormatException exc) { 959 960 PersistenceManager.LOG.log(Level.WARNING, 961 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Cannot read attribute \"x\"" + " of element \"joined-properties\".", exc); winMgrConfig.xJoined = -1; 965 } 966 967 try { 968 s = attrs.getValue("y"); if (s != null) { 970 winMgrConfig.yJoined = Integer.parseInt(s); 971 } else { 972 winMgrConfig.yJoined = -1; 973 } 974 } catch (NumberFormatException exc) { 975 976 PersistenceManager.LOG.log(Level.WARNING, 977 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Cannot read attribute \"y\"" + " of element \"joined-properties\".", exc); winMgrConfig.yJoined = -1; 981 } 982 983 try { 984 s = attrs.getValue("width"); if (s != null) { 986 winMgrConfig.widthJoined = Integer.parseInt(s); 987 } else { 988 winMgrConfig.widthJoined = -1; 989 } 990 } catch (NumberFormatException exc) { 991 992 PersistenceManager.LOG.log(Level.WARNING, 993 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Cannot read attribute \"width\"" + " of element \"joined-properties\".", exc); winMgrConfig.widthJoined = -1; 997 } 998 999 try { 1000 s = attrs.getValue("height"); if (s != null) { 1002 winMgrConfig.heightJoined = Integer.parseInt(s); 1003 } else { 1004 winMgrConfig.heightJoined = -1; 1005 } 1006 } catch (NumberFormatException exc) { 1007 1008 PersistenceManager.LOG.log(Level.WARNING, 1009 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Cannot read attribute \"height\"" + " of element \"joined-properties\".", exc); winMgrConfig.heightJoined = -1; 1013 } 1014 1015 try { 1016 s = attrs.getValue("relative-x"); if (s != null) { 1018 winMgrConfig.relativeXJoined = floatParse(s); 1019 } else { 1020 winMgrConfig.relativeXJoined = -1; 1021 } 1022 } catch (NumberFormatException exc) { 1023 1024 PersistenceManager.LOG.log(Level.WARNING, 1025 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Cannot read attribute \"relative-x\"" + " of element \"joined-properties\".", exc); winMgrConfig.relativeXJoined = -1; 1029 } 1030 1031 try { 1032 s = attrs.getValue("relative-y"); 1034 if (s != null) { 1035 winMgrConfig.relativeYJoined = floatParse(s); 1036 } else { 1037 winMgrConfig.relativeYJoined = -1; 1038 } 1039 } catch (NumberFormatException exc) { 1040 1041 PersistenceManager.LOG.log(Level.WARNING, 1042 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Cannot read attribute \"relative-y\"" + " of element \"joined-properties\".", exc); winMgrConfig.relativeYJoined = -1; 1046 } 1047 1048 try { 1049 s = attrs.getValue("relative-width"); if (s != null) { 1051 winMgrConfig.relativeWidthJoined = floatParse(s); 1052 } else { 1053 winMgrConfig.relativeWidthJoined = -1; 1054 } 1055 } catch (NumberFormatException exc) { 1056 1057 PersistenceManager.LOG.log(Level.WARNING, 1058 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Cannot read attribute \"relative-width\"" + " of element \"joined-properties\".", exc); winMgrConfig.relativeWidthJoined = -1; 1062 } 1063 1064 try { 1065 s = attrs.getValue("relative-height"); if (s != null) { 1067 winMgrConfig.relativeHeightJoined = floatParse(s); 1068 } else { 1069 winMgrConfig.relativeHeightJoined = -1; 1070 } 1071 } catch (NumberFormatException exc) { 1072 1073 PersistenceManager.LOG.log(Level.WARNING, 1074 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Cannot read attribute \"relative-height\"" + " of element \"joined-properties\".",exc); winMgrConfig.relativeHeightJoined = -1; 1078 } 1079 1080 s = attrs.getValue("centered-horizontally"); if (s != null) { 1082 if ("true".equals(s)) { winMgrConfig.centeredHorizontallyJoined = true; 1084 } else if ("false".equals(s)) { winMgrConfig.centeredHorizontallyJoined = false; 1086 } else { 1087 PersistenceManager.LOG.log(Level.WARNING, 1088 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Invalid value of attribute \"centered-horizontally\"" + " of element \"joined-properties\"."); winMgrConfig.centeredHorizontallyJoined = false; 1092 } 1093 } else { 1094 winMgrConfig.centeredHorizontallyJoined = false; 1095 } 1096 1097 s = attrs.getValue("centered-vertically"); if (s != null) { 1099 if ("true".equals(s)) { winMgrConfig.centeredVerticallyJoined = true; 1101 } else if ("false".equals(s)) { winMgrConfig.centeredVerticallyJoined = false; 1103 } else { 1104 PersistenceManager.LOG.log(Level.WARNING, 1105 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Invalid value of attribute \"centered-vertically\"" + " of element \"joined-properties\"."); winMgrConfig.centeredVerticallyJoined = false; 1109 } 1110 } else { 1111 winMgrConfig.centeredVerticallyJoined = false; 1112 } 1113 1114 try { 1115 s = attrs.getValue("maximize-if-width-below"); if (s != null) { 1117 winMgrConfig.maximizeIfWidthBelowJoined = Integer.parseInt(s); 1118 } else { 1119 winMgrConfig.maximizeIfWidthBelowJoined = -1; 1120 } 1121 } catch (NumberFormatException exc) { 1122 1123 PersistenceManager.LOG.log(Level.WARNING, 1124 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Cannot read attribute \"maximize-if-width-below\"" + " of element \"joined-properties\".", exc); winMgrConfig.maximizeIfWidthBelowJoined = -1; 1128 } 1129 1130 try { 1131 s = attrs.getValue("maximize-if-height-below"); if (s != null) { 1133 winMgrConfig.maximizeIfHeightBelowJoined = Integer.parseInt(s); 1134 } else { 1135 winMgrConfig.maximizeIfHeightBelowJoined = -1; 1136 } 1137 } catch (NumberFormatException exc) { 1138 1139 PersistenceManager.LOG.log(Level.WARNING, 1140 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Cannot read attribute \"maximize-if-height-below\"" + " of element \"joined-properties\".", exc); 1143 winMgrConfig.maximizeIfHeightBelowJoined = -1; 1144 } 1145 1146 String frameState = attrs.getValue("frame-state"); if (frameState != null) { 1148 try { 1149 winMgrConfig.mainWindowFrameStateJoined = Integer.parseInt(frameState); 1150 } catch (NumberFormatException exc) { 1151 1152 PersistenceManager.LOG.log(Level.WARNING, 1153 "[WinSys.WindowManagerParser.handleJoinedProperties]" + " Warning: Cannot read attribute \"frame-state\"" + " of element \"joined-properties\".", exc); winMgrConfig.mainWindowFrameStateJoined = Frame.NORMAL; 1157 } 1158 } else { 1159 winMgrConfig.mainWindowFrameStateJoined = Frame.NORMAL; 1160 } 1161 } 1162 1163 1164 private void handleSeparatedProperties (Attributes attrs) { 1165 String s; 1166 try { 1167 s = attrs.getValue("x"); if (s != null) { 1169 winMgrConfig.xSeparated = Integer.parseInt(s); 1170 } else { 1171 winMgrConfig.xSeparated = -1; 1172 } 1173 } catch (NumberFormatException exc) { 1174 1175 PersistenceManager.LOG.log(Level.WARNING, 1176 "[WinSys.WindowManagerParser.handleSeparatedProperties]" + " Warning: Cannot read attribute \"x\"" + " of element \"separated-properties\".", exc); winMgrConfig.xSeparated = -1; 1180 } 1181 1182 try { 1183 s = attrs.getValue("y"); if (s != null) { 1185 winMgrConfig.ySeparated = Integer.parseInt(s); 1186 } else { 1187 winMgrConfig.ySeparated = -1; 1188 } 1189 } catch (NumberFormatException exc) { 1190 1191 PersistenceManager.LOG.log(Level.WARNING, 1192 "[WinSys.WindowManagerParser.handleSeparatedProperties]" + " Warning: Cannot read attribute \"y\"" + " of element \"separated-properties\".", exc); winMgrConfig.ySeparated = -1; 1196 } 1197 1198 try { 1199 s = attrs.getValue("width"); if (s != null) { 1201 winMgrConfig.widthSeparated = Integer.parseInt(s); 1202 } else { 1203 winMgrConfig.widthSeparated = -1; 1204 } 1205 } catch (NumberFormatException exc) { 1206 1207 PersistenceManager.LOG.log(Level.WARNING, 1208 "[WinSys.WindowManagerParser.handleSeparatedProperties]" + " Warning: Cannot read attribute \"width\"" + " of element \"separated-properties\".", exc); winMgrConfig.widthSeparated = -1; 1212 } 1213 1214 try { 1215 s = attrs.getValue("height"); if (s != null) { 1217 winMgrConfig.heightSeparated = Integer.parseInt(s); 1218 } else { 1219 winMgrConfig.heightSeparated = -1; 1220 } 1221 } catch (NumberFormatException exc) { 1222 1223 PersistenceManager.LOG.log(Level.WARNING, 1224 "[WinSys.WindowManagerParser.handleSeparatedProperties]" + " Warning: Cannot read attribute \"height\"" + " of element \"separated-properties\".", exc); winMgrConfig.heightSeparated = -1; 1228 } 1229 1230 try { 1231 s = attrs.getValue("relative-x"); if (s != null) { 1233 winMgrConfig.relativeXSeparated = floatParse(s); 1234 } else { 1235 winMgrConfig.relativeXSeparated = -1; 1236 } 1237 } catch (NumberFormatException exc) { 1238 1239 PersistenceManager.LOG.log(Level.WARNING, 1240 "[WinSys.WindowManagerParser.handleSeparatedProperties]" + " Warning: Cannot read attribute \"relative-x\"" + " of element \"separated-properties\".", exc); winMgrConfig.relativeXSeparated = -1; 1244 } 1245 1246 try { 1247 s = attrs.getValue("relative-y"); if (s != null) { 1249 winMgrConfig.relativeYSeparated = floatParse(s); 1250 } else { 1251 winMgrConfig.relativeYSeparated = -1; 1252 } 1253 } catch (NumberFormatException exc) { 1254 1255 PersistenceManager.LOG.log(Level.WARNING, 1256 "[WinSys.WindowManagerParser.handleSeparatedProperties]" + " Warning: Cannot read attribute \"relative-y\"" + " of element \"separated-properties\".", exc); winMgrConfig.relativeYSeparated = -1; 1260 } 1261 1262 try { 1263 s = attrs.getValue("relative-width"); if (s != null) { 1265 winMgrConfig.relativeWidthSeparated = floatParse(s); 1266 } else { 1267 winMgrConfig.relativeWidthSeparated = -1; 1268 } 1269 } catch (NumberFormatException exc) { 1270 1271 PersistenceManager.LOG.log(Level.WARNING, 1272 "[WinSys.WindowManagerParser.handleSeparatedProperties]" + " Warning: Cannot read attribute \"relative-width\"" + " of element \"separated-properties\".", exc); winMgrConfig.relativeWidthSeparated = -1; 1276 } 1277 1278 try { 1279 s = attrs.getValue("relative-height"); if (s != null) { 1281 winMgrConfig.relativeHeightSeparated = floatParse(s); 1282 } else { 1283 winMgrConfig.relativeHeightSeparated = -1; 1284 } 1285 } catch (NumberFormatException exc) { 1286 1287 PersistenceManager.LOG.log(Level.WARNING, 1288 "[WinSys.WindowManagerParser.handleSeparatedProperties]" + " Warning: Cannot read attribute \"relative-height\"" + " of element \"separated-properties\".", exc); winMgrConfig.relativeHeightSeparated = -1; 1292 } 1293 1294 s = attrs.getValue("centered-horizontally"); if (s != null) { 1296 if ("true".equals(s)) { winMgrConfig.centeredHorizontallySeparated = true; 1298 } else if ("false".equals(s)) { winMgrConfig.centeredHorizontallySeparated = false; 1300 } else { 1301 PersistenceManager.LOG.log(Level.WARNING, 1302 "[WinSys.WindowManagerParser.handleSeparatedProperties]" + " Warning: Invalid value of attribute \"centered-horizontally\"" + " of element \"separated-properties\"."); winMgrConfig.centeredHorizontallySeparated = false; 1306 } 1307 } else { 1308 winMgrConfig.centeredHorizontallySeparated = false; 1309 } 1310 1311 s = attrs.getValue("centered-vertically"); if (s != null) { 1313 if ("true".equals(s)) { winMgrConfig.centeredVerticallySeparated = true; 1315 } else if ("false".equals(s)) { winMgrConfig.centeredVerticallySeparated = false; 1317 } else { 1318 PersistenceManager.LOG.log(Level.WARNING, 1319 "[WinSys.WindowManagerParser.handleSeparatedProperties]" + " Warning: Invalid value of attribute \"centered-vertically\"" + " of element \"separated-properties\"."); winMgrConfig.centeredVerticallySeparated = false; 1323 } 1324 } else { 1325 winMgrConfig.centeredVerticallySeparated = false; 1326 } 1327 1328 String frameState = attrs.getValue("frame-state"); if (frameState != null) { 1330 try { 1331 winMgrConfig.mainWindowFrameStateSeparated = Integer.parseInt(frameState); 1332 } catch (NumberFormatException exc) { 1333 1334 PersistenceManager.LOG.log(Level.WARNING, 1335 "[WinSys.WindowManagerParser.handleSeparatedProperties]" + " Warning: Cannot read attribute \"frame-state\"" + " of element \"separated-properties\".", exc); winMgrConfig.mainWindowFrameStateSeparated = Frame.NORMAL; 1339 } 1340 } else { 1341 winMgrConfig.mainWindowFrameStateSeparated = Frame.NORMAL; 1342 } 1343 } 1344 1345 1346 private void handleEditorArea (Attributes attrs) { 1347 String state = attrs.getValue("state"); 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]" + " Warning: Invalid value of attribute \"state\"" + " of element \"editor-area\"."); winMgrConfig.editorAreaState = Constants.EDITOR_AREA_JOINED; 1359 } 1360 } else { 1361 PersistenceManager.LOG.log(Level.WARNING, 1362 "[WinSys.WindowManagerParser.handleEditorArea]" + " Warning: Missing value of attribute \"state\"" + " of element \"editor-area\"."); winMgrConfig.editorAreaState = Constants.EDITOR_AREA_JOINED; 1366 } 1367 String frameState = attrs.getValue("frame-state"); if (frameState != null) { 1369 try { 1370 winMgrConfig.editorAreaFrameState = Integer.parseInt(frameState); 1371 } catch (NumberFormatException exc) { 1372 1373 PersistenceManager.LOG.log(Level.WARNING, 1374 "[WinSys.WindowManagerParser.handleEditorArea]" + " Warning: Cannot read attribute \"frame-state\"" + " of element \"editor-area\".", exc); winMgrConfig.editorAreaFrameState = Frame.NORMAL; 1378 } 1379 } else { 1380 winMgrConfig.editorAreaFrameState = Frame.NORMAL; 1381 } 1382 } 1383 1384 1385 private void handleConstraints (Attributes attrs) { 1386 } 1387 1388 1389 private void handlePath (Attributes attrs) { 1390 String s = attrs.getValue("orientation"); int orientation; 1392 if ("horizontal".equals(s)) { orientation = Constants.HORIZONTAL; 1394 } else if ("vertical".equals(s)) { orientation = Constants.VERTICAL; 1396 } else { 1397 PersistenceManager.LOG.log(Level.WARNING, 1398 "[WinSys.WindowManagerParser.handlePath]" + " Invalid or missing value of attribute \"orientation\"."); orientation = Constants.VERTICAL; 1401 } 1402 1403 int number; 1404 try { 1405 s = attrs.getValue("number"); if (s != null) { 1407 number = Integer.parseInt(s); 1408 } else { 1409 PersistenceManager.LOG.log(Level.WARNING, 1410 "[WinSys.WindowManagerParser.handlePath]" + " Missing value of attribute \"number\"."); number = 0; 1413 } 1414 } catch (NumberFormatException exc) { 1415 1416 PersistenceManager.LOG.log(Level.WARNING, 1417 "[WinSys.WindowManagerParser.handlePath]" + " Cannot read element \"path\", attribute \"number\"", exc); number = 0; 1420 } 1421 1422 double weight; 1423 try { 1424 s = attrs.getValue("weight"); if (s != null) { 1426 weight = Double.parseDouble(s); 1427 } else { 1428 weight = 0.5; 1430 } 1431 } catch (NumberFormatException exc) { 1432 1433 PersistenceManager.LOG.log(Level.WARNING, 1434 "[WinSys.WindowManagerParser.handlePath]" + " Warning: Cannot read element \"path\", attribute \"weight\".", exc); weight = 0.5; 1437 } 1438 SplitConstraint item = new SplitConstraint(orientation, number, weight); 1439 itemList.add(item); 1440 } 1441 1442 1443 private void handleScreen (Attributes attrs) { 1444 try { 1445 String s; 1446 winMgrConfig.screenSize = null; 1447 int width, height; 1448 s = attrs.getValue("width"); if (s != null) { 1450 width = Integer.parseInt(s); 1451 } else { 1452 PersistenceManager.LOG.log(Level.WARNING, 1453 "[WinSys.WindowManagerParser.handleScreen]" + " Warning: Missing attribute \"width\" of element \"screen\"."); return; 1456 } 1457 s = attrs.getValue("height"); if (s != null) { 1459 height = Integer.parseInt(s); 1460 } else { 1461 PersistenceManager.LOG.log(Level.WARNING, 1462 "[WinSys.WindowManagerParser.handleScreen]" + " Warning: Missing attribute \"height\" of element \"screen\"."); return; 1465 } 1466 winMgrConfig.screenSize = new Dimension(width, height); 1467 } catch (NumberFormatException exc) { 1468 1469 PersistenceManager.LOG.log(Level.WARNING, 1470 "[WinSys.WindowManagerParser.handleScreen]" + " Warning: Cannot read element \"screen\".", exc); } 1473 } 1474 1475 1476 private void handleEditorAreaBounds (Attributes attrs) { 1477 try { 1478 String s; 1479 int x, y, width, height; 1480 1481 winMgrConfig.editorAreaBounds = null; 1482 s = attrs.getValue("x"); if (s != null) { 1484 x = Integer.parseInt(s); 1485 } else { 1486 PersistenceManager.LOG.log(Level.WARNING, 1487 "[WinSys.WindowManagerParser.handleEditorAreaBounds]" + " Warning: Missing attribute \"x\" of element \"bounds\"."); return; 1490 } 1491 s = attrs.getValue("y"); if (s != null) { 1493 y = Integer.parseInt(s); 1494 } else { 1495 PersistenceManager.LOG.log(Level.WARNING, 1496 "[WinSys.WindowManagerParser.handleEditorAreaBounds]" + " Warning: Missing attribute \"y\" of element \"bounds\"."); return; 1499 } 1500 s = attrs.getValue("width"); if (s != null) { 1502 width = Integer.parseInt(s); 1503 } else { 1504 PersistenceManager.LOG.log(Level.WARNING, 1505 "[WinSys.WindowManagerParser.handleEditorAreaBounds]" + " Warning: Missing attribute \"width\" of element \"bounds\"."); return; 1508 } 1509 s = attrs.getValue("height"); if (s != null) { 1511 height = Integer.parseInt(s); 1512 } else { 1513 PersistenceManager.LOG.log(Level.WARNING, 1514 "[WinSys.WindowManagerParser.handleEditorAreaBounds]" + " Warning: Missing attribute \"height\" of element \"bounds\"."); return; 1517 } 1518 winMgrConfig.editorAreaBounds = new Rectangle(x, y, width, height); 1519 } catch (NumberFormatException exc) { 1520 PersistenceManager.LOG.log(Level.WARNING, 1521 "[WinSys.WindowManagerParser.handleEditorAreaBounds]" + " Warning: Cannot read element \"bounds\".", exc); } 1524 } 1525 1526 1527 private void handleEditorAreaRelativeBounds (Attributes attrs) { 1528 try { 1529 String s; 1530 int x, y, width, height; 1531 1532 winMgrConfig.editorAreaRelativeBounds = null; 1533 s = attrs.getValue("x"); if (s != null) { 1535 x = Integer.parseInt(s); 1536 } else { 1537 PersistenceManager.LOG.log(Level.WARNING, 1538 "[WinSys.WindowManagerParser.handleEditorAreaRelativeBounds]" + " Warning: Missing attribute \"x\" of element \"relative-bounds\"."); return; 1541 } 1542 s = attrs.getValue("y"); if (s != null) { 1544 y = Integer.parseInt(s); 1545 } else { 1546 PersistenceManager.LOG.log(Level.WARNING, 1547 "[WinSys.WindowManagerParser.handleEditorAreaRelativeBounds]" + " Warning: Missing attribute \"y\" of element \"relative-bounds\"."); return; 1550 } 1551 s = attrs.getValue("width"); if (s != null) { 1553 width = Integer.parseInt(s); 1554 } else { 1555 PersistenceManager.LOG.log(Level.WARNING, 1556 "[WinSys.WindowManagerParser.handleEditorAreaRelativeBounds]" + " Warning: Missing attribute \"width\" of element \"relative-bounds\"."); return; 1559 } 1560 s = attrs.getValue("height"); if (s != null) { 1562 height = Integer.parseInt(s); 1563 } else { 1564 PersistenceManager.LOG.log(Level.WARNING, 1565 "[WinSys.WindowManagerParser.handleEditorAreaRelativeBounds]" + " Warning: Missing attribute \"height\" of element \"relative-bounds\"."); return; 1568 } 1569 winMgrConfig.editorAreaRelativeBounds = new Rectangle(x, y, width, height); 1570 } catch (NumberFormatException exc) { 1571 1572 PersistenceManager.LOG.log(Level.WARNING, 1573 "[WinSys.WindowManagerParser.handleEditorAreaRelativeBounds]" + " Warning: Cannot read element \"relative-bounds\".", exc); } 1576 } 1577 1578 1579 private void handleActiveMode (Attributes attrs) { 1580 String name = attrs.getValue("name"); if (name != null) { 1582 winMgrConfig.activeModeName = name; 1583 } else { 1584 winMgrConfig.activeModeName = ""; } 1586 } 1587 1588 1589 private void handleMaximizedMode (Attributes attrs) { 1590 String name = attrs.getValue("editor"); if (name != null) { 1592 winMgrConfig.editorMaximizedModeName = name; 1593 } else { 1594 winMgrConfig.editorMaximizedModeName = ""; } 1596 1597 name = attrs.getValue("view"); if (name != null) { 1599 winMgrConfig.viewMaximizedModeName = name; 1600 } else { 1601 winMgrConfig.viewMaximizedModeName = ""; } 1603 } 1604 1605 1606 private void handleToolbar (Attributes attrs) { 1607 String configuration = attrs.getValue("configuration"); if (configuration != null) { 1609 winMgrConfig.toolbarConfiguration = configuration; 1610 } else { 1611 winMgrConfig.toolbarConfiguration = ""; } 1613 String prefIconSize = attrs.getValue("preferred-icon-size"); 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]" + " Warning: Invalid value of attribute \"preferred-icon-size\"" + " of element \"toolbar\": " + winMgrConfig.preferredToolbarIconSize + ". Fixed to default value 24."); winMgrConfig.preferredToolbarIconSize = 24; 1626 } 1627 } catch (NumberFormatException exc) { 1628 1629 PersistenceManager.LOG.log(Level.WARNING, 1630 "[WinSys.WindowManagerParser.handleToolbar]" + " Warning: Cannot read attribute \"preferred-icon-size\"" + " of element \"toolbar\"." + " Fixed to default value 24.", exc); winMgrConfig.preferredToolbarIconSize = 24; 1635 } 1636 } else { 1637 winMgrConfig.preferredToolbarIconSize = 24; 1638 } 1639 } 1640 1641 1642 private void handleTcId (Attributes attrs) { 1643 String id = attrs.getValue("id"); if (id != null) { 1645 if (!"".equals(id)) { 1646 tcIdList.add(id); 1647 } else { 1648 PersistenceManager.LOG.log(Level.WARNING, 1649 "[WinSys.WindowManagerParser.handleTcId]" + " Warning: Empty required attribute \"id\" of element \"tc-id\"."); } 1652 } else { 1653 PersistenceManager.LOG.log(Level.WARNING, 1654 "[WinSys.WindowManagerParser.handleTcId]" + " Warning: Missing required attribute \"id\" of element \"tc-id\"."); } 1657 } 1658 1659 1660 private void handleTCRefItem (Attributes attrs) { 1661 String workspaceName = attrs.getValue("workspace"); String modeName = attrs.getValue("mode"); String tc_id = attrs.getValue("id"); 1665 if (workspaceName != null) { 1666 if ("".equals(workspaceName)) { 1667 PersistenceManager.LOG.log(Level.WARNING, 1668 "[WinSys.WindowManagerParser.handleTCRefItem]" + " Warning: Empty required attribute \"workspace\" of element \"tcref-item\"."); return; 1671 } 1672 } else { 1673 PersistenceManager.LOG.log(Level.WARNING, 1674 "[WinSys.WindowManagerParser.handleTCRefItem]" + " Warning: Missing required attribute \"workspace\" of element \"tcref-item\"."); return; 1677 } 1678 if (modeName != null) { 1679 if ("".equals(modeName)) { 1680 PersistenceManager.LOG.log(Level.WARNING, 1681 "[WinSys.WindowManagerParser.handleTCRefItem]" + " Warning: Empty required attribute \"mode\" of element \"tcref-item\"."); return; 1684 } 1685 } else { 1686 PersistenceManager.LOG.log(Level.WARNING, 1687 "[WinSys.WindowManagerParser.handleTCRefItem]" + " Warning: Missing required attribute \"mode\" of element \"tcref-item\"."); return; 1690 } 1691 if (tc_id != null) { 1692 if ("".equals(tc_id)) { 1693 PersistenceManager.LOG.log(Level.WARNING, 1694 "[WinSys.WindowManagerParser.handleTCRefItem]" + " Warning: Empty required attribute \"id\" of element \"tcref-item\"."); return; 1697 } 1698 } else { 1699 PersistenceManager.LOG.log(Level.WARNING, 1700 "[WinSys.WindowManagerParser.handleTCRefItem]" + " Warning: Missing required attribute \"id\" of element \"tcref-item\"."); return; 1703 } 1704 } 1705 1706 1707 void writeData (WindowManagerConfig wmc) throws IOException { 1708 final StringBuffer 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"); osw.write(buff.toString()); 1719 } 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 1738 private StringBuffer fillBuffer (WindowManagerConfig wmc) throws IOException { 1739 StringBuffer buff = new StringBuffer (800); 1740 String curValue = null; 1741 buff.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"). 1746 append("<windowmanager version=\"2.1\">\n"); 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"); return buff; 1758 } 1759 1760 1761 private void appendMainWindow (WindowManagerConfig wmc, StringBuffer buff) { 1762 buff.append(" <main-window>\n <joined-properties\n"). append(" x=\"").append(wmc.xJoined).append("\"\n"). append(" y=\"").append(wmc.yJoined).append("\"\n"). append(" width=\"").append(wmc.widthJoined).append("\"\n"). append(" height=\"").append(wmc.heightJoined).append("\"\n"). append(" relative-x=\"").append(wmc.relativeXJoined).append("\"\n"). append(" relative-y=\"").append(wmc.relativeYJoined).append("\"\n"). append(" relative-width=\"").append(wmc.relativeWidthJoined).append("\"\n"). append(" relative-height=\"").append(wmc.relativeHeightJoined).append("\"\n"). append(" centered-horizontally=\"").append(wmc.centeredHorizontallyJoined).append("\"\n"). append(" centered-vertically=\"").append(wmc.centeredVerticallyJoined).append("\"\n"). append(" maximize-if-width-below=\"").append(wmc.maximizeIfWidthBelowJoined).append("\"\n"). append(" maximize-if-height-below=\"").append(wmc.maximizeIfHeightBelowJoined).append("\"\n"). append(" frame-state=\"").append(wmc.mainWindowFrameStateJoined).append("\"\n/>\n"). 1777 append(" <separated-properties\n"). append(" x=\"").append(wmc.xSeparated).append("\"\n"). append(" y=\"").append(wmc.ySeparated).append("\"\n"). append(" width=\"").append(wmc.widthSeparated).append("\"\n"). append(" height=\"").append(wmc.heightSeparated).append("\"\n"). append(" relative-x=\"").append(wmc.relativeXSeparated).append("\"\n"). append(" relative-y=\"").append(wmc.relativeYSeparated).append("\"\n"). append(" relative-width=\"").append(wmc.relativeWidthSeparated).append("\"\n"). append(" relative-height=\"").append(wmc.relativeHeightSeparated).append("\"\n"). append(" centered-horizontally=\"").append(wmc.centeredHorizontallySeparated).append("\"\n"). append(" centered-vertically=\"").append(wmc.centeredVerticallySeparated).append("\"\n"). append(" frame-state=\"").append(wmc.mainWindowFrameStateSeparated).append("\"\n"). append("/>\n </main-window>\n"); } 1792 1793 private void appendEditorArea (WindowManagerConfig wmc, StringBuffer buff) { 1794 buff.append(" <editor-area state=\""); if (wmc.editorAreaState == Constants.EDITOR_AREA_JOINED) { 1796 buff.append("joined"); } else { 1798 buff.append("separated"); } 1800 buff.append("\" frame-state=\"").append(wmc.editorAreaFrameState).append("\">\n"); 1802 buff.append(" <constraints>\n"); for (int i = 0; i < wmc.editorAreaConstraints.length; i++) { 1805 SplitConstraint item = wmc.editorAreaConstraints[i]; 1806 buff.append(" <path orientation=\""); if (item.orientation == Constants.HORIZONTAL) { 1808 buff.append("horizontal"); } else { 1810 buff.append("vertical"); } 1812 buff.append("\" number=\"").append(item.index).append("\" weight=\"").append(item.splitWeight).append("\" />\n"); } 1814 buff.append(" </constraints>\n"); 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=\""); buff.append(wmc.editorAreaBounds.height).append("\" />\n"); } 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"); } 1828 buff.append(" </editor-area>\n"); } 1831 1832 private void appendScreen (WindowManagerConfig wmc, StringBuffer buff) { 1833 buff.append(" <screen width=\"").append(wmc.screenSize.width). append("\" height=\"").append(wmc.screenSize.height).append("\"/>\n"); } 1836 1837 private void appendActiveMode (WindowManagerConfig wmc, StringBuffer buff) { 1838 if ((wmc.activeModeName != null) && !"".equals(wmc.activeModeName)) { 1839 buff.append(" <active-mode name=\"").append(wmc.activeModeName).append("\"/>\n"); } 1841 } 1842 1843 private void appendMaximizedMode (WindowManagerConfig wmc, StringBuffer 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("\""); if (wmc.viewMaximizedModeName != null && !"".equals(wmc.viewMaximizedModeName)) 1850 buff.append( " view=\"").append(wmc.viewMaximizedModeName).append("\""); buff.append("/>\n"); } 1853 } 1854 1855 private void appendToolbar (WindowManagerConfig wmc, StringBuffer buff) { 1856 buff.append(" <toolbar"); if ((wmc.toolbarConfiguration != null) && !"".equals(wmc.toolbarConfiguration)) { buff.append(" configuration=\"").append(wmc.toolbarConfiguration).append("\""); } 1860 buff.append(" preferred-icon-size=\"").append(wmc.preferredToolbarIconSize).append("\"/>\n"); } 1862 1863 private void appendRecentViewList (WindowManagerConfig wmc, StringBuffer buff) { 1864 if (wmc.tcIdViewList.length == 0) { 1865 return; 1866 } 1867 buff.append(" <tc-list>\n"); for (int i = 0; i < wmc.tcIdViewList.length; i++) { 1869 buff.append(" <tc-id id=\"").append(wmc.tcIdViewList[i]).append("\"/>\n"); } 1871 buff.append(" </tc-list>\n"); } 1873 1874 } 1875 1876 1878 private static final float floatParse (String s) throws NumberFormatException { 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 [] floatStrings = new String [] { 1887 "0", "0.0", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9","1","1.0" }; 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 |