Package org.eclipse.wst.xml.core.internal.provisional.document

Examples of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument


   * Mostly copied from HTMLValidator
   */
  private void validate(IReporter reporter, IFile file, IDOMModel model) {
    if (file == null || model == null)
      return; // error
    IDOMDocument document = model.getDocument();
    if (document == null)
      return; // error

    // This validator currently only handles validating HTML content in
    // JSP
View Full Code Here


         * tolerant.
         */
        model = StructuredModelManager.getModelManager().getModelForRead(file);
        monitor.worked(1);
        if (model instanceof IDOMModel) {
          IDOMDocument document = ((IDOMModel) model).getDocument();
          _parseDocument(path, version, groupList, urlPatterns, subMonitor, document);
        }
      }
      catch (Exception e) {
        Logger.logException(e);
View Full Code Here

  /**
   * Returns the CMDocument that corresponds to the DOM Node. or null if no
   * CMDocument is appropriate for the DOM Node.
   */
  public CMDocument getCorrespondingCMDocument(Node node) {
    IDOMDocument owner = getOwnerXMLDocument(node);
    if (owner == null)
      return null;

    String pid = getPublicId(owner);
    // no PID, always return the currently-supported HTML version
View Full Code Here

  /**
   */
  public void setDeclaration(IDOMModel model, String declaration, String publicId) {
    if (model == null)
      return;
    IDOMDocument document = model.getDocument();
    if (document == null)
      return;

    try {
      model.aboutToChangeModel();

      ProcessingInstruction pi = null;
      Node child = document.getFirstChild();
      if (child != null && child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
        String target = child.getNodeName();
        if (target != null && target.equals("xml")) { //$NON-NLS-1$
          pi = (ProcessingInstruction) child;
          child = child.getNextSibling();
        }
      }
      IDOMDocumentType docType = (IDOMDocumentType) document.getDoctype();

      if (declaration != null) {
        if (pi != null) {
          pi.setData(declaration);
        }
        else {
          pi = document.createProcessingInstruction("xml", declaration); //$NON-NLS-1$
          document.insertBefore(pi, child);
          insertBreak(model, child);
        }
      }

      if (publicId != null) {
        HTMLDocumentTypeEntry entry = HTMLDocumentTypeRegistry.getInstance().getEntry(publicId);
        String name = (entry != null ? entry.getName() : null);
        if (name == null || name.length() == 0)
          name = "HTML"; // default //$NON-NLS-1$
        if (docType != null) {
          if (!name.equals(docType.getName())) { // replace
            Node parent = docType.getParentNode();
            child = docType;
            docType = (IDOMDocumentType) document.createDoctype(name);
            parent.insertBefore(docType, child);
            parent.removeChild(child);
          }
        }
        else {
          docType = (IDOMDocumentType) document.createDoctype(name);
          document.insertBefore(docType, child);
          insertBreak(model, child);
        }
        docType.setPublicId(publicId);
        if (entry != null) {
          String systemId = entry.getSystemId();
          if (systemId != null)
            docType.setSystemId(systemId);
          String namespaceURI = entry.getNamespaceURI();
          if (namespaceURI != null) {
            Element element = document.getDocumentElement();
            if (element != null) {
              element.setAttribute("xmlns", namespaceURI); //$NON-NLS-1$
            }
          }
        }
View Full Code Here

  }

  /**
   */
  private void documentTypeChanged() {
    IDOMDocument document = getDocument();
    if (document == null)
      return; // error
    IDOMModel model = document.getModel();
    if (model == null)
      return; // error

    IFile file = getFile(model);

    // find DOCTYPE delcaration and Public ID
    String publicId = null;
    String systemId = null;
    DocumentType newDocumentType = findDocumentType(document);
    if (newDocumentType != null) {
      publicId = newDocumentType.getPublicId();
      systemId = newDocumentType.getSystemId();
    }
    else {
      // lookup default set by contentsettings
      publicId = HTMLContentProperties.getProperty(HTMLContentProperties.DOCUMENT_TYPE, file, true);
    }

    // lookup DOCTYPE registry
    HTMLDocumentTypeEntry newEntry = null;
    if (publicId != null) {
      newEntry = HTMLDocumentTypeRegistry.getInstance().getEntry(publicId);
    }
    else if (systemId == null){
        newEntry = HTMLDocumentTypeRegistry.getInstance().getDefaultEntry(HTMLDocumentTypeRegistry.DEFAULT_HTML5);
    }

    boolean newXMLType = (newEntry != null ? newEntry.isXMLType() : false);
    boolean newWMLType = (newEntry != null ? newEntry.isWMLType() : false);

    if (!newXMLType) {
      // find XML declaration
      if (findXMLNode(document) != null) {
        newXMLType = true;
      }

      // check file extension
      if (file != null) {
        String ext = file.getFileExtension();
        if (ext != null && ext.equalsIgnoreCase(XHTML)) {
          newXMLType = true;
        }

        if (ext != null && ext.equalsIgnoreCase(WML)) {
          newXMLType = true;
          newWMLType = true;
        }
      }

    }

    if (newEntry == null) {
      // lookup system default
      if (newXMLType && newDocumentType == null) {
        // use default XHTML, if it's XML and no document type
        // declared
        if (newWMLType)
          newEntry = HTMLDocumentTypeRegistry.getInstance().getDefaultEntry(HTMLDocumentTypeRegistry.DEFAULT_WML);
        else
          newEntry = HTMLDocumentTypeRegistry.getInstance().getDefaultEntry(HTMLDocumentTypeRegistry.DEFAULT_XHTML);

      }
      else {
        newEntry = HTMLDocumentTypeRegistry.getInstance().getDefaultEntry(HTMLDocumentTypeRegistry.DEFAULT_HTML);
      }
      if (newEntry == null)
        return; // error
    }

    if (newDocumentType == null) {
      DocumentType oldDocumentType = getDocumentType();
      if (oldDocumentType == null || oldDocumentType.getName() != newEntry.getName()) {
        // create implicit DocumentType
        DOMImplementation impl = document.getImplementation();
        if (impl != null) {
          String name = newEntry.getName();
          publicId = newEntry.getPublicId();
          systemId = newEntry.getSystemId();
          newDocumentType = impl.createDocumentType(name, publicId, systemId);
View Full Code Here

    // critical here, the doc must have been created, but its contents not
    // set yet,
    // and all factories must have been set up also.
    IDOMModel domModel = (IDOMModel) model;
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    IDOMDocument document = domModel.getDocument();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getExistingAdapter(PageDirectiveAdapter.class);
    // ==> // PropagatingAdapter propagatingAdapter = (PropagatingAdapter)
    // ((INodeNotifier)
    // document).getExistingAdapter(PropagatingAdapter.class);
    // ==> // ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter)
    // ((INodeNotifier)
View Full Code Here

    // critical here, the doc must have been created, but its contents not
    // set yet,
    // and all factories must have been set up also.
    IDOMModel domModel = (IDOMModel) model;
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    IDOMDocument document = domModel.getDocument();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getAdapterFor(PageDirectiveAdapter.class);
    // ==> // PropagatingAdapter propagatingAdapter = (PropagatingAdapter)
    // ((INodeNotifier) document).getAdapterFor(PropagatingAdapter.class);
    // ==> // ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter)
    // ((INodeNotifier) document).getAdapterFor(ModelQueryAdapter.class);
    // because, even in the clone case, the model has been paritally
View Full Code Here

          }
        }
      }
    }

    IDOMDocument document = domModel.getDocument();
    PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getAdapterFor(PageDirectiveAdapter.class);

    if (embeddedContentType != null) {
      pageDirectiveAdapter.setEmbeddedType(embeddedContentType);
      embeddedContentType.initializeFactoryRegistry(model.getFactoryRegistry());
    }
View Full Code Here

    }
  }

  protected void setLanguageInPageDirective(IStructuredModel newModel) {
    if (newModel instanceof IDOMModel) {
      IDOMDocument document = ((IDOMModel) newModel).getDocument();
      PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getAdapterFor(PageDirectiveAdapter.class);
      String language = getLanguage(newModel);
      pageDirectiveAdapter.setLanguage(language);
    }
  }
View Full Code Here

    // have to be released.

    ModelQueryAdapter modelQueryAdapter = getModelQueryAdapter(model);
    if (modelQueryAdapter == null) {
      modelQueryAdapter = getModelQueryAdapter(oldModel);
      IDOMDocument document = ((IDOMModel) model).getDocument();
      document.addAdapter(new JSPModelQueryAdapterImpl(modelQueryAdapter.getCMDocumentCache(), modelQueryAdapter.getModelQuery(), modelQueryAdapter.getIdResolver()));

    }


View Full Code Here

TOP

Related Classes of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.