public void exportIntroductionPuzzle(IntroductionPuzzle puzzle, OutputStream os)
      throws TransformerException, ParserConfigurationException {

    Document xmlDoc;
    synchronized (
        mDocumentBuilder) { // TODO: Figure out whether the DocumentBuilder is maybe synchronized
                            // anyway
      xmlDoc = mDOM.createDocument(null, WebOfTrust.WOT_NAME, null);
    }

    // 1.0 does not support all Unicode characters which the String class supports. To prevent us
    // from having to filter all Strings, we use 1.1
    xmlDoc.setXmlVersion("1.1");

    Element rootElement = xmlDoc.getDocumentElement();

    // We include the WoT version to have an easy way of handling bogus XML which might be created
    // by bugged versions.
    rootElement.setAttribute("Version", Long.toString(Version.getRealVersion()));

    Element puzzleElement = xmlDoc.createElement("IntroductionPuzzle");
    puzzleElement.setAttribute(
        "Version",
        Integer.toString(INTRODUCTION_XML_FORMAT_VERSION)); /* Version of the XML format */

    // This lock is actually not necessary because all values which are taken from the puzzle are
    // final. We leave it here just to make sure that it does
    // not get lost if it becomes necessary someday.
    synchronized (puzzle) {
      puzzleElement.setAttribute("ID", puzzle.getID());
      puzzleElement.setAttribute("Type", puzzle.getType().toString());
      puzzleElement.setAttribute("MimeType", puzzle.getMimeType());
      synchronized (mDateFormat) {
        puzzleElement.setAttribute("ValidUntil", mDateFormat.format(puzzle.getValidUntilDate()));
      }

      Element dataElement = xmlDoc.createElement("Data");
      dataElement.setAttribute("Value", Base64.encodeStandard(puzzle.getData()));
      puzzleElement.appendChild(dataElement);
    }

    rootElement.appendChild(puzzleElement);

    DOMSource domSource = new DOMSource(xmlDoc);
    StreamResult resultStream = new StreamResult(os);
    synchronized (mSerializer) {
      mSerializer.transform(domSource, resultStream);
    }
  }
  public void exportIntroduction(OwnIdentity identity, OutputStream os)
      throws TransformerException {
    Document xmlDoc;
    synchronized (
        mDocumentBuilder) { // TODO: Figure out whether the DocumentBuilder is maybe synchronized
                            // anyway
      xmlDoc = mDOM.createDocument(null, WebOfTrust.WOT_NAME, null);
    }

    // 1.0 does not support all Unicode characters which the String class supports. To prevent us
    // from having to filter all Strings, we use 1.1
    xmlDoc.setXmlVersion("1.1");

    Element rootElement = xmlDoc.getDocumentElement();

    // We include the WoT version to have an easy way of handling bogus XML which might be created
    // by bugged versions.
    rootElement.setAttribute("Version", Long.toString(Version.getRealVersion()));

    Element introElement = xmlDoc.createElement("IdentityIntroduction");
    introElement.setAttribute(
        "Version", Integer.toString(XML_FORMAT_VERSION)); /* Version of the XML format */

    Element identityElement = xmlDoc.createElement("Identity");
    // synchronized(mWoT) { // Not necessary according to JavaDoc of identity.getRequestURI()
    identityElement.setAttribute("URI", identity.getRequestURI().toString());
    // }
    introElement.appendChild(identityElement);

    rootElement.appendChild(introElement);

    DOMSource domSource = new DOMSource(xmlDoc);
    StreamResult resultStream = new StreamResult(os);
    synchronized (
        mSerializer) { // TODO: Figure out whether the Serializer is maybe synchronized anyway
      mSerializer.transform(domSource, resultStream);
    }
  }
  public void exportOwnIdentity(OwnIdentity identity, OutputStream os) throws TransformerException {
    Document xmlDoc;
    synchronized (
        mDocumentBuilder) { // TODO: Figure out whether the DocumentBuilder is maybe synchronized
                            // anyway
      xmlDoc = mDOM.createDocument(null, WebOfTrust.WOT_NAME, null);
    }

    // 1.0 does not support all Unicode characters which the String class supports. To prevent us
    // from having to filter all Strings, we use 1.1
    xmlDoc.setXmlVersion("1.1");

    Element rootElement = xmlDoc.getDocumentElement();

    // We include the WoT version to have an easy way of handling bogus XML which might be created
    // by bugged versions.
    rootElement.setAttribute("Version", Long.toString(Version.getRealVersion()));

    /* Create the identity Element */

    Element identityElement = xmlDoc.createElement("Identity");
    identityElement.setAttribute(
        "Version", Integer.toString(XML_FORMAT_VERSION)); /* Version of the XML format */

    synchronized (mWoT) {
      identityElement.setAttribute("Name", identity.getNickname());
      identityElement.setAttribute(
          "PublishesTrustList", Boolean.toString(identity.doesPublishTrustList()));

      /* Create the context Elements */

      for (String context : identity.getContexts()) {
        Element contextElement = xmlDoc.createElement("Context");
        contextElement.setAttribute("Name", context);
        identityElement.appendChild(contextElement);
      }

      /* Create the property Elements */

      for (Entry<String, String> property : identity.getProperties().entrySet()) {
        Element propertyElement = xmlDoc.createElement("Property");
        propertyElement.setAttribute("Name", property.getKey());
        propertyElement.setAttribute("Value", property.getValue());
        identityElement.appendChild(propertyElement);
      }

      /* Create the trust list Element and its trust Elements */

      if (identity.doesPublishTrustList()) {
        Element trustListElement = xmlDoc.createElement("TrustList");

        int trustCount = 0;
        for (Trust trust : mWoT.getGivenTrustsSortedDescendingByLastSeen(identity)) {
          if (++trustCount > MAX_IDENTITY_XML_TRUSTEE_AMOUNT) {
            Logger.normal(
                this,
                "Amount of trustees exceeded "
                    + MAX_IDENTITY_XML_TRUSTEE_AMOUNT
                    + ", not adding any more to trust list of "
                    + identity);
            break;
          }

          /* We should make very sure that we do not reveal the other own identity's */
          if (trust.getTruster() != identity)
            throw new RuntimeException(
                "Error in WoT: It is trying to export trust values of someone else in the trust list "
                    + "of "
                    + identity
                    + ": Trust value from "
                    + trust.getTruster()
                    + "");

          Element trustElement = xmlDoc.createElement("Trust");
          trustElement.setAttribute("Identity", trust.getTrustee().getRequestURI().toString());
          trustElement.setAttribute("Value", Byte.toString(trust.getValue()));
          trustElement.setAttribute("Comment", trust.getComment());
          trustListElement.appendChild(trustElement);
        }
        identityElement.appendChild(trustListElement);
      }
    }

    rootElement.appendChild(identityElement);

    DOMSource domSource = new DOMSource(xmlDoc);
    StreamResult resultStream = new StreamResult(os);
    synchronized (
        mSerializer) { // TODO: Figure out whether the Serializer is maybe synchronized anyway
      mSerializer.transform(domSource, resultStream);
    }
  }
 @Override
 public long getRealVersion() {
   return Version.getRealVersion();
 }