code: public Map<String, String> getDocumentMetadata(InputStream docIS) {
          Map<String, String> metadata = new HashMap<String, String>();
  
          try {
              // Create instance of DocumentBuilderFactory
              DocumentBuilderFactory factory =
                      DocumentBuilderFactory.newInstance();
              // Get the DocumentBuilder
              DocumentBuilder docBuilder = factory.newDocumentBuilder();
              // Create blank DOM Document and parse contents of input stream
              Document doc = docBuilder.parse(docIS);
  
              NodeList nodes = null;
  
              metadata.put("PolicyId", doc.getDocumentElement()
                      .getAttribute("PolicyId"));
  
              nodes = doc.getElementsByTagName("Subjects");
              if (nodes.getLength() == 0) {
                  metadata.put("anySubject", "T");
              }
  
              nodes = doc.getElementsByTagName("Resources");
              if (nodes.getLength() == 0) {
                  metadata.put("anyResource", "T");
              }
  
              nodes = doc.getElementsByTagName("Actions");
              if (nodes.getLength() == 0) {
                  metadata.put("anyAction", "T");
              }
  
              nodes = doc.getElementsByTagName("Environments");
              if (nodes.getLength() == 0) {
                  metadata.put("anyEnvironment", "T");
              }
          } catch (Exception e) {
              log.error(e.getMessage());
          }
  
          return metadata;
      }
docs: Obtains the metadata for the given document.
  
  @param docIS
  the document as an InputStream
  @return the document metadata as a Map