예제 #1
0
 /**
  * This method returns the original document appended with an XML signature element, if it exists.
  * Before an advertisement is signed, the method returns the original document. After the
  * advertisement is signed successfully, the method returns the original document appended with a
  * valid XML signature element. For a newly discovered advertisement, the method may return the
  * original document with or without an XML signature element attached, depending on whether the
  * original publisher has signed it or not. If there is an XML signature attached, the verify()
  * method must return true before you can trust the advertisement.
  *
  * <p>When the XML signature element is not attached, the method is equivalent to
  * getDocument(MimeMediaType.XMLUTF8).
  *
  * <p>The abstract method getDocument(MimeMediaType asMimeType) is used only for the subclass to
  * implement the advertisement. The getSignedDocument() is used whenever you want to get the
  * document out of the advertisement.
  *
  * @return The document with an XML signature, if it exists.
  */
 public final synchronized Document getSignedDocument() {
   if (this.xmlSignatureInfoElement == null || this.xmlSignatureElement == null) {
     return this.getDocument(MimeMediaType.XMLUTF8);
   } else {
     XMLDocument tempDoc = (XMLDocument) this.getDocument(MimeMediaType.XMLUTF8);
     StructuredDocumentUtils.copyElements(
         tempDoc, tempDoc.getRoot(), this.xmlSignatureInfoElement);
     StructuredDocumentUtils.copyElements(tempDoc, tempDoc.getRoot(), this.xmlSignatureElement);
     return tempDoc;
   }
 }
예제 #2
0
  /**
   * Return a string representation of this advertisement. The string will contain the advertisement
   * pretty-print formatted as a UTF-8 encoded XML Document.
   *
   * @return A String containing the advertisement.
   */
  @Override
  public String toString() {
    XMLDocument doc = (XMLDocument) getDocument(MimeMediaType.XMLUTF8);

    // Force pretty printing
    doc.addAttribute("xml:space", "default");

    if (this.xmlSignatureInfoElement == null || this.xmlSignatureElement == null) {
      // Not signature available.
    } else {
      StructuredDocumentUtils.copyElements(doc, doc.getRoot(), this.xmlSignatureInfoElement);
      StructuredDocumentUtils.copyElements(doc, doc.getRoot(), this.xmlSignatureElement);
    }

    return doc.toString();
  }