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.openide.util.TopologicalSortException; 33 import org.openide.util.Utilities; 34 import org.xml.sax.*; 35 import org.xml.sax.helpers.DefaultHandler ; 36 37 import java.awt.*; 38 import java.io.*; 39 import java.util.*; 40 import java.util.List ; 41 import java.util.logging.Logger ; 42 43 44 49 50 class ModeParser { 51 52 public static final String INSTANCE_DTD_ID_1_0 53 = "-//NetBeans//DTD Mode Properties 1.0//EN"; public static final String INSTANCE_DTD_ID_1_1 55 = "-//NetBeans//DTD Mode Properties 1.1//EN"; public static final String INSTANCE_DTD_ID_1_2 57 = "-//NetBeans//DTD Mode Properties 1.2//EN"; public static final String INSTANCE_DTD_ID_2_0 59 = "-//NetBeans//DTD Mode Properties 2.0//EN"; public static final String INSTANCE_DTD_ID_2_1 61 = "-//NetBeans//DTD Mode Properties 2.1//EN"; public static final String INSTANCE_DTD_ID_2_2 63 = "-//NetBeans//DTD Mode Properties 2.2//EN"; public static final String INSTANCE_DTD_ID_2_3 65 = "-//NetBeans//DTD Mode Properties 2.3//EN"; 67 68 private static final String EA_ORDER = "WinSys-TCRef-Order"; 70 72 private static final char SEP = '/'; 73 74 private static final boolean DEBUG = Debug.isLoggable(ModeParser.class); 75 76 77 private FileObject moduleParentFolder; 78 79 80 private FileObject localParentFolder; 81 82 private InternalConfig internalConfig; 83 84 85 private Map<String , TCRefParser> tcRefParserMap = new HashMap<String , TCRefParser>(19); 86 87 88 private Map<String ,Integer > tcRefOrder; 89 90 91 private String modeName; 92 93 94 private boolean inModuleFolder; 95 96 private boolean inLocalFolder; 97 98 99 private Set maskSet; 100 101 public ModeParser (String name, Set maskSet) { 102 this.modeName = name; 103 this.maskSet = maskSet; 104 } 105 106 107 ModeConfig load () throws IOException { 108 ModeConfig mc = new ModeConfig(); 110 readProperties(mc); 111 if (mc.kind == Constants.MODE_KIND_SLIDING && mc.side != null && !mc.permanent) { 112 mc.permanent = true; 115 } 125 readTCRefs(mc); 126 return mc; 128 } 129 130 131 void save (ModeConfig mc) throws IOException { 132 writeProperties(mc); 134 writeTCRefs(mc); 135 } 137 138 private void readProperties (ModeConfig mc) throws IOException { 139 if (DEBUG) Debug.log(ModeParser.class, "readProperties ENTER" + " mo:" + getName()); 140 PropertyHandler propertyHandler = new PropertyHandler(); 141 InternalConfig internalCfg = getInternalConfig(); 142 internalCfg.clear(); 143 propertyHandler.readData(mc, internalCfg); 144 145 149 150 if (DEBUG) Debug.log(ModeParser.class, "readProperties LEAVE" + " mo:" + getName()); 151 } 152 153 private void readTCRefs (ModeConfig mc) throws IOException { 154 if (DEBUG) Debug.log(ModeParser.class, "readTCRefs ENTER" + " mo:" + getName()); 155 156 for (Iterator it = tcRefParserMap.keySet().iterator(); it.hasNext(); ) { 157 TCRefParser tcRefParser = tcRefParserMap.get(it.next()); 158 tcRefParser.setInModuleFolder(false); 159 tcRefParser.setInLocalFolder(false); 160 } 161 162 167 if (isInModuleFolder()) { 168 FileObject moduleModeFolder = moduleParentFolder.getFileObject(modeName); 169 if (moduleModeFolder != null) { 170 FileObject [] files = moduleModeFolder.getChildren(); 171 for (int i = 0; i < files.length; i++) { 172 if (!files[i].isFolder() && PersistenceManager.TCREF_EXT.equals(files[i].getExt())) { 174 TCRefParser tcRefParser; 176 if (tcRefParserMap.containsKey(files[i].getName())) { 177 tcRefParser = tcRefParserMap.get(files[i].getName()); 178 } else { 179 tcRefParser = new TCRefParser(files[i].getName()); 180 tcRefParserMap.put(files[i].getName(), tcRefParser); 181 } 182 tcRefParser.setInModuleFolder(true); 183 tcRefParser.setModuleParentFolder(moduleModeFolder); 184 } 185 } 186 } 187 } 188 189 if (isInLocalFolder()) { 190 FileObject localModeFolder = localParentFolder.getFileObject(modeName); 191 if (localModeFolder != null) { 192 FileObject [] files = localModeFolder.getChildren(); 193 for (int i = 0; i < files.length; i++) { 194 if (!files[i].isFolder() && PersistenceManager.TCREF_EXT.equals(files[i].getExt())) { 196 TCRefParser tcRefParser = tcRefParserMap.get(files[i].getName()); 198 if (tcRefParser== null) { 199 tcRefParser = new TCRefParser(files[i].getName()); 200 tcRefParserMap.put(files[i].getName(), tcRefParser); 201 } 202 tcRefParser.setInLocalFolder(true); 203 tcRefParser.setLocalParentFolder(localModeFolder); 204 } 205 } 206 } 207 } 208 209 215 216 readOrder(); 218 219 List <TCRefParser> localList = new ArrayList<TCRefParser>(10); 220 Map<String , TCRefParser> localMap = new HashMap<String , TCRefParser>( tcRefParserMap ); 221 222 if (tcRefOrder != null) { 223 TCRefParser [] tcRefParserArray = new TCRefParser[tcRefOrder.size()]; 227 for (Iterator it = tcRefOrder.entrySet().iterator(); it.hasNext(); ) { 228 Map.Entry en = (Map.Entry) it.next(); 229 String tcRefName = (String ) en.getKey(); 230 int index = ((Integer ) en.getValue()).intValue(); 231 TCRefParser tcRefParser = (TCRefParser) localMap.remove(tcRefName); 232 tcRefParserArray[index] = tcRefParser; 236 } 237 for (int i = 0; i < tcRefParserArray.length; i++) { 238 if (tcRefParserArray[i] != null) { 239 localList.add(tcRefParserArray[i]); 240 } 241 } 242 for (String s: localMap.keySet()) { 244 TCRefParser tcRefParser = localMap.get(s); 245 localList.add(tcRefParser); 246 } 247 } else { 248 for (String s: localMap.keySet()) { 250 TCRefParser tcRefParser = localMap.get(s); 251 localList.add(tcRefParser); 252 } 253 254 259 260 localList = carefullySort(localList); 262 263 268 269 if (tcRefOrder == null) { 270 tcRefOrder = new HashMap<String ,Integer >(19); 271 } 272 tcRefOrder.clear(); 273 for (int i = 0; i < localList.size(); i++) { 274 TCRefParser tcRefParser = localList.get(i); 275 tcRefOrder.put(tcRefParser.getName(), Integer.valueOf(i)); 276 } 277 writeOrder(); 278 } 279 280 List <TCRefConfig> tcRefCfgList = new ArrayList<TCRefConfig>(localList.size()); 283 List <TCRefParser> toRemove = new ArrayList<TCRefParser>(localList.size()); 284 for (int i = 0; i < localList.size(); i++) { 285 TCRefParser tcRefParser = localList.get(i); 286 if (maskSet.contains(tcRefParser.getName())) { 291 if (tcRefParser.isInModuleFolder() && !tcRefParser.isInLocalFolder()) { 292 toRemove.add(tcRefParser); 293 continue; 294 } 295 } 296 TCRefConfig tcRefCfg; 297 try { 298 tcRefCfg = tcRefParser.load(); 299 } catch (IOException exc) { 300 Logger.getLogger(ModeParser.class.getName()).log(Level.WARNING, null, exc); 303 continue; 304 } 305 boolean tcRefAccepted = acceptTCRef(tcRefParser, tcRefCfg); 306 if (tcRefAccepted) { 307 tcRefCfgList.add(tcRefCfg); 308 } else { 309 toRemove.add(tcRefParser); 310 deleteLocalTCRef(tcRefParser.getName()); 311 } 312 } 313 314 for (int i = 0; i < toRemove.size(); i++) { 315 TCRefParser tcRefParser = toRemove.get(i); 316 localList.remove(tcRefParser); 317 tcRefParserMap.remove(tcRefParser.getName()); 318 } 319 320 if (toRemove.size() > 0) { 322 if (tcRefOrder == null) { 323 tcRefOrder = new HashMap<String ,Integer >(19); 324 } 325 tcRefOrder.clear(); 326 for (int i = 0; i < localList.size(); i++) { 327 TCRefParser tcRefParser = (TCRefParser) localList.get(i); 328 tcRefOrder.put(tcRefParser.getName(), Integer.valueOf(i)); 329 } 330 writeOrder(); 331 } 332 333 mc.tcRefConfigs = 334 tcRefCfgList.toArray(new TCRefConfig[tcRefCfgList.size()]); 335 336 PersistenceManager pm = PersistenceManager.getDefault(); 337 for (int i = 0; i < mc.tcRefConfigs.length; i++) { 338 pm.addUsedTCId(mc.tcRefConfigs[i].tc_id); 339 } 340 341 if (DEBUG) Debug.log(ModeParser.class, "readTCRefs LEAVE" + " mo:" + getName()); 342 } 343 344 347 private boolean acceptTCRef (TCRefParser tcRefParser, TCRefConfig config) { 348 InternalConfig cfg = tcRefParser.getInternalConfig(); 349 if (cfg.moduleCodeNameBase != null) { 351 ModuleInfo curModuleInfo = PersistenceManager.findModule 352 (cfg.moduleCodeNameBase, cfg.moduleCodeNameRelease, 353 cfg.moduleSpecificationVersion); 354 if (curModuleInfo == null) { 355 PersistenceManager.LOG.fine("Cannot find module \'" + 356 cfg.moduleCodeNameBase + " " + cfg.moduleCodeNameRelease + " " + 357 cfg.moduleSpecificationVersion + "\' for tcref with id \'" + config.tc_id + "\'"); 359 } 360 return (curModuleInfo != null) && curModuleInfo.isEnabled(); 361 } else { 362 return true; 364 } 365 } 366 367 private void writeProperties (ModeConfig mc) throws IOException { 368 if (DEBUG) Debug.log(ModeParser.class, "writeProperties ENTER" + " mo:" + getName()); 369 PropertyHandler propertyHandler = new PropertyHandler(); 370 InternalConfig internalCfg = getInternalConfig(); 371 propertyHandler.writeData(mc, internalCfg); 372 if (DEBUG) Debug.log(ModeParser.class, "writeProperties LEAVE" + " mo:" + getName()); 373 } 374 375 private void writeTCRefs (ModeConfig mc) throws IOException { 376 if (DEBUG) Debug.log(ModeParser.class, "writeTCRefs ENTER" + " mo:" + getName()); 377 if (mc.tcRefConfigs.length > 0) { 379 if (tcRefOrder == null) { 380 tcRefOrder = new HashMap<String ,Integer >(19); 381 } 382 tcRefOrder.clear(); 383 for (int i = 0; i < mc.tcRefConfigs.length; i++) { 384 tcRefOrder.put(mc.tcRefConfigs[i].tc_id, Integer.valueOf(i)); 385 } 386 } else { 387 tcRefOrder = null; 388 } 389 writeOrder(); 390 Map<String , TCRefConfig> tcRefConfigMap = new HashMap<String , TCRefConfig>(19); 392 for (int i = 0; i < mc.tcRefConfigs.length; i++) { 393 tcRefConfigMap.put(mc.tcRefConfigs[i].tc_id, mc.tcRefConfigs[i]); 395 } 396 TCRefParser tcRefParser; 397 List <String > toDelete = new ArrayList<String >(10); 398 for (String s: tcRefParserMap.keySet()) { 399 tcRefParser = tcRefParserMap.get(s); 400 if (!tcRefConfigMap.containsKey(tcRefParser.getName())) { 401 toDelete.add(tcRefParser.getName()); 402 } 403 } 404 for (int i = 0; i < toDelete.size(); i++) { 405 tcRefParserMap.remove(toDelete.get(i)); 407 deleteLocalTCRef(toDelete.get(i)); 409 } 410 411 for (int i = 0; i < mc.tcRefConfigs.length; i++) { 414 if (!tcRefParserMap.containsKey(mc.tcRefConfigs[i].tc_id)) { 416 tcRefParser = new TCRefParser(mc.tcRefConfigs[i].tc_id); 417 tcRefParserMap.put(mc.tcRefConfigs[i].tc_id, tcRefParser); 419 } 420 } 421 422 FileObject localFolder = localParentFolder.getFileObject(getName()); 424 if ((localFolder == null) && (tcRefParserMap.size() > 0)) { 425 localFolder = FileUtil.createFolder(localParentFolder, getName()); 428 } 429 431 for (Iterator it = tcRefParserMap.keySet().iterator(); it.hasNext(); ) { 432 tcRefParser = tcRefParserMap.get(it.next()); 433 tcRefParser.setLocalParentFolder(localFolder); 434 tcRefParser.setInLocalFolder(true); 435 tcRefParser.save((TCRefConfig) tcRefConfigMap.get(tcRefParser.getName())); 436 } 437 438 if (DEBUG) Debug.log(ModeParser.class, "writeTCRefs LEAVE" + " mo:" + getName()); 439 } 440 441 private void deleteLocalTCRef (String tcRefName) { 442 if (DEBUG) Debug.log(ModeParser.class, "deleteLocalTCRef" + " tcRefName:" + tcRefName); 443 if (localParentFolder == null) { 444 return; 445 } 446 FileObject localModeFolder = localParentFolder.getFileObject(modeName); 447 if (localModeFolder == null) { 448 return; 449 } 450 FileObject tcRefFO = localModeFolder.getFileObject(tcRefName, PersistenceManager.TCREF_EXT); 451 if (tcRefFO != null) { 452 PersistenceManager.deleteOneFO(tcRefFO); 453 } 454 } 455 456 463 465 private void readOrder () { 466 if (localParentFolder == null) { 467 try { 468 localParentFolder = PersistenceManager.getDefault().getModesLocalFolder(); 469 } 470 catch (IOException ex) { 471 Logger.getLogger(ModeParser.class.getName()).log( 472 Level.WARNING, "Cannot get access to lcoal modes folder", ex); return; 474 } 475 } 476 FileObject localModeFolder = localParentFolder.getFileObject(modeName); 477 if (localModeFolder == null) { 478 tcRefOrder = null; 479 return; 480 } 481 Object o = localModeFolder.getAttribute(EA_ORDER); 482 483 if (o == null) { 484 tcRefOrder = null; 485 return; 486 } else if (o instanceof String ) { 487 String sepNames = (String ) o; 488 Map<String ,Integer > map = new HashMap<String ,Integer >(19); 489 StringTokenizer tok = new StringTokenizer(sepNames, "/"); int i = 0; 491 while (tok.hasMoreTokens()) { 492 String tcRefName = tok.nextToken(); 493 map.put(tcRefName, Integer.valueOf(i)); 494 i++; 495 } 496 tcRefOrder = map; 497 return; 498 } else { 499 tcRefOrder = null; 501 return; 502 } 503 } 504 505 507 private void writeOrder () throws IOException { 508 if (localParentFolder == null) { 510 localParentFolder = PersistenceManager.getDefault().getModesLocalFolder(); 511 } 512 513 FileObject localModeFolder = localParentFolder.getFileObject(modeName); 514 if (localModeFolder == null) { 515 localModeFolder = FileUtil.createFolder(localParentFolder, modeName); 517 } 518 if (tcRefOrder == null) { 519 localModeFolder.setAttribute(EA_ORDER, null); 521 } else { 522 String [] tcRefNames = new String [tcRefOrder.size()]; 524 for (Map.Entry<String , Integer > en: tcRefOrder.entrySet()) { 525 String tcRefName = en.getKey(); 526 int index = en.getValue().intValue(); 527 tcRefNames[index] = tcRefName; 528 } 529 StringBuilder buf = new StringBuilder (255); 530 for (int i = 0; i < tcRefNames.length; i++) { 531 if (i > 0) { 532 buf.append(SEP); 533 } 534 buf.append(tcRefNames[i]); 535 } 536 localModeFolder.setAttribute(EA_ORDER, buf.toString ()); 538 } 539 } 540 541 545 private Set<String > readPartials () { 546 Set<String > s = new HashSet<String >(19); 549 550 if (moduleParentFolder == null) { 552 return s; 553 } 554 FileObject moduleModeFolder = moduleParentFolder.getFileObject(modeName); 555 if (moduleModeFolder == null) { 556 return s; 558 } 559 560 Enumeration e = moduleModeFolder.getAttributes(); 561 while (e.hasMoreElements()) { 562 String name = (String ) e.nextElement(); 563 if (name.indexOf(SEP) != -1) { 564 Object value = moduleModeFolder.getAttribute(name); 565 if ((value instanceof Boolean ) && ((Boolean ) value).booleanValue()) { 566 int ind = name.indexOf(SEP); 567 String name1 = name.substring(0, ind); 569 String name2 = name.substring(ind + 1); 570 int indExt = name1.indexOf('.'); 572 if (indExt != -1) { 573 name1 = name1.substring(0, indExt); 574 } 575 indExt = name2.indexOf('.'); 576 if (indExt != -1) { 577 name2 = name2.substring(0, indExt); 578 } 579 name = name1 + SEP + name2; 581 s.add(name); 582 } 584 } 585 } 586 return s; 589 } 590 591 597 private Map<TCRefParser,List <TCRefParser>> getOrderingConstraints (List <TCRefParser> tcRefParsers) { 598 final Set<String > partials = readPartials(); 600 if (partials.isEmpty()) { 601 return null; 603 } else { 604 if (tcRefOrder != null) { 606 Iterator it = partials.iterator(); 608 while (it.hasNext()) { 609 String constraint = (String ) it.next(); 610 int idx = constraint.indexOf(SEP); 612 String a = constraint.substring(0, idx); 613 String b = constraint.substring(idx + 1); 614 if (tcRefOrder.containsKey(a) && tcRefOrder.containsKey(b)) { 616 it.remove(); 618 } 621 } 622 } 623 Map<String , TCRefParser> objectsByName = new HashMap<String , TCRefParser>(19); 624 for (int i = 0; i < tcRefParsers.size(); i++) { 625 TCRefParser tcRefParser = tcRefParsers.get(i); 626 objectsByName.put(tcRefParser.getName(), tcRefParser); 627 } 628 Map<TCRefParser,List <TCRefParser>> m = new HashMap<TCRefParser,List <TCRefParser>>(19); 629 for (String constraint: partials) { 630 int idx = constraint.indexOf(SEP); 631 String a = constraint.substring(0, idx); 632 String b = constraint.substring(idx + 1); 633 if ((tcRefOrder != null) && (tcRefOrder.containsKey(a) && tcRefOrder.containsKey(b))) { 634 continue; 635 } 636 TCRefParser ad = objectsByName.get(a); 637 if (ad == null) { 638 continue; 639 } 640 TCRefParser bd = objectsByName.get(b); 641 if (bd == null) { 642 continue; 643 } 644 List <TCRefParser> l = m.get(ad); 645 if (l == null) { 646 m.put(ad, l = new LinkedList<TCRefParser>()); 647 } 648 l.add(bd); 649 } 650 return m; 652 } 653 } 654 655 661 private List <TCRefParser> carefullySort (List <TCRefParser> l) { 662 Map<TCRefParser, List <TCRefParser>> constraints = getOrderingConstraints(l); 663 if (constraints == null) { 664 return l; 665 } else { 666 try { 667 return Utilities.topologicalSort(l, constraints); 668 } catch (TopologicalSortException ex) { 669 @SuppressWarnings ("unchecked") 670 List <TCRefParser> corrected = ex.partialSort(); 671 PersistenceManager.LOG.log(Level.WARNING,"Note: Mode " + getName() + " cannot be consistently sorted due to ordering conflicts.", ex); PersistenceManager.LOG.log(Level.WARNING,"Using partial sort: " + corrected); return corrected; 675 } 676 } 677 } 678 682 685 void removeTCRef (String tcRefName) { 686 if (DEBUG) Debug.log(ModeParser.class, "removeTCRef ENTER" + " tcRef:" + tcRefName); 687 List <TCRefParser> localList = new ArrayList<TCRefParser>(10); 689 Map localMap = (Map) ((HashMap) tcRefParserMap).clone(); 690 691 tcRefParserMap.remove(tcRefName); 692 693 TCRefParser [] tcRefParserArray = new TCRefParser[tcRefOrder.size()]; 694 for (Iterator it = tcRefOrder.entrySet().iterator(); it.hasNext(); ) { 695 Map.Entry en = (Map.Entry) it.next(); 696 String name = (String ) en.getKey(); 697 int index = ((Integer ) en.getValue()).intValue(); 698 TCRefParser tcRefParser = (TCRefParser) localMap.remove(name); 699 tcRefParserArray[index] = tcRefParser; 703 } 704 for (int i = 0; i < tcRefParserArray.length; i++) { 705 localList.add(tcRefParserArray[i]); 706 } 707 for (Iterator it = localMap.keySet().iterator(); it.hasNext(); ) { 709 TCRefParser tcRefParser = (TCRefParser) localMap.get(it.next()); 710 localList.add(tcRefParser); 711 } 712 713 for (int i = 0; i < localList.size(); i++) { 715 TCRefParser tcRefParser = localList.get(i); 716 if (tcRefName.equals(tcRefParser.getName())) { 717 localList.remove(i); 718 break; 719 } 720 } 721 722 tcRefOrder.clear(); 724 for (int i = 0; i < localList.size(); i++) { 725 TCRefParser tcRefParser = localList.get(i); 726 tcRefOrder.put(tcRefParser.getName(), Integer.valueOf(i)); 727 } 728 try { 729 writeOrder(); 730 } catch (IOException exc) { 731 PersistenceManager.LOG.log(Level.WARNING, 732 "[WinSys.ModeParser.removeTCRef]" + " Warning: Cannot write order of mode: " + getName(), exc); } 735 736 deleteLocalTCRef(tcRefName); 737 if (DEBUG) Debug.log(ModeParser.class, "removeTCRef LEAVE" + " tcRef:" + tcRefName); 738 } 739 740 743 TCRefConfig addTCRef (String tcRefName, List <String > tcRefNameList) { 744 if (DEBUG) Debug.log(ModeParser.class, "addTCRef ENTER" + " mo:" + getName() 745 + " tcRef:" + tcRefName); 746 TCRefParser tcRefParser = tcRefParserMap.get(tcRefName); 748 if (tcRefParser != null) { 749 PersistenceManager.LOG.log(Level.WARNING, 750 "[WinSys.ModeParser.addTCRef]" + " Warning: ModeParser " + getName() + ". TCRefParser " + tcRefName + " exists but it should not."); tcRefParserMap.remove(tcRefName); 754 } 755 tcRefParser = new TCRefParser(tcRefName); 756 FileObject moduleFolder = moduleParentFolder.getFileObject(modeName); 757 tcRefParser.setModuleParentFolder(moduleFolder); 758 tcRefParser.setInModuleFolder(true); 759 tcRefParserMap.put(tcRefName, tcRefParser); 760 TCRefConfig tcRefConfig = null; 761 try { 762 tcRefConfig = tcRefParser.load(); 763 } catch (IOException exc) { 764 PersistenceManager.LOG.log(Level.WARNING, 765 "[WinSys.ModeParser.addTCRef]" + " Warning: ModeParser " + getName() + ". Cannot load tcRef " + tcRefName, exc); } 768 769 List <TCRefParser> localList = new ArrayList<TCRefParser>(10); 771 Map localMap = (Map) ((HashMap) tcRefParserMap).clone(); 772 773 TCRefParser [] tcRefParserArray = new TCRefParser[tcRefOrder.size()]; 774 for (Iterator it = tcRefOrder.entrySet().iterator(); it.hasNext(); ) { 775 Map.Entry en = (Map.Entry) it.next(); 776 String name = (String ) en.getKey(); 777 int index = ((Integer ) en.getValue()).intValue(); 778 tcRefParser = (TCRefParser) localMap.remove(name); 779 tcRefParserArray[index] = tcRefParser; 783 } 784 for (int i = 0; i < tcRefParserArray.length; i++) { 785 localList.add(tcRefParserArray[i]); 786 } 787 for (Iterator it = localMap.keySet().iterator(); it.hasNext(); ) { 789 tcRefParser = (TCRefParser) localMap.get(it.next()); 790 localList.add(tcRefParser); 791 } 792 793 798 799 localList = carefullySort(localList); 800 801 806 807 tcRefOrder.clear(); 809 for (int i = 0; i < localList.size(); i++) { 810 tcRefParser = (TCRefParser) localList.get(i); 811 tcRefOrder.put(tcRefParser.getName(), Integer.valueOf(i)); 812 } 813 try { 814 writeOrder(); 815 } catch (IOException exc) { 816 PersistenceManager.LOG.log(Level.WARNING, 817 "[WinSys.ModeParser.addTCRef]" + " Warning: Cannot write order of mode: " + getName(), exc); } 820 821 tcRefNameList.clear(); 823 for (int i = 0; i < localList.size(); i++) { 824 tcRefParser = (TCRefParser) localList.get(i); 825 tcRefNameList.add(tcRefParser.getName()); 826 } 827 828 if (DEBUG) Debug.log(ModeParser.class, "addTCRef LEAVE" + " mo:" + getName() 829 + " tcRef:" + tcRefName); 830 831 return tcRefConfig; 832 } 833 834 838 void addTCRefImport (String tcRefName, InternalConfig internalCfg) { 839 if (DEBUG) Debug.log(ModeParser.class, "addTCRefImport ENTER" + " mo:" + getName() 840 + " tcRef:" + tcRefName); 841 TCRefParser tcRefParser = tcRefParserMap.get(tcRefName); 843 if (tcRefParser != null) { 844 PersistenceManager.LOG.log(Level.WARNING, 845 "[WinSys.ModeParser.addTCRef]" + " Warning: ModeParser " + getName() + ". TCRefParser " + tcRefName + " exists but it should not."); tcRefParserMap.remove(tcRefName); 849 } 850 tcRefParser = new TCRefParser(tcRefName); 851 FileObject localFolder = localParentFolder.getFileObject(modeName); 855 tcRefParser.setLocalParentFolder(localFolder); 856 tcRefParser.setInternalConfig(internalCfg); 857 858 863 tcRefParserMap.put(tcRefName, tcRefParser); 864 865 if (DEBUG) Debug.log(ModeParser.class, "addTCRefImport LEAVE" + " mo:" + getName() 866 + " tcRef:" + tcRefName); 867 } 868 869 873 TCRefParser findTCRefParser (String tcRefName) { 874 return tcRefParserMap.get(tcRefName); 876 } 877 878 881 InternalConfig getInternalConfig () { 882 if (internalConfig == null) { 883 internalConfig = new InternalConfig(); 884 } 885 return internalConfig; 886 } 887 888 void setModuleParentFolder (FileObject moduleParentFolder) { 889 this.moduleParentFolder = moduleParentFolder; 890 } 891 892 void setLocalParentFolder (FileObject localParentFolder) { 893 this.localParentFolder = localParentFolder; 894 } 895 896 String getName () { 897 return modeName; 898 } 899 900 boolean isInModuleFolder () { 901 return inModuleFolder; 902 } 903 904 void setInModuleFolder (boolean inModuleFolder) { 905 this.inModuleFolder = inModuleFolder; 906 } 907 908 boolean isInLocalFolder () { 909 return inLocalFolder; 910 } 911 912 void setInLocalFolder (boolean inLocalFolder) { 913 this.inLocalFolder = inLocalFolder; 914 } 915 916 private final class PropertyHandler extends DefaultHandler { 917 918 919 private ModeConfig modeConfig = null; 920 921 922 private InternalConfig internalConfig = null; 923 924 925 private List <SplitConstraint> itemList = new ArrayList<SplitConstraint>(10); 926 927 928 private final Object RW_LOCK = new Object (); 929 930 public PropertyHandler () { 931 } 932 933 private FileObject getConfigFOInput () { 934 FileObject modeConfigFO; 935 if (isInLocalFolder()) { 936 modeConfigFO = localParentFolder.getFileObject 938 (ModeParser.this.getName(), PersistenceManager.MODE_EXT); 939 } else if (isInModuleFolder()) { 940 modeConfigFO = moduleParentFolder.getFileObject 942 (ModeParser.this.getName(), PersistenceManager.MODE_EXT); 943 } else { 944 modeConfigFO = null; 946 } 947 return modeConfigFO; 949 } 950 951 private FileObject getConfigFOOutput () throws IOException { 952 FileObject modeConfigFO; 953 modeConfigFO = localParentFolder.getFileObject 954 (ModeParser.this.getName(), PersistenceManager.MODE_EXT); 955 if (modeConfigFO != null) { 956 return modeConfigFO; 958 } else { 959 StringBuffer buffer = new StringBuffer (); 960 buffer.append(ModeParser.this.getName()); 961 buffer.append('.'); 962 buffer.append(PersistenceManager.MODE_EXT); 963 modeConfigFO = FileUtil.createData(localParentFolder, buffer.toString()); 965 967 return modeConfigFO; 968 } 969 } 970 974 void readData (ModeConfig modeCfg, InternalConfig internalCfg) 975 throws IOException { 976 modeConfig = modeCfg; 977 internalConfig = internalCfg; 978 itemList.clear(); 979 980 FileObject cfgFOInput = getConfigFOInput(); 981 if (cfgFOInput == null) { 982 throw new FileNotFoundException("[WinSys] Missing Mode configuration file:" + ModeParser.this.getName()); 984 } 985 InputStream is = null; 986 try { 987 synchronized (RW_LOCK) { 988 997 is = cfgFOInput.getInputStream(); 999 PersistenceManager.getDefault().getXMLParser(this).parse(new InputSource(is)); 1000 } 1001 } catch (SAXException exc) { 1002 String msg = NbBundle.getMessage(ModeParser.class, 1004 "EXC_ModeParse", cfgFOInput); 1005 1006 throw (IOException) new IOException(msg).initCause(exc); 1007 } finally { 1008 try { 1009 if (is != null) { 1010 is.close(); 1011 } 1012 } catch (IOException exc) { 1013 Logger.getLogger(ModeParser.class.getName()).log(Level.WARNING, null, exc); 1014 } 1015 } 1016 1017 modeConfig.constraints = 1018 itemList.toArray(new SplitConstraint[itemList.size()]); 1019 1020 modeCfg = modeConfig; 1021 internalCfg = internalConfig; 1022 1023 modeConfig = null; 1024 internalConfig = null; 1025 } 1026 1027 public void startElement (String nameSpace, String name, String qname, Attributes attrs) throws SAXException { 1028 if ("mode".equals(qname)) { handleMode(attrs); 1030 } else if (internalConfig.specVersion != null && 1031 internalConfig.specVersion.compareTo(new SpecificationVersion("2.0")) >= 0) { if ("module".equals(qname)) { handleModule(attrs); 1037 } else if ("name".equals(qname)) { handleName(attrs); 1039 } else if ("kind".equals(qname)) { handleKind(attrs); 1041 } else if ("slidingSide".equals(qname)) { handleSlidingSide(attrs); 1043 } else if ("slide-in-size".equals(qname)) { handleSlideInSize(attrs); 1045 } else if ("state".equals(qname)) { handleState(attrs); 1047 } else if ("constraints".equals(qname)) { handleConstraints(attrs); 1049 } else if ("path".equals(qname)) { handlePath(attrs); 1051 } else if ("bounds".equals(qname)) { handleBounds(attrs); 1053 } else if ("relative-bounds".equals(qname)) { handleRelativeBounds(attrs); 1055 } else if ("frame".equals(qname)) { handleFrame(attrs); 1057 } else if ("active-tc".equals(qname)) { handleActiveTC(attrs); 1059 } else if ("empty-behavior".equals(qname)) { handleEmptyBehavior(attrs); 1061 } 1062 } else { 1063 if (DEBUG) Debug.log(ModeParser.class, "-- ModeParser.startElement PARSING OLD"); 1064 } 1066 } 1067 1068 public void error(SAXParseException ex) throws SAXException { 1069 throw ex; 1070 } 1071 1072 1073 private void handleMode (Attributes attrs) { 1074 String version = attrs.getValue("version"); if (version != null) { 1076 internalConfig.specVersion = new SpecificationVersion(version); 1077 } else { 1078 PersistenceManager.LOG.log(Level.WARNING, 1079 "[WinSys.ModeParser.handleMode]" + " Warning: Missing attribute \"version\" of element \"mode\"."); internalConfig.specVersion = new SpecificationVersion("2.0"); } 1083 } 1084 1085 1086 private void handleModule (Attributes attrs) { 1087 String moduleCodeName = attrs.getValue("name"); internalConfig.moduleCodeNameBase = null; 1090 internalConfig.moduleCodeNameRelease = null; 1091 internalConfig.moduleSpecificationVersion = null; 1092 if (moduleCodeName != null) { 1093 int i = moduleCodeName.indexOf('/'); 1094 if (i != -1) { 1095 internalConfig.moduleCodeNameBase = moduleCodeName.substring(0, i); 1096 internalConfig.moduleCodeNameRelease = moduleCodeName.substring(i + 1); 1097 checkReleaseCode(internalConfig); 1098 } else { 1099 internalConfig.moduleCodeNameBase = moduleCodeName; 1100 } 1101 internalConfig.moduleSpecificationVersion = attrs.getValue("spec"); } 1103 } 1104 1105 1107 private void checkReleaseCode (InternalConfig internalConfig) { 1108 if("null".equals(internalConfig.moduleCodeNameRelease)) { Logger.getLogger(ModeParser.class.getName()).log(Level.WARNING, null, 1112 new IllegalStateException ("Module release code was saved as null string" + 1113 " for module " + 1114 internalConfig.moduleCodeNameBase + 1115 "! Repairing.")); 1116 internalConfig.moduleCodeNameRelease = null; 1117 } 1118 } 1119 1120 1121 private void handleName (Attributes attrs) throws SAXException { 1122 String name = attrs.getValue("unique"); if (name != null) { 1124 modeConfig.name = name; 1125 if (!name.equals(ModeParser.this.getName())) { 1126 PersistenceManager.LOG.log(Level.WARNING, 1127 "[WinSys.ModeParser.handleName]" + " Error: Value of attribute \"unique\" of element \"name\"" + " and configuration file name must be the same."); throw new SAXException("Invalid attribute value"); } 1132 } else { 1133 PersistenceManager.LOG.log(Level.WARNING, 1134 "[WinSys.ModeParser.handleName]" + " Error: Missing required attribute \"unique\" of element \"name\"."); throw new SAXException("Missing required attribute"); } 1138 } 1139 1140 1141 private void handleKind (Attributes attrs) { 1142 String type = attrs.getValue("type"); if (type != null) { 1144 if ("editor".equals(type)) { 1145 modeConfig.kind = Constants.MODE_KIND_EDITOR; 1146 } else if ("view".equals(type)) { 1147 modeConfig.kind = Constants.MODE_KIND_VIEW; 1148 } else if ("sliding".equals(type)) { 1149 modeConfig.kind = Constants.MODE_KIND_SLIDING; 1150 } else { 1151 PersistenceManager.LOG.log(Level.WARNING, 1152 "[WinSys.ModeParser.handleKind]" + " Warning: Invalid value of attribute \"type\"."); modeConfig.kind = Constants.MODE_KIND_VIEW; 1155 } 1156 } else { 1157 PersistenceManager.LOG.log(Level.WARNING, 1158 "[WinSys.ModeParser.handleKind]" + " Error: Missing required attribute \"type\" of element \"kind\"."); modeConfig.kind = Constants.MODE_KIND_VIEW; 1161 } 1162 } 1163 1164 1165 private void handleSlidingSide(Attributes attrs) { 1166 String side = attrs.getValue("side"); 1167 if (side != null) { 1168 if (Constants.LEFT.equals(side) || 1169 Constants.RIGHT.equals(side) || 1170 Constants.BOTTOM.equals(side)) 1171 { 1172 modeConfig.side = side; 1173 } else { 1174 PersistenceManager.LOG.log(Level.WARNING, 1175 "[WinSys.ModeParser.handleSlidingSide]" + " Warning: Wrong value \"" + side + "\" of attribute \"side\" for sliding mode"); modeConfig.side = Constants.LEFT; 1178 } 1179 } else { 1180 PersistenceManager.LOG.log(Level.WARNING, 1181 "[WinSys.ModeParser.handleSlidingSide]" + " Warning: Missing value of attribute \"side\" for sliding mode."); modeConfig.side = Constants.LEFT; 1184 } 1185 } 1186 1187 1188 private void handleSlideInSize(Attributes attrs) { 1189 String tcId = attrs.getValue("tc-id"); 1190 String size = attrs.getValue("size"); 1191 if (tcId != null && size != null) { 1192 try { 1193 Integer intSize = Integer.valueOf( size ); 1194 if( null == modeConfig.slideInSizes ) 1195 modeConfig.slideInSizes = new HashMap<String , Integer >(5); 1196 modeConfig.slideInSizes.put( tcId, intSize ); 1197 return; 1198 } catch( NumberFormatException nfE ) { 1199 } 1201 } 1202 PersistenceManager.LOG.log(Level.WARNING, 1203 "[WinSys.ModeParser.handleSlideInSize]" + " Warning: Invalid attributes for preferred slide-in size."); } 1206 1207 private void handleState(Attributes attrs) throws SAXException { 1208 String type = attrs.getValue("type"); if (type != null) { 1210 if ("joined".equals(type)) { 1211 modeConfig.state = Constants.MODE_STATE_JOINED; 1212 } else if ("separated".equals(type)) { 1213 modeConfig.state = Constants.MODE_STATE_SEPARATED; 1214 } else { 1215 PersistenceManager.LOG.log(Level.WARNING, 1216 "[WinSys.ModeParser.handleState]" + " Warning: Invalid value of attribute \"type\"" + " of element \"state\"."); modeConfig.state = Constants.MODE_STATE_JOINED; 1220 } 1221 } else { 1222 PersistenceManager.LOG.log(Level.WARNING, 1223 "[WinSys.ModeParser.handleState]" + " Error: Missing required attribute \"type\"" 1225 + " of element \"state\"."); modeConfig.state = Constants.MODE_STATE_JOINED; 1227 } 1228 } 1229 1230 1231 private void handleConstraints (Attributes attrs) { 1232 } 1233 1234 1235 private void handlePath (Attributes attrs) { 1236 String s = attrs.getValue("orientation"); int orientation; 1238 if ("horizontal".equals(s)) { orientation = Constants.HORIZONTAL; 1240 } else if ("vertical".equals(s)) { orientation = Constants.VERTICAL; 1242 } else { 1243 PersistenceManager.LOG.log(Level.WARNING, 1244 "[WinSys.ModeParser.handlePath]" + " Warning: Invalid or missing value of attribute \"orientation\"."); orientation = Constants.VERTICAL; 1247 } 1248 1249 int number; 1250 try { 1251 s = attrs.getValue("number"); if (s != null) { 1253 number = Integer.parseInt(s); 1254 } else { 1255 PersistenceManager.LOG.log(Level.WARNING, 1256 "[WinSys.ModeParser.handlePath]" + " Warning: Missing value of attribute \"number\"."); number = 0; 1259 } 1260 } catch (NumberFormatException exc) { 1261 PersistenceManager.LOG.log(Level.WARNING, 1262 "[WinSys.ModeParser.handlePath]" + " Warning: Cannot read element \"path\", attribute \"number\"", exc); number = 0; 1265 } 1266 1267 double weight; 1268 try { 1269 s = attrs.getValue("weight"); if (s != null) { 1271 weight = Double.parseDouble(s); 1272 } else { 1273 weight = 0.5; 1275 } 1276 } catch (NumberFormatException exc) { 1277 PersistenceManager.LOG.log(Level.WARNING, 1278 "[WinSys.ModeParser.handlePath]" + " Warning: Cannot read element \"path\", attribute \"weight\".", exc); weight = 0.5; 1281 } 1282 SplitConstraint item = new SplitConstraint(orientation, number, weight); 1283 itemList.add(item); 1284 } 1285 1286 1287 private void handleBounds (Attributes attrs) { 1288 try { 1289 String s; 1290 int x, y, width, height; 1291 1292 modeConfig.bounds = null; 1293 s = attrs.getValue("x"); if (s != null) { 1295 x = Integer.parseInt(s); 1296 } else { 1297 PersistenceManager.LOG.log(Level.WARNING, 1298 "[WinSys.ModeParser.handleBounds]" + " Warning: Missing attribute \"x\" of element \"bounds\"."); return; 1301 } 1302 s = attrs.getValue("y"); if (s != null) { 1304 y = Integer.parseInt(s); 1305 } else { 1306 PersistenceManager.LOG.log(Level.WARNING, 1307 "[WinSys.ModeParser.handleBounds]" + " Warning: Missing attribute \"y\" of element \"bounds\"."); return; 1310 } 1311 s = attrs.getValue("width"); if (s != null) { 1313 width = Integer.parseInt(s); 1314 } else { 1315 PersistenceManager.LOG.log(Level.WARNING, 1316 "[WinSys.ModeParser.handleBounds]" + " Warning: Missing attribute \"width\" of element \"bounds\"."); return; 1319 } 1320 s = attrs.getValue("height"); if (s != null) { 1322 height = Integer.parseInt(s); 1323 } else { 1324 PersistenceManager.LOG.log(Level.WARNING, 1325 "[WinSys.ModeParser.handleBounds]" + " Warning: Missing attribute \"height\" of element \"bounds\"."); return; 1328 } 1329 modeConfig.bounds = new Rectangle(x, y, width, height); 1330 } catch (NumberFormatException exc) { 1331 PersistenceManager.LOG.log(Level.WARNING, 1332 "[WinSys.ModeParser.handleBounds]" + " Warning: Cannot read element \"bounds\".", exc); } 1335 } 1336 1337 1338 private void handleRelativeBounds (Attributes attrs) { 1339 try { 1340 String s; 1341 int x, y, width, height; 1342 1343 modeConfig.relativeBounds = null; 1344 s = attrs.getValue("x"); if (s != null) { 1346 x = Integer.parseInt(s); 1347 } else { 1348 PersistenceManager.LOG.log(Level.WARNING, 1349 "[WinSys.ModeParser.handleRelativeBounds]" + " Warning: Missing attribute \"x\" of element \"relative-bounds\"."); return; 1352 } 1353 s = attrs.getValue("y"); if (s != null) { 1355 y = Integer.parseInt(s); 1356 } else { 1357 PersistenceManager.LOG.log(Level.WARNING, 1358 "[WinSys.ModeParser.handleRelativeBounds]" + " Warning: Missing attribute \"y\" of element \"relative-bounds\"."); return; 1361 } 1362 s = attrs.getValue("width"); if (s != null) { 1364 width = Integer.parseInt(s); 1365 } else { 1366 PersistenceManager.LOG.log(Level.WARNING, 1367 "[WinSys.ModeParser.handleRelativeBounds]" + " Warning: Missing attribute \"width\" of element \"relative-bounds\"."); return; 1370 } 1371 s = attrs.getValue("height"); if (s != null) { 1373 height = Integer.parseInt(s); 1374 } else { 1375 PersistenceManager.LOG.log(Level.WARNING, 1376 "[WinSys.ModeParser.handleRelativeBounds]" + " Warning: Missing attribute \"height\" of element \"relative-bounds\"."); return; 1379 } 1380 modeConfig.relativeBounds = new Rectangle(x, y, width, height); 1381 } catch (NumberFormatException exc) { 1382 PersistenceManager.LOG.log(Level.WARNING, 1383 "[WinSys.ModeParser.handleRelativeBounds]" + " Warning: Cannot read element \"relative-bounds\".", exc); } 1386 } 1387 1388 1389 private void handleFrame (Attributes attrs) { 1390 String frameState = attrs.getValue("state"); if (frameState != null) { 1392 try { 1393 modeConfig.frameState = Integer.parseInt(frameState); 1394 } catch (NumberFormatException exc) { 1395 PersistenceManager.LOG.log(Level.WARNING, 1396 "[WinSys.ModeParser.handleFrame]" + " Warning: Cannot read attribute \"state\"" + " of element \"frame\".", exc); modeConfig.frameState = Frame.NORMAL; 1400 } 1401 } else { 1402 PersistenceManager.LOG.log(Level.WARNING, 1403 "[WinSys.ModeParser.handleFrame]" + " Warning: Missing value of attribute \"state\"" + " of element \"frame\"."); modeConfig.frameState = Frame.NORMAL; 1407 } 1408 } 1409 1410 1411 private void handleActiveTC (Attributes attrs) { 1412 String id = attrs.getValue("id"); if (id != null) { 1414 modeConfig.selectedTopComponentID = id; 1415 } else { 1416 modeConfig.selectedTopComponentID = ""; } 1418 String prevId = attrs.getValue("prev-id"); if (prevId != null) { 1420 modeConfig.previousSelectedTopComponentID = prevId; 1421 } else { 1422 modeConfig.previousSelectedTopComponentID = ""; } 1424 } 1425 1426 1427 private void handleEmptyBehavior (Attributes attrs) { 1428 String value = attrs.getValue("permanent"); if ("true".equals(value)) { modeConfig.permanent = true; 1431 } else if ("false".equals(value)) { modeConfig.permanent = false; 1433 } else { 1434 PersistenceManager.LOG.log(Level.WARNING, 1435 "[WinSys.ModeParser.handleEmptyBehavior]" + " Warning: Invalid value of attribute \"permanent\"."); modeConfig.permanent = false; 1438 } 1439 } 1440 1441 1442 void writeData (ModeConfig mc, InternalConfig ic) throws IOException { 1443 final StringBuffer buff = fillBuffer(mc, ic); 1444 synchronized (RW_LOCK) { 1445 FileObject cfgFOOutput = getConfigFOOutput(); 1446 FileLock lock = null; 1447 OutputStream os = null; 1448 OutputStreamWriter osw = null; 1449 try { 1450 lock = cfgFOOutput.lock(); 1451 os = cfgFOOutput.getOutputStream(lock); 1452 osw = new OutputStreamWriter(os, "UTF-8"); osw.write(buff.toString()); 1454 1456 } finally { 1457 try { 1458 if (osw != null) { 1459 osw.close(); 1460 } 1461 } catch (IOException exc) { 1462 Logger.getLogger(ModeParser.class.getName()).log(Level.WARNING, null, exc); 1463 } 1464 if (lock != null) { 1465 lock.releaseLock(); 1466 } 1467 } 1468 } 1469 } 1470 1471 1473 private StringBuffer fillBuffer (ModeConfig mc, InternalConfig ic) throws IOException { 1474 StringBuffer buff = new StringBuffer (800); 1475 buff.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"). 1480 append("<mode version=\"2.3\">\n"); 1482 appendModule(ic, buff); 1483 appendName(mc, buff); 1484 appendKind(mc, buff); 1485 if (mc.kind == Constants.MODE_KIND_SLIDING) { 1486 appendSlidingSide(mc, buff); 1487 if( null != mc.slideInSizes ) 1488 appendSlideInSize(mc, buff); 1489 } 1490 appendState(mc, buff); 1491 appendConstraints(mc, buff); 1492 if (mc.bounds != null) { 1493 appendBounds(mc, buff); 1494 } else if (mc.relativeBounds != null) { 1495 appendRelativeBounds(mc, buff); 1496 } 1497 appendFrame(mc, buff); 1498 appendActiveTC(mc, buff); 1499 appendEmptyBehavior(mc, buff); 1500 1501 buff.append("</mode>\n"); return buff; 1503 } 1504 1505 private void appendModule (InternalConfig ic, StringBuffer buff) { 1506 if (ic == null) { 1507 return; 1508 } 1509 if (ic.moduleCodeNameBase != null) { 1510 buff.append(" <module name=\""); buff.append(ic.moduleCodeNameBase); 1512 if (ic.moduleCodeNameRelease != null) { 1513 buff.append("/").append(ic.moduleCodeNameRelease); } 1515 if (ic.moduleSpecificationVersion != null) { 1516 buff.append("\" spec=\""); buff.append(ic.moduleSpecificationVersion); 1518 } 1519 buff.append("\" />\n"); } 1521 } 1522 1523 private void appendName (ModeConfig mc, StringBuffer buff) { 1524 buff.append(" <name unique=\""); buff.append(mc.name); 1526 buff.append("\" />\n"); } 1528 1529 private void appendKind (ModeConfig mc, StringBuffer buff) { 1530 buff.append(" <kind type=\""); if (mc.kind == Constants.MODE_KIND_EDITOR) { 1532 buff.append("editor"); } else if (mc.kind == Constants.MODE_KIND_VIEW) { 1534 buff.append("view"); } else if (mc.kind == Constants.MODE_KIND_SLIDING) { 1536 buff.append("sliding"); } 1538 buff.append("\" />\n"); } 1540 1541 private void appendSlidingSide(ModeConfig mc, StringBuffer buff) { 1542 buff.append(" <slidingSide side=\""); 1543 buff.append(mc.side); 1544 buff.append("\" "); 1545 buff.append("/>\n"); } 1547 1548 private void appendSlideInSize(ModeConfig mc, StringBuffer buff) { 1549 if( null != mc.slideInSizes ) { 1550 for( Iterator<String > i=mc.slideInSizes.keySet().iterator(); i.hasNext(); ) { 1551 String tcId = i.next(); 1552 Integer size = mc.slideInSizes.get(tcId); 1553 1554 buff.append(" <slide-in-size tc-id=\""); 1555 buff.append(tcId); 1556 buff.append("\" size=\""); 1557 buff.append(size.intValue()); 1558 buff.append("\" />\n"); } 1560 } 1561 } 1562 1563 private void appendState (ModeConfig mc, StringBuffer buff) { 1564 buff.append(" <state type=\""); if (mc.state == Constants.MODE_STATE_JOINED) { 1566 buff.append("joined"); } else if (mc.state == Constants.MODE_STATE_SEPARATED) { 1568 buff.append("separated"); } 1570 buff.append("\" />\n"); } 1572 1573 private void appendConstraints (ModeConfig mc, StringBuffer buff) { 1574 if (mc.constraints.length == 0) { 1575 return; 1576 } 1577 buff.append(" <constraints>\n"); for (int i = 0; i < mc.constraints.length; i++) { 1579 SplitConstraint item = mc.constraints[i]; 1580 buff.append(" <path orientation=\""); if (item.orientation == Constants.HORIZONTAL) { 1582 buff.append("horizontal"); } else { 1584 buff.append("vertical"); } 1586 buff.append("\" number=\"").append(item.index).append("\" weight=\"").append(item.splitWeight).append("\"/>\n"); } 1588 buff.append(" </constraints>\n"); } 1590 1591 private void appendBounds (ModeConfig mc, StringBuffer buff) { 1592 if (mc.bounds == null) { 1593 return; 1594 } 1595 buff.append(" <bounds x=\"").append(mc.bounds.x). 1596 append("\" y=\"").append(mc.bounds.y). 1597 append("\" width=\"").append(mc.bounds.width). 1598 append("\" height=\"").append(mc.bounds.height).append("\" />\n"); } 1600 1601 private void appendRelativeBounds (ModeConfig mc, StringBuffer buff) { 1602 if (mc.relativeBounds == null) { 1603 return; 1604 } 1605 buff.append(" <relative-bounds x=\"").append(mc.relativeBounds.x). 1606 append("\" y=\"").append(mc.relativeBounds.y). 1607 append("\" width=\"").append(mc.relativeBounds.width). 1608 append("\" height=\"").append(mc.relativeBounds.height).append("\" />\n"); } 1610 1611 private void appendFrame (ModeConfig mc, StringBuffer buff) { 1612 buff.append(" <frame state=\"").append(mc.frameState).append("\"/>\n"); } 1614 1615 private void appendActiveTC (ModeConfig mc, StringBuffer buff) { 1616 if ((mc.selectedTopComponentID != null && !"".equals(mc.selectedTopComponentID)) 1617 || (mc.previousSelectedTopComponentID != null && !"".equals(mc.previousSelectedTopComponentID)) ) { 1618 buff.append(" <active-tc "); 1619 1620 if (mc.selectedTopComponentID != null && !"".equals(mc.selectedTopComponentID)) { 1621 String tcName = PersistenceManager.escapeTcId4XmlContent(mc.selectedTopComponentID); 1622 buff.append( " id=\"").append(tcName).append("\" "); } 1624 1625 if (mc.previousSelectedTopComponentID != null && !"".equals(mc.previousSelectedTopComponentID)) { 1626 String tcName = PersistenceManager.escapeTcId4XmlContent(mc.previousSelectedTopComponentID); 1627 buff.append( " prev-id=\"").append(tcName).append("\" "); } 1629 buff.append("/>\n"); } 1631 } 1632 1633 private void appendEmptyBehavior (ModeConfig mc, StringBuffer buff) { 1634 buff.append(" <empty-behavior permanent=\"").append(mc.permanent).append("\"/>\n"); } 1636 } 1637 1638} 1639 | Popular Tags |