Exemple #1
0
  private Param resolveParameter(Param param) {
    String href = param.getHref();
    if (!StringUtils.hasContent(href)) {
      return param;
    }

    try {
      Application app = application;

      if (!href.startsWith("#")) {
        ApplicationDocument applicationDocument = loadReferencedWadl(href);
        app = applicationDocument.getApplication();
      }

      if (app != null) {
        int ix = href.lastIndexOf('#');
        if (ix >= 0) {
          href = href.substring(ix + 1);
        }

        for (Param p : application.getParamList()) {
          if (p.getId().equals(href)) {
            return p;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }
Exemple #2
0
  private ResourceTypeDocument.ResourceType resolveResource(String id) {
    for (ResourceTypeDocument.ResourceType resourceType : application.getResourceTypeList()) {
      if (resourceType.getId().equals(id)) {
        return resourceType;
      }
    }

    try {
      ApplicationDocument applicationDocument = loadReferencedWadl(id);
      if (applicationDocument != null) {
        int ix = id.lastIndexOf('#');
        if (ix > 0) {
          id = id.substring(ix + 1);
        }

        for (ResourceTypeDocument.ResourceType resourceType :
            applicationDocument.getApplication().getResourceTypeList()) {
          if (resourceType.getId().equals(id)) {
            return resourceType;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }
Exemple #3
0
  private Representation resolveRepresentation(Representation representation) {
    String href = representation.getHref();
    if (!StringUtils.hasContent(href)) {
      return representation;
    }

    try {
      Application app = application;

      if (!href.startsWith("#")) {
        ApplicationDocument applicationDocument = loadReferencedWadl(href);
        app = applicationDocument.getApplication();
      }

      if (app != null) {
        int ix = href.lastIndexOf('#');
        if (ix >= 0) {
          href = href.substring(ix + 1);
        }

        for (Representation m : application.getRepresentationList()) {
          if (m.getId().equals(href)) {
            return m;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return representation;
  }
Exemple #4
0
  public void initFromWadl(String wadlUrl) {
    try {
      // XmlObject xmlObject = XmlObject.Factory.parse( new URL( wadlUrl ) );
      XmlObject xmlObject = XmlUtils.createXmlObject(new URL(wadlUrl));

      String content = xmlObject.xmlText();
      Element element = ((Document) xmlObject.getDomNode()).getDocumentElement();

      // try to allow older namespaces
      if (element.getLocalName().equals("application")
          && element.getNamespaceURI().startsWith("http://research.sun.com/wadl")) {
        isWADL11 = false;
        content =
            content.replaceAll(
                "\"" + element.getNamespaceURI() + "\"", "\"" + Constants.WADL11_NS + "\"");
      } else if (!element.getLocalName().equals("application")
          || !element.getNamespaceURI().equals(Constants.WADL11_NS)) {
        throw new Exception(
            "Document is not a WADL application with " + Constants.WADL11_NS + " namespace");
      }
      content = PropertyExpansionRemover.removeExpansions(content);
      ApplicationDocument applicationDocument = ApplicationDocument.Factory.parse(content);
      application = applicationDocument.getApplication();

      resourcesList = application.getResourcesList();

      service.setName(getFirstTitle(application.getDocList(), service.getName()));

      String base = resourcesList.size() == 1 ? resourcesList.get(0).getBase() : "";

      try {
        URL baseUrl = new URL(base);
        service.setBasePath(baseUrl.getPath());

        service.addEndpoint(Tools.getEndpointFromUrl(baseUrl));
      } catch (Exception e) {
        service.setBasePath(base);
      }

      service.setWadlUrl(wadlUrl);
      service.getConfig().setWadlVersion(isWADL11 ? Constants.WADL11_NS : Constants.WADL10_NS);

      for (Resources resources : resourcesList) {
        RestResource baseResource = null;
        if (resourcesList.size() > 1) {
          String path = resources.getBase();
          baseResource = service.addNewResource(path, path);
        }
        for (Resource resource : resources.getResourceList()) {
          String name = getFirstTitle(resource.getDocList(), resource.getPath());
          String path = resource.getPath();

          RestResource newResource = null;

          if (baseResource != null && path != null) {
            for (RestResource res : baseResource.getChildResourceList()) {
              if (path.equals(res.getPath())) {
                newResource = res;
                break;
              }
            }

            if (newResource == null) {
              newResource = baseResource.addNewChildResource(name, path);
            }
          } else if (path != null) {
            for (RestResource res : service.getResourceList()) {
              if (path.equals(res.getPath())) {
                newResource = res;
                break;
              }
            }

            if (newResource == null) {
              newResource = service.addNewResource(name, path);
            }
          } else {
            newResource = service.addNewResource(name, "");
          }

          initResourceFromWadlResource(newResource, resource);
          addSubResources(newResource, resource);
        }
      }
    } catch (InvalidDefinitionException ex) {
      ex.show();
    } catch (Exception e) {
      UISupport.showErrorMessage(e);
    }
  }