示例#1
0
文件: XSDUtil.java 项目: NCIP/cagrid2
  /**
   * Loops through the SchemaDocuments in the Schema and returns null or the first which has a
   * matching systemID to the given systemID;
   *
   * @throws IllegalArgumentException if Schema is null or contains no SchemaDocuments
   * @param schema the Schema to search
   * @param systemId the systemID to look for
   * @return the matching SchemaDocuemnt or null
   */
  public static XMLSchemaDocument getSchemaDocumentFromSchema(XMLSchema schema, String systemId) {
    if (schema == null) {
      throw new IllegalArgumentException("Schema must be non null.");
    }
    if (schema.getRootDocument().getSystemID().equals(systemId)) {
      return schema.getRootDocument();
    } else {
      for (XMLSchemaDocument sd : schema.getAdditionalDocuments()) {
        if (sd.getSystemID().equals(systemId)) {
          return sd;
        }
      }
    }

    return null;
  }
示例#2
0
文件: XSDUtil.java 项目: NCIP/cagrid2
  /**
   * Constructs a SchemaDocument with the given file's contents, and uses the filename (not the full
   * path), as the systemID. Note: this does not check that the file actually represents a valid XML
   * Schema.
   *
   * @param schemaFile the file to convert to a schemadocument
   * @return the constructed SchemaDocument
   * @throws java.io.FileNotFoundException if the file is not valid
   * @throws java.io.IOException if the file is not valid
   */
  public static XMLSchemaDocument createSchemaDocument(File schemaFile)
      throws FileNotFoundException, IOException {
    if (schemaFile == null || !schemaFile.canRead()) {
      throw new IllegalArgumentException(
          "schemaFile [" + schemaFile + "] must be a valid, readable file.");
    }

    FileInputStream fileInputStream = new FileInputStream(schemaFile);
    String fileContents = IOUtils.toString(fileInputStream);
    fileInputStream.close();
    String systemID = schemaFile.getName();

    XMLSchemaDocument sd = new XMLSchemaDocument();
    sd.setSchemaText(fileContents);
    sd.setSystemID(systemID);
    return sd;
  }