コード例 #1
0
  protected CMDocument getCorrespondingCMDocument(Node node, boolean getDocumentFromCMNode) {
    CMDocument result = null;
    try {
      Document document =
          node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument();

      String[] doctypeInfo = getDoctypeInfo(document);

      if (doctypeInfo != null) {
        result = getCMDocument(doctypeInfo[0], doctypeInfo[1], "DTD"); // $NON-NLS-1$
      }
      // defect 211236 ... in some cases calling this method can result in a cycle
      // we use the getDocumentFromCMNode as a flag to avoid this
      // TODO... see if there is a way to re-organize to avoid the need for this flag
      else if (getDocumentFromCMNode) {
        CMNode cmNode = getCMNode(node);
        if (cmNode != null) {
          // todo... add a getCMDocument() methods to CMNode
          // for now use the getProperty interface
          result = (CMDocument) cmNode.getProperty("CMDocument"); // $NON-NLS-1$
        }
      }
    } catch (Exception e) {
      Logger.logException("exception locating CMDocument for " + node, e); // $NON-NLS-1$
    }
    return result;
  }
コード例 #2
0
  protected CMElementDeclaration getCMElementDeclaration(
      Element targetElement, List list, String publicId, String systemId) {
    CMElementDeclaration currentED = null;
    try {
      int listSize = list.size();
      for (int i = 0; i < listSize; i++) {
        Element element = (Element) list.get(i);

        final String nodeName = element.getNodeName();

        CMElementDeclaration ed = null;

        // see if the element is a local of the currentED
        //
        if (currentED != null) {
          ed = (CMElementDeclaration) currentED.getLocalElements().getNamedItem(nodeName);
        }

        if (ed == null) {
          CMDocument cmDocument = getCMDocument(publicId, systemId, "XSD"); // $NON-NLS-1$
          if (cmDocument != null) {
            ed = (CMElementDeclaration) cmDocument.getElements().getNamedItem(nodeName);
          }
        }
        currentED = ed;
      }
    } catch (Exception e) {
      Logger.logException(
          "exception locating element declaration for " + targetElement, e); // $NON-NLS-1$
    }

    return currentED;
  }
  public CommentElementHandler getHandler() {
    if (fHandler == null) {
      if (fElement != null) {
        try {
          if (isCustom()) {
            fHandler =
                (CommentElementHandler) fElement.createExecutableExtension("class"); // $NON-NLS-1$
          } else {
            String elementName = getProperty("elementname"); // $NON-NLS-1$
            if (elementName != null) {
              fHandler = new BasicCommentElementHandler(elementName, fEmpty);
            }
          }
          //
          //	((AbstractCommentElementHandler)fHandler).setElementPrefix(fElement.getAttribute("prefix"));
        } catch (Exception e) {
          // catch and log (and ignore) ANY exception created
          // by executable extension.
          Logger.logException(e);
          fHandler = null;
        }
      }
      if (fHandler == null) {
        fHandler =
            new CommentElementHandler() {
              public Element createElement(Document document, String data, boolean isJSPTag) {
                return null;
              }

              public String generateEndTagContent(IDOMElement element) {
                return null;
              }

              public String generateStartTagContent(IDOMElement element) {
                return null;
              }

              // removed in RC2, ro removed "unused" error/warning
              //					public String getElementPrefix() {
              //						return null;
              //					}

              public boolean isCommentElement(IDOMElement element) {
                return false;
              }

              public boolean isEmpty() {
                return false;
              }
            };
      }
    }
    return fHandler;
  }
コード例 #4
0
  protected CMElementDeclaration getCMElementDeclaration(
      Element targetElement, List list, NamespaceTable namespaceTable) {
    CMElementDeclaration currentED = null;
    try {
      int listSize = list.size();
      for (int i = 0; i < listSize; i++) {
        Element element = (Element) list.get(i);

        if (i != 0) {
          namespaceTable.addElement(element);
        }

        String nodeName = element.getNodeName();
        String unprefixedName = DOMNamespaceHelper.getUnprefixedName(nodeName);
        String prefix = DOMNamespaceHelper.getPrefix(nodeName);

        CMElementDeclaration ed = null;

        // see if the element is a local of the currentED
        //
        if (currentED != null) {
          ed = (CMElementDeclaration) currentED.getLocalElements().getNamedItem(unprefixedName);
        }

        if (ed == null) {
          NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForPrefix(prefix);
          if (namespaceInfo != null) {
            CMDocument cmDocument =
                getCMDocument(namespaceInfo.uri, namespaceInfo.locationHint, "XSD"); // $NON-NLS-1$
            if (cmDocument != null) {
              ed = (CMElementDeclaration) cmDocument.getElements().getNamedItem(unprefixedName);
            }
          }
        }
        currentED = ed;

        // handle XSIType
        if (currentED != null) {
          CMElementDeclaration derivedED =
              getDerivedCMElementDeclaration(element, currentED, namespaceTable);
          if (derivedED != null) {
            currentED = derivedED;
          }
        }
      }
    } catch (Exception e) {
      Logger.logException(
          "exception locating element declaration for " + targetElement, e); // $NON-NLS-1$
    }

    return currentED;
  }
コード例 #5
0
 public static void loadAnnotationsForGrammar(String publicId, CMDocument cmDocument) {
   List annotationFiles = ContentModelManager.getInstance().getAnnotationFilesInfos(publicId);
   AnnotationMap map = (AnnotationMap) cmDocument.getProperty("annotationMap"); // $NON-NLS-1$
   if (map != null) {
     synchronized (annotationFiles) {
       for (Iterator i = annotationFiles.iterator(); i.hasNext(); ) {
         try {
           AnnotationFileInfo annotationFileInfo = (AnnotationFileInfo) i.next();
           AnnotationFileParser parser = new AnnotationFileParser();
           parser.parse(map, annotationFileInfo);
         } catch (Exception e) {
           Logger.logException(e);
         }
       }
     }
   }
 }