// Gets the specified XML Schema doc if one is mentioned in the file
  public static File getSchemaFile(Document xmlDoc) {
    /** @todo Must be an easier way of doing this... */
    logger.logComment("Getting schema file for: " + xmlDoc.getDocumentURI());

    NodeList nl = xmlDoc.getChildNodes();
    for (int j = 0; j < nl.getLength(); j++) {
      Node node = nl.item(j);
      logger.logComment("Type: " + node.getNodeType() + "Name: " + node.getNodeName());
      if (node.getNodeName().equals(XML_STYLESHEET_NODE)) {
        String nodeVal = node.getNodeValue();

        logger.logComment("Looking at: " + nodeVal);
        String xslFileName =
            nodeVal.substring(nodeVal.indexOf("href=\"") + 6, nodeVal.length() - 1);
        File xslFile = new File(xslFileName);
        return xslFile;
      }

      if (node.getAttributes().getLength() > 0) {
        logger.logComment("Attributes: " + node.getAttributes());
        if (node.getAttributes().getNamedItem(XML_SCHEMA_LOC_ATTR) != null) {
          String locString = node.getAttributes().getNamedItem(XML_SCHEMA_LOC_ATTR).getNodeValue();
          logger.logComment("Loc string: " + locString);
          String file = locString.split("\\s")[1];
          return new File(file);
        }
      }
    }
    logger.logError("No node found with name: " + XML_STYLESHEET_NODE);
    return null;
  }
 public String getSystemId() {
   try {
     return sysId == null ? document.getDocumentURI() : sysId;
   } catch (Throwable ex) {
     // ignore, probably not DOM level 3
   }
   return sysId;
 }
Example #3
0
  private Element parseMetadata(
      @NotNull String systemId, @NotNull ServiceDescriptor serviceDescriptor) {
    List<? extends Source> mexWsdls = serviceDescriptor.getWSDLs();
    List<? extends Source> mexSchemas = serviceDescriptor.getSchemas();
    Document root = null;
    for (Source src : mexWsdls) {
      if (src instanceof DOMSource) {
        Node n = ((DOMSource) src).getNode();
        Document doc;
        if (n.getNodeType() == Node.ELEMENT_NODE && n.getOwnerDocument() == null) {
          doc = DOMUtil.createDom();
          doc.importNode(n, true);
        } else {
          doc = n.getOwnerDocument();
        }

        //                Element e = (n.getNodeType() == Node.ELEMENT_NODE)?(Element)n:
        // DOMUtil.getFirstElementChild(n);
        if (root == null) {
          // check if its main wsdl, then set it to root
          NodeList nl =
              doc.getDocumentElement().getElementsByTagNameNS(WSDLConstants.NS_WSDL, "service");
          if (nl.getLength() > 0) {
            root = doc;
            rootWSDL = src.getSystemId();
          }
        }
        NodeList nl =
            doc.getDocumentElement().getElementsByTagNameNS(WSDLConstants.NS_WSDL, "import");
        for (int i = 0; i < nl.getLength(); i++) {
          Element imp = (Element) nl.item(i);
          String loc = imp.getAttribute("location");
          if (loc != null) {
            if (!externalReferences.contains(loc)) externalReferences.add(loc);
          }
        }
        if (core.keySet().contains(systemId)) core.remove(systemId);
        core.put(src.getSystemId(), doc);
        resolvedCache.put(systemId, doc.getDocumentURI());
        isMexMetadata = true;
      }

      // TODO:handle SAXSource
      // TODO:handler StreamSource
    }

    for (Source src : mexSchemas) {
      if (src instanceof DOMSource) {
        Node n = ((DOMSource) src).getNode();
        Element e =
            (n.getNodeType() == Node.ELEMENT_NODE) ? (Element) n : DOMUtil.getFirstElementChild(n);
        inlinedSchemaElements.add(e);
      }
      // TODO:handle SAXSource
      // TODO:handler StreamSource
    }
    return root.getDocumentElement();
  }
Example #4
0
  private FailureLocation getFailureLocation(List<Document> docs, XNode fNode) {
    if (fNode == null) {
      return null;
    }

    XPathUtils xpather = new XPathUtils(fNode.getNSMap());
    for (Document doc : docs) {
      Node node = (Node) xpather.getValue(fNode.toString(), doc, XPathConstants.NODE);
      if (null != node) {
        try {
          return new FailureLocation((Location) node.getUserData("location"), doc.getDocumentURI());
        } catch (Exception ex) {
          // ignore, probably not DOM level 3
        }
      }
    }
    return null;
  }