private void outputModules(
      StructuredTextDocument doc, Hashtable modulesTable, String mainTag, MimeMediaType encodeAs) {

    Enumeration allClasses = modulesTable.keys();
    while (allClasses.hasMoreElements()) {
      ModuleClassID mcid = (ModuleClassID) allClasses.nextElement();
      Object val = modulesTable.get(mcid);

      // For applications, we ignore the role ID. It is not meaningfull,
      // and a new one is assigned on the fly when loading this adv.

      if (val instanceof Advertisement) {
        TextElement m = doc.createElement(mainTag);
        doc.appendChild(m);

        if (!(modulesTable == appsTable || mcid.equals(mcid.getBaseClass()))) {
          // It is not an app and there is a role ID. Output it.

          TextElement i = doc.createElement(mcidTag, mcid.toString());
          m.appendChild(i);
        }

        StructuredTextDocument advdoc =
            (StructuredTextDocument) ((Advertisement) val).getDocument(encodeAs);

        StructuredDocumentUtils.copyElements(doc, m, advdoc);

      } else if (val instanceof ModuleSpecID) {
        TextElement m;

        if (modulesTable == appsTable || mcid.equals(mcid.getBaseClass())) {

          // Either it is an app or there is no role ID.
          // So the specId is good enough.
          m = doc.createElement(mainTag, ((ModuleSpecID) val).toString());
          doc.appendChild(m);
        } else {
          // The role ID matters, so the classId must be separate.
          m = doc.createElement(mainTag);
          doc.appendChild(m);

          TextElement i;
          i = doc.createElement(mcidTag, mcid.toString());
          m.appendChild(i);

          i = doc.createElement(msidTag, ((ModuleSpecID) val).toString());
          m.appendChild(i);
        }
      } else {
        if (LOG.isEnabledFor(Level.WARN)) LOG.warn("unsupported class in modules table");
      }
    }
  }
Exemple #2
0
  /**
   * return the string representaion of this doc
   *
   * @deprecated should not be used. use getDocument().toString() instead.
   */
  @Override
  @Deprecated
  public String toString() {

    try {
      StructuredTextDocument doc = (StructuredTextDocument) getDocument(MimeMediaType.XMLUTF8);

      return doc.toString();
    } catch (Exception e) {
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      } else {
        throw new UndeclaredThrowableException(e);
      }
    }
  }