1 27 package com.genimen.djeneric.tools.io; 28 29 import java.awt.Color ; 30 import java.io.ByteArrayInputStream ; 31 import java.io.UnsupportedEncodingException ; 32 import java.util.ArrayList ; 33 import java.util.HashMap ; 34 import java.util.StringTokenizer ; 35 36 import javax.swing.JFrame ; 37 import javax.xml.parsers.DocumentBuilderFactory ; 38 39 import org.w3c.dom.CDATASection ; 40 import org.w3c.dom.Document ; 41 import org.w3c.dom.Element ; 42 import org.w3c.dom.NodeList ; 43 44 import com.genimen.djeneric.language.Messages; 45 import com.genimen.djeneric.repository.DjExtent; 46 import com.genimen.djeneric.repository.DjPersistenceManager; 47 import com.genimen.djeneric.repository.DjProperty; 48 import com.genimen.djeneric.repository.DjRelation; 49 import com.genimen.djeneric.repository.exceptions.CatalogException; 50 import com.genimen.djeneric.repository.exceptions.DjenericException; 51 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException; 52 import com.genimen.djeneric.structure.EditorDefinition; 53 import com.genimen.djeneric.structure.ExtentUsage; 54 import com.genimen.djeneric.structure.PropertyUsage; 55 import com.genimen.djeneric.structure.ResourceDefinition; 56 import com.genimen.djeneric.structure.ScriptDefinition; 57 import com.genimen.djeneric.tools.modeler.diagrammer.ExtentViewer; 58 import com.genimen.djeneric.util.DjLogger; 59 60 public class DjenericDocumentHandler 61 { 62 private Document _xmlDoc = null; 63 64 public final static String VIEW = "view"; 65 66 public final static String VIEW_STRUCTURE_VERSION = "structureversion"; 67 public final static int VIEW_STRUCTURE_VERSION_NUMBER = 101; 68 69 public final static String DIAGRAM_ELEMENT = "diagram"; 70 71 public final static String EXTENTVIEW_ELEMENT = "extentview"; 72 public final static String EXTENTVIEW_TABLE = "extent"; 73 public final static String EXTENTVIEW_ALIAS = "alias"; 74 public final static String EXTENTVIEW_TYPE = "type"; 75 public final static String EXTENTVIEW_X = "x"; 76 public final static String EXTENTVIEW_Y = "y"; 77 public final static String EXTENTVIEW_WIDTH = "with"; 78 public final static String EXTENTVIEW_HEIGHT = "height"; 79 public final static String EXTENTVIEW_TCOLOR = "tcolor"; 80 public final static String EXTENTVIEW_NCOLOR = "ncolor"; 81 public final static String EXTENTVIEW_CCOLOR = "vcolor"; 82 83 public final static String NAVIGATOR_ELEMENT = "navigator"; 84 85 public final static String NAVIGATOR_EXTENTNODE_ELEMENT = "extentnode"; 86 public final static String NAVIGATOR_EXTENTNODE_NAME = "name"; 87 public final static String NAVIGATOR_EXTENTNODE_TYPE = "type"; 88 public final static String NAVIGATOR_EXTENTNODE_VIA = "via"; 89 public final static String NAVIGATOR_EXTENTNODE_DETAIL_COLUMN = "viacolumn"; 90 public final static String NAVIGATOR_EXTENTNODE_TITLE = "title"; 91 public final static String NAVIGATOR_EXTENTNODE_ALIAS = "alias"; 92 public final static String NAVIGATOR_EXTENTNODE_ID = "id"; 93 public final static String NAVIGATOR_EXTENTNODE_INTERNAL_CODE = "extentcode"; 94 public final static String NAVIGATOR_EXTENTNODE_DESCRIPTOR = "descriptor"; 95 public final static String NAVIGATOR_EXTENTNODE_EDIT = "edit"; 96 public final static String NAVIGATOR_EXTENTNODE_INSERT = "insert"; 97 public final static String NAVIGATOR_EXTENTNODE_DELETE = "delete"; 98 public final static String NAVIGATOR_EXTENTNODE_RECURSIVE = "recursive"; 99 public final static String NAVIGATOR_EXTENTNODE_QBE_FILTER = "qbefilter"; 100 101 public final static String NAVIGATOR_EXTENTNODE_CUSTOM_NODE_CLASS = "customnodeclass"; 102 public final static String NAVIGATOR_EXTENTNODE_EDITOR = "editor"; 103 public final static String NAVIGATOR_EXTENTNODE_EDITORTARGET = "editortarget"; 104 public final static String NAVIGATOR_EXTENTNODE_IMAGEICON = "imageicon"; 105 106 public final static String EDITORS_ELEMENT = "editors"; 107 108 public final static String EDITOR_ELEMENT = "editor"; 109 public final static String EDITOR_NAME = "name"; 110 public final static String EDITOR_CUSTOMCLASS = "class"; 111 public final static String EDITOR_EXTENTNODE_TYPE = "type"; 112 public final static String EDITOR_EXTENTNODE_VIA = "via"; 113 public final static String EDITOR_DETAIL_COLUMN = "viacolumn"; 114 public final static String EDITOR_TITLE = "title"; 115 public final static String EDITOR_QBE_FILTER = "qbefilter"; 116 public final static String EDITOR_EXTENTNODE_ID = "id"; 117 public final static String EDITOR_EXTENTNODE_ALIAS = "alias"; 118 public final static String EDITOR_EXTENTNODE_INTERNAL_CODE = "extentcode"; 119 public final static String EDITOR_EDIT = "edit"; 120 public final static String EDITOR_INSERT = "insert"; 121 public final static String EDITOR_DELETE = "delete"; 122 public final static String EDITOR_MULTIROW = "multirow"; 123 public final static String EDITOR_ROWSDISPLAYED = "rows"; 124 public final static String EDITOR_EMBEDDED_SCRIPT = "embeddedscript"; 125 126 public final static String RESOURCE_ELEMENT = "resource"; 127 public final static String RESOURCE_ELEMENT_ABSOLUTE_PATH = "abspath"; 128 public final static String RESOURCE_ELEMENT_TIMESTAMP = "timestamp"; 129 130 public final static String SCRIPT_ELEMENT = "script"; 131 public final static String SCRIPT_ELEMENT_TITLE = "title"; 132 133 public final static String EDITOR_EXTENT_USAGE_ELEMENT = "extentusage"; 134 public final static String EDITOR_PROPERTY_USAGE_ELEMENT = "columnusage"; 135 public final static String EDITOR_PROPERTY_USAGE_SEQ = "seq"; 136 public final static String EDITOR_PROPERTY_USAGE_COLUMN = "column"; 137 public final static String EDITOR_PROPERTY_USAGE_PROMPT = "prompt"; 138 public final static String EDITOR_PROPERTY_USAGE_DESCRIPTION = "description"; 139 public final static String EDITOR_PROPERTY_USAGE_COMPONENT = "component"; 140 public final static String EDITOR_PROPERTY_USAGE_REQUIRED = "required"; 141 public final static String EDITOR_PROPERTY_USAGE_UPDATEABLE = "updateable"; 142 public final static String EDITOR_PROPERTY_USAGE_QUERYABLE = "queryable"; 143 public final static String EDITOR_PROPERTY_USAGE_DISPLAYED = "displayed"; 144 public final static String EDITOR_PROPERTY_USAGE_DEFAULT_VALUE = "default"; 145 public final static String EDITOR_PROPERTY_USAGE_CUSTOM_EDITOR = "customeditor"; 146 public final static String EDITOR_PROPERTY_USAGE_RELATIVE_PATH = "relativepath"; 147 public final static String EDITOR_PROPERTY_USAGE_WIDTH = "width"; 148 public final static String EDITOR_PROPERTY_USAGE_HEIGHT = "height"; 149 public final static String EDITOR_PROPERTY_USAGE_SORT_ORDER = "sortorder"; 150 151 private HashMap _allEditorsHashed = null; 152 private EditorDefinition[] _allEditors = null; 153 154 private HashMap _allResourcesHashed = null; 155 private ResourceDefinition[] _allResources = null; 156 157 private ScriptDefinition[] _allScripts = null; 158 159 public DjenericDocumentHandler() 160 { 161 } 162 163 public DjenericDocumentHandler(String xmlString) throws DjenericException 164 { 165 try 166 { 167 ByteArrayInputStream sr = new ByteArrayInputStream (xmlString.getBytes(DjPersistenceManager.ENCODING_METHOD)); 168 169 DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); 170 _xmlDoc = dfactory.newDocumentBuilder().parse(sr); 171 } 172 catch (Exception x) 173 { 174 throw new DjenericException(x); 175 } 176 } 177 178 protected DjExtent findExtent(DjPersistenceManager mgr, String extentName, String extentAlias, String objectType) 179 { 180 DjExtent tab = null; 181 try 182 { 183 tab = mgr.getExtent(extentName); 184 } 185 catch (Exception x) 186 { 187 } 189 if (tab == null) 190 { 191 try 192 { 193 tab = mgr.getExtentByInternalCode(extentAlias); 194 } 195 catch (Exception x) 196 { 197 } 199 } 200 if (tab == null) 201 { 202 try 203 { 204 tab = mgr.getExtentByObjectType(objectType); 205 } 206 catch (Exception x) 207 { 208 } 210 } 211 return tab; 212 } 213 214 protected DjRelation findRelation(DjExtent parent, DjExtent detail, String relationName, String detailPropertyName) 215 { 216 for (int i = 0; i < parent.getDetailRelationCount(); i++) 217 { 218 DjRelation rel = parent.getDetailRelation(i); 219 if (rel.getName().equals(relationName)) return rel; 220 } 221 for (int i = 0; i < parent.getDetailRelationCount(); i++) 223 { 224 DjRelation rel = parent.getDetailRelation(i); 225 if ((rel.getDetailExtent() == detail) && (rel.getDetailProperty().getName().equalsIgnoreCase(detailPropertyName))) return rel; 226 } 227 return null; 229 } 230 231 protected boolean convert2bool(String str) 232 { 233 return convert2bool(str, false); 234 } 235 236 protected boolean convert2bool(String str, boolean dflt) 237 { 238 if (str == null || str.trim().length() == 0) return dflt; 239 return str.equalsIgnoreCase("true"); 240 } 241 242 protected int convert2Int(String str) 243 { 244 int result = 0; 245 if (str.trim().length() > 0) 246 { 247 result = Integer.parseInt(str); 248 } 249 return result; 250 } 251 252 protected String encodeColor(Color c) 253 { 254 return c.getRed() + "," + c.getGreen() + "," + c.getBlue(); 255 } 256 257 protected Color decodeColor(String s, Color c2) 258 { 259 try 260 { 261 StringTokenizer st = new StringTokenizer (s, ","); 262 Color c = new Color (Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st 263 .nextToken())); 264 return c; 265 } 266 catch (Exception x) 267 { 268 DjLogger.log(x); 269 } 270 return c2; 271 } 272 273 public ExtentViewer[] getExtentViewers(DjPersistenceManager mgr) throws Exception 274 { 275 ArrayList result = new ArrayList (); 276 277 Element diagram = (Element ) _xmlDoc.getElementsByTagName(DIAGRAM_ELEMENT).item(0); 278 279 if (diagram != null) 280 { 281 NodeList extentviews = diagram.getElementsByTagName(EXTENTVIEW_ELEMENT); 282 for (int t = 0; t < extentviews.getLength(); t++) 283 { 284 if (extentviews.item(t) instanceof Element ) 285 { 286 Element extentView = (Element ) (extentviews.item(t)); 287 DjExtent tab = findExtent(mgr, extentView.getAttribute(EXTENTVIEW_TABLE), extentView 288 .getAttribute(EXTENTVIEW_ALIAS), extentView.getAttribute(EXTENTVIEW_TYPE)); 289 290 if (tab == null) 291 { 292 DjLogger.log(Messages.getString("DjenericDocumentHandler.ExtentRemovedFromDiag", extentView 293 .getAttribute(EXTENTVIEW_TABLE))); 294 continue; 295 } 296 ExtentViewer tv = new ExtentViewer(tab); 297 tv.setX(convert2Int(extentView.getAttribute(EXTENTVIEW_X))); 298 tv.setY(convert2Int(extentView.getAttribute(EXTENTVIEW_Y))); 299 tv.setWidth(convert2Int(extentView.getAttribute(EXTENTVIEW_WIDTH))); 300 tv.setHeight(convert2Int(extentView.getAttribute(EXTENTVIEW_HEIGHT))); 301 302 tv.setExtentColor(decodeColor(extentView.getAttribute(EXTENTVIEW_TCOLOR), tv.getExtentColor())); 303 tv.setNameColor(decodeColor(extentView.getAttribute(EXTENTVIEW_NCOLOR), tv.getNameColor())); 304 tv.setPropertyColor(decodeColor(extentView.getAttribute(EXTENTVIEW_CCOLOR), tv.getPropertyColor())); 305 306 result.add(tv); 307 } 308 } 309 } 310 return (ExtentViewer[]) result.toArray(new ExtentViewer[0]); 311 } 312 313 public ExtentUsage[] getTreeStructure(DjPersistenceManager mgr) throws DjenericException 314 { 315 getEditors(mgr); 317 getResources(); 318 319 Element navigator = (Element ) _xmlDoc.getElementsByTagName(NAVIGATOR_ELEMENT).item(0); 320 ArrayList result = new ArrayList (); 321 322 if (navigator != null) 323 { 324 NodeList extentnodes = navigator.getChildNodes(); 325 for (int t = 0; t < extentnodes.getLength(); t++) 326 { 327 if (extentnodes.item(t) instanceof Element ) 328 { 329 Element tn = (Element ) (extentnodes.item(t)); 330 if (tn.getNodeName().equals(NAVIGATOR_EXTENTNODE_ELEMENT)) 331 { 332 DjExtent tab = findExtent(mgr, tn.getAttribute(NAVIGATOR_EXTENTNODE_NAME), tn 333 .getAttribute(NAVIGATOR_EXTENTNODE_ALIAS), tn.getAttribute(NAVIGATOR_EXTENTNODE_TYPE)); 334 if (tab == null) 335 { 336 DjLogger.log(Messages.getString("DjenericDocumentHandler.ExtentRemovedFromNav", tn 337 .getAttribute(NAVIGATOR_EXTENTNODE_NAME))); 338 339 continue; 340 } 341 342 ExtentUsage extentUsage = new ExtentUsage(tab); 343 result.add(extentUsage); 344 extentUsage.setTitle(tn.getAttribute(NAVIGATOR_EXTENTNODE_TITLE)); 345 extentUsage.setOqlExpression(tn.getAttribute(NAVIGATOR_EXTENTNODE_QBE_FILTER)); 346 extentUsage.setCustomNodeClass(tn.getAttribute(NAVIGATOR_EXTENTNODE_CUSTOM_NODE_CLASS)); 347 348 extentUsage.setId(tn.getAttribute(NAVIGATOR_EXTENTNODE_ID)); 349 extentUsage.setDescriptorExpression(tn.getAttribute(NAVIGATOR_EXTENTNODE_DESCRIPTOR)); 350 extentUsage.setEditAllowed(convert2bool(tn.getAttribute(NAVIGATOR_EXTENTNODE_EDIT))); 351 extentUsage.setInsertAllowed(convert2bool(tn.getAttribute(NAVIGATOR_EXTENTNODE_INSERT))); 352 extentUsage.setDeleteAllowed(convert2bool(tn.getAttribute(NAVIGATOR_EXTENTNODE_DELETE))); 353 extentUsage.setRecursive(convert2bool(tn.getAttribute(NAVIGATOR_EXTENTNODE_RECURSIVE))); 354 355 createDetailsFromDoc(mgr, extentUsage, tn); 356 } 357 } 358 } 359 } 360 return (ExtentUsage[]) result.toArray(new ExtentUsage[0]); 361 } 362 363 protected void createDetailsFromDoc(DjPersistenceManager mgr, ExtentUsage parent, Element parentElement) 364 throws DjenericException 365 { 366 String editorName = parentElement.getAttribute(NAVIGATOR_EXTENTNODE_EDITOR); 367 if (editorName != null && editorName.trim().length() != 0) 368 { 369 EditorDefinition editor = getEditor(editorName); 370 parent.setEditor(editor); 371 parent.setEditorTarget(parentElement.getAttribute(NAVIGATOR_EXTENTNODE_EDITORTARGET)); 372 } 373 374 String imageIconName = parentElement.getAttribute(NAVIGATOR_EXTENTNODE_IMAGEICON); 375 if (imageIconName != null && imageIconName.trim().length() != 0) 376 { 377 ResourceDefinition res = getResource(imageIconName); 378 parent.setImageIconResource(res); 379 } 380 381 NodeList children = parentElement.getChildNodes(); 382 for (int t = 0; t < children.getLength(); t++) 383 { 384 if (children.item(t) instanceof Element ) 385 { 386 Element tn = (Element ) (children.item(t)); 387 if (tn.getNodeName().equals(EDITOR_ELEMENT)) 389 { 390 parent.setEditor(getEditor(generateEditorname(parent))); 391 } 392 else if (tn.getNodeName().equals(NAVIGATOR_EXTENTNODE_ELEMENT)) 393 { 394 DjExtent currentExtent = findExtent(mgr, tn.getAttribute(NAVIGATOR_EXTENTNODE_NAME), tn 395 .getAttribute(NAVIGATOR_EXTENTNODE_ALIAS), tn.getAttribute(NAVIGATOR_EXTENTNODE_TYPE)); 396 if (currentExtent == null) 397 { 398 DjLogger.log(Messages.getString("DjenericDocumentHandler.ExtentRemovedFromNav", tn 399 .getAttribute(NAVIGATOR_EXTENTNODE_NAME))); 400 return; 401 } 402 403 String relationName = tn.getAttribute(NAVIGATOR_EXTENTNODE_VIA); 404 if (relationName != null && relationName.trim().length() == 0) relationName = null; 405 DjRelation rel = null; 406 if (relationName != null) 407 { 408 rel = findRelation(parent.getExtent(), currentExtent, relationName, tn 409 .getAttribute(NAVIGATOR_EXTENTNODE_DETAIL_COLUMN)); 410 if (rel == null) 411 { 412 DjLogger.log(Messages.getString("DjenericDocumentHandler.DetailRemoved", relationName, parent.getExtent() 413 .getName(), currentExtent.getName())); 414 return; 415 } 416 } 417 ExtentUsage extentUsage = new ExtentUsage(currentExtent); 418 parent.addDetail(extentUsage, rel); 419 extentUsage.setTitle(tn.getAttribute(NAVIGATOR_EXTENTNODE_TITLE)); 420 extentUsage.setOqlExpression(tn.getAttribute(NAVIGATOR_EXTENTNODE_QBE_FILTER)); 421 extentUsage.setCustomNodeClass(tn.getAttribute(NAVIGATOR_EXTENTNODE_CUSTOM_NODE_CLASS)); 422 extentUsage.setId(tn.getAttribute(NAVIGATOR_EXTENTNODE_ID)); 423 extentUsage.setDescriptorExpression(tn.getAttribute(NAVIGATOR_EXTENTNODE_DESCRIPTOR)); 424 extentUsage.setEditAllowed(convert2bool(tn.getAttribute(NAVIGATOR_EXTENTNODE_EDIT))); 425 extentUsage.setInsertAllowed(convert2bool(tn.getAttribute(NAVIGATOR_EXTENTNODE_INSERT))); 426 extentUsage.setDeleteAllowed(convert2bool(tn.getAttribute(NAVIGATOR_EXTENTNODE_DELETE))); 427 extentUsage.setRecursive(convert2bool(tn.getAttribute(NAVIGATOR_EXTENTNODE_RECURSIVE))); 428 429 createDetailsFromDoc(mgr, extentUsage, tn); 430 } 431 } 432 } 433 } 434 435 public EditorDefinition[] getEditors(DjPersistenceManager mgr) throws DjenericException 436 { 437 if (_allEditors != null) return _allEditors; 438 439 NodeList editorElements = _xmlDoc.getElementsByTagName(EDITOR_ELEMENT); 440 ArrayList result = new ArrayList (); 441 442 if (editorElements != null) 443 { 444 for (int t = 0; t < editorElements.getLength(); t++) 445 { 446 if (editorElements.item(t) instanceof Element ) 447 { 448 Element tn = (Element ) (editorElements.item(t)); 449 result.add(createEditor(mgr, tn)); 450 } 451 } 452 } 453 _allEditors = (EditorDefinition[]) result.toArray(new EditorDefinition[0]); 454 455 _allEditorsHashed = new HashMap (); 456 457 for (int i = 0; i < _allEditors.length; i++) 458 { 459 _allEditorsHashed.put(_allEditors[i].getName(), _allEditors[i]); 460 } 461 return _allEditors; 462 } 463 464 public EditorDefinition getEditor(String name) throws CatalogException 465 { 466 if (_allEditorsHashed == null) throw new CatalogException( 467 "Internal error: load editors before calling getEditor(name)"); 468 469 return (EditorDefinition) _allEditorsHashed.get(name); 470 } 471 472 public ResourceDefinition[] getResources() throws DjenericException 473 { 474 if (_allResources != null) return _allResources; 475 476 NodeList resourceElements = _xmlDoc.getElementsByTagName(RESOURCE_ELEMENT); 477 ArrayList result = new ArrayList (); 478 479 if (resourceElements != null) 480 { 481 for (int t = 0; t < resourceElements.getLength(); t++) 482 { 483 if (resourceElements.item(t) instanceof Element ) 484 { 485 Element resel = (Element ) (resourceElements.item(t)); 486 String base64 = ""; 487 488 NodeList nl = resel.getChildNodes(); 489 for (int x = 0; x < nl.getLength(); x++) 490 { 491 if (nl.item(x) instanceof CDATASection ) 492 { 493 CDATASection d = (CDATASection ) nl.item(x); 494 base64 = d.getData(); 495 } 496 } 497 498 ResourceDefinition def = new ResourceDefinition(); 499 def.setAbsolutePath(resel.getAttribute(RESOURCE_ELEMENT_ABSOLUTE_PATH)); 500 def.setTimeStamp(resel.getAttribute(RESOURCE_ELEMENT_TIMESTAMP)); 501 try 502 { 503 def.setBase64(base64); 504 } 505 catch (UnsupportedEncodingException e) 506 { 507 throw new DjenericException(e); 508 } 509 result.add(def); 510 } 511 } 512 } 513 _allResources = (ResourceDefinition[]) result.toArray(new ResourceDefinition[0]); 514 515 _allResourcesHashed = new HashMap (); 516 517 for (int i = 0; i < _allResources.length; i++) 518 { 519 _allResourcesHashed.put(_allResources[i].getAbsolutePath(), _allResources[i]); 520 } 521 522 return _allResources; 523 } 524 525 public ScriptDefinition[] getScripts(JFrame mainWindow) throws DjenericException 526 { 527 if (_allScripts != null) return _allScripts; 528 529 NodeList scriptElements = _xmlDoc.getElementsByTagName(SCRIPT_ELEMENT); 530 ArrayList result = new ArrayList (); 531 532 if (scriptElements != null) 533 { 534 for (int t = 0; t < scriptElements.getLength(); t++) 535 { 536 if (scriptElements.item(t) instanceof Element ) 537 { 538 Element e = (Element ) (scriptElements.item(t)); 539 ScriptDefinition def = createScriptDefinition(e); 540 result.add(def); 541 } 542 } 543 } 544 _allScripts = (ScriptDefinition[]) result.toArray(new ScriptDefinition[0]); 545 546 return _allScripts; 547 } 548 549 protected ScriptDefinition createScriptDefinition(Element scriptElement) throws DjenericException 550 { 551 String base64 = ""; 552 553 NodeList nl = scriptElement.getChildNodes(); 554 for (int x = 0; x < nl.getLength(); x++) 555 { 556 if (nl.item(x) instanceof CDATASection ) 557 { 558 CDATASection d = (CDATASection ) nl.item(x); 559 base64 = d.getData(); 560 } 561 } 562 563 ScriptDefinition def = new ScriptDefinition(); 564 def.setTitle(scriptElement.getAttribute(SCRIPT_ELEMENT_TITLE)); 565 try 566 { 567 def.setBase64(base64); 568 } 569 catch (UnsupportedEncodingException e) 570 { 571 throw new DjenericException(e); 572 } 573 return def; 574 } 575 576 public ResourceDefinition getResource(String absPath) throws DjenericException 577 { 578 if (_allResourcesHashed == null) getResources(); 579 580 ResourceDefinition result = (ResourceDefinition) _allResourcesHashed.get(absPath); 581 return result; 582 } 583 584 public int getViewStructureVersion() 585 { 586 Element view = (Element ) _xmlDoc.getElementsByTagName(VIEW).item(0); 587 String version = view.getAttribute(VIEW_STRUCTURE_VERSION); 588 589 if (version == null || version.trim().length() == 0) version = "100"; 590 591 return Integer.parseInt(version); 592 } 593 594 600 public boolean isVersionSafeToSave() 601 { 602 return getViewStructureVersion() <= VIEW_STRUCTURE_VERSION_NUMBER; 603 } 604 605 protected EditorDefinition createEditor(DjPersistenceManager mgr, Element editorElement) throws DjenericException 606 { 607 EditorDefinition result = null; 608 609 ExtentUsage structure = createEditorStructure(mgr, null, editorElement); 610 String name = editorElement.getAttribute(EDITOR_NAME); 611 if (structure != null) 612 { 613 if (name == null || name.trim().length() == 0) name = generateEditorname(structure); 614 615 result = new EditorDefinition(name, structure); 616 } 617 else 618 { 619 if (name == null) name = "Invalid editor"; 620 result = new EditorDefinition(name, structure); 621 } 622 623 String customClassName = editorElement.getAttribute(EDITOR_CUSTOMCLASS); 624 result.setCustomEditorClass(customClassName); 625 626 NodeList scriptElements = editorElement.getElementsByTagName(EDITOR_EMBEDDED_SCRIPT); 627 628 if (scriptElements != null) 629 { 630 for (int t = 0; t < scriptElements.getLength(); t++) 631 { 632 if (scriptElements.item(t) instanceof Element ) 633 { 634 Element e = (Element ) (scriptElements.item(t)); 635 result.setScriptDefinition(createScriptDefinition(e)); 636 } 637 } 638 } 639 return result; 640 } 641 642 protected String generateEditorname(ExtentUsage structure) 643 { 644 return structure.getExtent().getName() + "Editor"; 645 } 646 647 protected ExtentUsage createEditorStructure(DjPersistenceManager mgr, ExtentUsage parent, Element parentElement) 648 throws CatalogException 649 { 650 ExtentUsage result = null; 651 652 NodeList extentList = parentElement.getChildNodes(); 653 for (int i = 0; i < extentList.getLength(); i++) 654 { 655 if (extentList.item(i) instanceof Element ) 656 { 657 Element usageElement = (Element ) (extentList.item(i)); 658 if (usageElement.getNodeName().equals(EDITOR_EXTENT_USAGE_ELEMENT)) 659 { 660 661 DjExtent tab = findExtent(mgr, usageElement.getAttribute(NAVIGATOR_EXTENTNODE_NAME), usageElement 662 .getAttribute(NAVIGATOR_EXTENTNODE_ALIAS), usageElement.getAttribute(NAVIGATOR_EXTENTNODE_TYPE)); 663 if (tab == null) 664 { 665 DjLogger.log(Messages.getString("DjenericDocumentHandler.ExtentRemovedFromEditor", usageElement 666 .getAttribute(NAVIGATOR_EXTENTNODE_NAME))); 667 continue; 668 } 669 ExtentUsage extentUsage = new ExtentUsage(tab); 670 if (result == null) result = extentUsage; 671 672 extentUsage.setTitle(usageElement.getAttribute(NAVIGATOR_EXTENTNODE_TITLE)); 673 extentUsage.setOqlExpression(usageElement.getAttribute(NAVIGATOR_EXTENTNODE_QBE_FILTER)); 674 extentUsage.setId(usageElement.getAttribute(NAVIGATOR_EXTENTNODE_ID)); 675 extentUsage.setEditAllowed(convert2bool(usageElement.getAttribute(NAVIGATOR_EXTENTNODE_EDIT))); 676 extentUsage.setInsertAllowed(convert2bool(usageElement.getAttribute(NAVIGATOR_EXTENTNODE_INSERT))); 677 extentUsage.setDeleteAllowed(convert2bool(usageElement.getAttribute(NAVIGATOR_EXTENTNODE_DELETE))); 678 extentUsage.setMultiRow(convert2bool(usageElement.getAttribute(EDITOR_MULTIROW))); 679 extentUsage.setRowsDisplayed(convert2Int(usageElement.getAttribute(EDITOR_ROWSDISPLAYED))); 680 681 addPropertyUsages(extentUsage, usageElement); 682 683 createEditorStructure(mgr, extentUsage, usageElement); 684 685 if (parent != null) 686 { 687 String via = usageElement.getAttribute(NAVIGATOR_EXTENTNODE_VIA); 688 String detailProperty = usageElement.getAttribute(NAVIGATOR_EXTENTNODE_DETAIL_COLUMN); 689 DjRelation rel = findRelation(parent.getExtent(), tab, via, detailProperty); 690 if (rel == null) 691 { 692 DjLogger.log(Messages.getString("DjenericDocumentHandler.RelationRemoved", usageElement 693 .getAttribute(NAVIGATOR_EXTENTNODE_VIA), parent.getExtent().getName(), tab.getName())); 694 continue; 695 } 696 parent.addDetail(extentUsage, rel); 697 } 698 } 699 } 700 } 701 return result; 702 } 703 704 protected void addPropertyUsages(ExtentUsage extentUsage, Element extentUsageElement) throws CatalogException 705 { 706 NodeList cuList = extentUsageElement.getChildNodes(); 707 for (int i = 0; i < cuList.getLength(); i++) 708 { 709 if (cuList.item(i) instanceof Element ) 710 { 711 Element cu = (Element ) (cuList.item(i)); 712 if (cu.getNodeName().equals(EDITOR_PROPERTY_USAGE_ELEMENT)) 713 { 714 try 715 { 716 DjProperty prop = extentUsage.getExtent().getProperty(cu.getAttribute(EDITOR_PROPERTY_USAGE_COLUMN)); 717 PropertyUsage columnUsage = new PropertyUsage(prop); 718 columnUsage.setSeq(convert2Int(cu.getAttribute(EDITOR_PROPERTY_USAGE_SEQ))); 719 columnUsage.setPrompt(cu.getAttribute(EDITOR_PROPERTY_USAGE_PROMPT)); 720 columnUsage.setDescription(cu.getAttribute(EDITOR_PROPERTY_USAGE_DESCRIPTION)); 721 columnUsage.setComponentType(cu.getAttribute(EDITOR_PROPERTY_USAGE_COMPONENT)); 722 columnUsage.setRequired(convert2bool(cu.getAttribute(EDITOR_PROPERTY_USAGE_REQUIRED))); 723 columnUsage.setUpdateable(convert2bool(cu.getAttribute(EDITOR_PROPERTY_USAGE_UPDATEABLE))); 724 columnUsage.setDisplayWidth(convert2Int(cu.getAttribute(EDITOR_PROPERTY_USAGE_WIDTH))); 725 columnUsage.setDisplayHeight(convert2Int(cu.getAttribute(EDITOR_PROPERTY_USAGE_HEIGHT))); 726 columnUsage.setSortOrder(convert2Int(cu.getAttribute(EDITOR_PROPERTY_USAGE_SORT_ORDER))); 727 columnUsage.setQueryable(convert2bool(cu.getAttribute(EDITOR_PROPERTY_USAGE_QUERYABLE))); 728 columnUsage.setDisplayed(convert2bool(cu.getAttribute(EDITOR_PROPERTY_USAGE_DISPLAYED), true)); 729 columnUsage.setDefaultValue(cu.getAttribute(EDITOR_PROPERTY_USAGE_DEFAULT_VALUE)); 730 columnUsage.setCustomEditorClass(cu.getAttribute(EDITOR_PROPERTY_USAGE_CUSTOM_EDITOR)); 731 columnUsage.setRelativePath(cu.getAttribute(EDITOR_PROPERTY_USAGE_RELATIVE_PATH)); 732 733 extentUsage.addPropertyUsage(columnUsage); 734 } 735 catch (ObjectNotDefinedException x) 736 { 737 DjLogger.log(Messages.getString("DjenericDocumentHandler.PropertyRemoved", cu 738 .getAttribute(EDITOR_PROPERTY_USAGE_COLUMN), extentUsage.getExtent().getName())); 739 } 740 } 741 } 742 } 743 extentUsage.sortPropertyUsages(); 744 } 745 } | Popular Tags |