@Nullable
  private static RunContentDescriptor chooseReuseContentForDescriptor(
      final ContentManager contentManager, final RunContentDescriptor descriptor) {
    Content content = null;
    if (descriptor != null) {
      if (descriptor.isContentReuseProhibited()) {
        return null;
      }
      final Content attachedContent = descriptor.getAttachedContent();
      if (attachedContent != null && attachedContent.isValid()) content = attachedContent;
    }
    if (content == null) {
      content = contentManager.getSelectedContent();
      if (content != null && content.isPinned()) content = null;
    }
    if (content == null || !isTerminated(content)) {
      return null;
    }
    final RunContentDescriptor oldDescriptor = getRunContentDescriptorByContent(content);
    if (oldDescriptor != null && !oldDescriptor.isContentReuseProhibited()) {
      return oldDescriptor;
    }

    return null;
  }
 @Override
 public boolean serialize(final ByteBuffer buffer) {
   if (this.contents.size() > 65535) {
     return false;
   }
   buffer.putShort((short) this.contents.size());
   for (int i = 0; i < this.contents.size(); ++i) {
     final Content contents_element = this.contents.get(i);
     final boolean contents_element_ok = contents_element.serialize(buffer);
     if (!contents_element_ok) {
       return false;
     }
   }
   if (this.contentsSelection != null) {
     buffer.put((byte) 1);
     final boolean contentsSelection_ok = this.contentsSelection.serialize(buffer);
     if (!contentsSelection_ok) {
       return false;
     }
   } else {
     buffer.put((byte) 0);
   }
   if (this.buyableContents.size() > 65535) {
     return false;
   }
   buffer.putShort((short) this.buyableContents.size());
   for (int i = 0; i < this.buyableContents.size(); ++i) {
     final BuyableContent buyableContents_element = this.buyableContents.get(i);
     final boolean buyableContents_element_ok = buyableContents_element.serialize(buffer);
     if (!buyableContents_element_ok) {
       return false;
     }
   }
   return true;
 }
 public final void internalToString(final StringBuilder repr, final String prefix) {
   repr.append(prefix).append("contents=");
   if (this.contents.isEmpty()) {
     repr.append("{}").append('\n');
   } else {
     repr.append("(").append(this.contents.size()).append(" elements)...\n");
     for (int i = 0; i < this.contents.size(); ++i) {
       final Content contents_element = this.contents.get(i);
       contents_element.internalToString(repr, prefix + i + "/ ");
     }
   }
   repr.append(prefix).append("contentsSelection=");
   if (this.contentsSelection == null) {
     repr.append("{}").append('\n');
   } else {
     repr.append("...\n");
     this.contentsSelection.internalToString(repr, prefix + "  ");
   }
   repr.append(prefix).append("buyableContents=");
   if (this.buyableContents.isEmpty()) {
     repr.append("{}").append('\n');
   } else {
     repr.append("(").append(this.buyableContents.size()).append(" elements)...\n");
     for (int i = 0; i < this.buyableContents.size(); ++i) {
       final BuyableContent buyableContents_element = this.buyableContents.get(i);
       buyableContents_element.internalToString(repr, prefix + i + "/ ");
     }
   }
 }
  /**
   * Sets the values of the properties of a specific <tt>ColibriConferenceIQ</tt> to the values of
   * the respective properties of this instance. Thus, the specified <tt>iq</tt> may be thought of
   * as a description of this instance.
   *
   * <p><b>Note</b>: The copying of the values is deep i.e. the <tt>Contents</tt>s of this instance
   * are described in the specified <tt>iq</tt>.
   *
   * @param iq the <tt>ColibriConferenceIQ</tt> to set the values of the properties of this instance
   *     on
   */
  public void describeDeep(ColibriConferenceIQ iq) {
    describeShallow(iq);

    if (isRecording()) {
      ColibriConferenceIQ.Recording recordingIQ =
          new ColibriConferenceIQ.Recording(State.ON.toString());
      recordingIQ.setDirectory(getRecordingDirectory());
      iq.setRecording(recordingIQ);
    }
    for (Content content : getContents()) {
      ColibriConferenceIQ.Content contentIQ = iq.getOrCreateContent(content.getName());

      for (Channel channel : content.getChannels()) {
        if (channel instanceof SctpConnection) {
          ColibriConferenceIQ.SctpConnection sctpConnectionIQ =
              new ColibriConferenceIQ.SctpConnection();

          channel.describe(sctpConnectionIQ);
          contentIQ.addSctpConnection(sctpConnectionIQ);
        } else {
          ColibriConferenceIQ.Channel channelIQ = new ColibriConferenceIQ.Channel();

          channel.describe(channelIQ);
          contentIQ.addChannel(channelIQ);
        }
      }
    }
  }
 /**
  * Add the modifier and type for the member in the member summary.
  *
  * @param member the member to add the type for
  * @param type the type to add
  * @param tdSummaryType the content tree to which the modified and type will be added
  */
 protected void addModifierAndType(ProgramElementDoc member, Type type, Content tdSummaryType) {
   HtmlTree code = new HtmlTree(HtmlTag.CODE);
   addModifier(member, code);
   if (type == null) {
     if (member.isClass()) {
       code.addContent("class");
     } else {
       code.addContent("interface");
     }
     code.addContent(writer.getSpace());
   } else {
     if (member instanceof ExecutableMemberDoc
         && ((ExecutableMemberDoc) member).typeParameters().length > 0) {
       Content typeParameters =
           ((AbstractExecutableMemberWriter) this).getTypeParameters((ExecutableMemberDoc) member);
       code.addContent(typeParameters);
       // Code to avoid ugly wrapping in member summary table.
       if (typeParameters.charCount() > 10) {
         code.addContent(new HtmlTree(HtmlTag.BR));
       } else {
         code.addContent(writer.getSpace());
       }
       code.addContent(
           writer.getLink(
               new LinkInfoImpl(configuration, LinkInfoImpl.Kind.SUMMARY_RETURN_TYPE, type)));
     } else {
       code.addContent(
           writer.getLink(
               new LinkInfoImpl(configuration, LinkInfoImpl.Kind.SUMMARY_RETURN_TYPE, type)));
     }
   }
   tdSummaryType.addContent(code);
 }
  /**
   * Notifies this <tt>Conference</tt> that the ordered list of <tt>Endpoint</tt>s of {@link
   * #speechActivity} i.e. the dominant speaker history has changed.
   *
   * <p>This instance notifies the video <tt>Channel</tt>s about the change so that they may update
   * their last-n lists and report to this instance which <tt>Endpoint</tt>s are to be asked for
   * video keyframes.
   */
  private void speechActivityEndpointsChanged() {
    List<Endpoint> endpoints = null;

    for (Content content : getContents()) {
      if (MediaType.VIDEO.equals(content.getMediaType())) {
        Set<Endpoint> endpointsToAskForKeyframes = null;

        endpoints = speechActivity.getEndpoints();
        for (Channel channel : content.getChannels()) {
          if (!(channel instanceof RtpChannel)) continue;

          RtpChannel rtpChannel = (RtpChannel) channel;
          List<Endpoint> channelEndpointsToAskForKeyframes =
              rtpChannel.speechActivityEndpointsChanged(endpoints);

          if ((channelEndpointsToAskForKeyframes != null)
              && !channelEndpointsToAskForKeyframes.isEmpty()) {
            if (endpointsToAskForKeyframes == null) {
              endpointsToAskForKeyframes = new HashSet<>();
            }
            endpointsToAskForKeyframes.addAll(channelEndpointsToAskForKeyframes);
          }
        }

        if ((endpointsToAskForKeyframes != null) && !endpointsToAskForKeyframes.isEmpty()) {
          content.askForKeyframes(endpointsToAskForKeyframes);
        }
      }
    }
  }
 /**
  * Build the summaries for the methods that belong to the given class.
  *
  * @param node the XML element that specifies which components to document
  * @param classContentTree content tree to which the documentation will be added
  */
 public void buildSerializableMethods(XMLNode node, Content classContentTree) {
   Content serializableMethodTree = methodWriter.getSerializableMethodsHeader();
   MemberDoc[] members = currentClass.serializationMethods();
   int membersLength = members.length;
   if (membersLength > 0) {
     for (int i = 0; i < membersLength; i++) {
       currentMember = members[i];
       Content methodsContentTree = methodWriter.getMethodsContentHeader((i == membersLength - 1));
       buildChildren(node, methodsContentTree);
       serializableMethodTree.addContent(methodsContentTree);
     }
   }
   if (currentClass.serializationMethods().length > 0) {
     classContentTree.addContent(
         methodWriter.getSerializableMethods(
             configuration.getText("doclet.Serialized_Form_methods"), serializableMethodTree));
     if (currentClass.isSerializable() && !currentClass.isExternalizable()) {
       if (currentClass.serializationMethods().length == 0) {
         Content noCustomizationMsg =
             methodWriter.getNoCustomizationMsg(
                 configuration.getText("doclet.Serializable_no_customization"));
         classContentTree.addContent(
             methodWriter.getSerializableMethods(
                 configuration.getText("doclet.Serialized_Form_methods"), noCustomizationMsg));
       }
     }
   }
 }
 /** {@inheritDoc} */
 protected void addNavDetailLink(boolean link, Content liNav) {
   if (link) {
     liNav.addContent(
         writer.getHyperLink(
             SectionName.CONSTRUCTOR_DETAIL, writer.getResource("doclet.navConstructor")));
   } else {
     liNav.addContent(writer.getResource("doclet.navConstructor"));
   }
 }
 /**
  * Add the deprecated information for the given member.
  *
  * @param member the member being documented.
  * @param contentTree the content tree to which the deprecated information will be added.
  */
 protected void addDeprecatedInfo(ProgramElementDoc member, Content contentTree) {
   Content output =
       (new DeprecatedTaglet()).getTagletOutput(member, writer.getTagletWriterInstance(false));
   if (!output.isEmpty()) {
     Content deprecatedContent = output;
     Content div = HtmlTree.DIV(HtmlStyle.block, deprecatedContent);
     contentTree.addContent(div);
   }
 }
 /** {@inheritDoc} */
 public Content getConstructorDetailsTreeHeader(ClassDoc classDoc, Content memberDetailsTree) {
   memberDetailsTree.addContent(HtmlConstants.START_OF_CONSTRUCTOR_DETAILS);
   Content constructorDetailsTree = writer.getMemberTreeHeader();
   constructorDetailsTree.addContent(writer.getMarkerAnchor(SectionName.CONSTRUCTOR_DETAIL));
   Content heading =
       HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING, writer.constructorDetailsLabel);
   constructorDetailsTree.addContent(heading);
   return constructorDetailsTree;
 }
 @Override
 public int serializedSize() {
   int size = 0;
   size += 2;
   for (int i = 0; i < this.gems.size(); ++i) {
     final Content gems_element = this.gems.get(i);
     size += gems_element.serializedSize();
   }
   return size;
 }
 /**
  * Build the member details contents of the page.
  *
  * @param node the XML element that specifies which components to document
  * @param annotationContentTree the content tree to which the documentation will be added
  */
 public void buildAnnotationTypeMemberDetails(XMLNode node, Content annotationContentTree) {
   Content memberDetailsTree = writer.getMemberTreeHeader();
   buildChildren(node, memberDetailsTree);
   if (memberDetailsTree.isValid()) {
     Content memberDetails = writer.getMemberTreeHeader();
     writer.addAnnotationDetailsMarker(memberDetails);
     memberDetails.addContent(writer.getMemberTree(memberDetailsTree));
     annotationContentTree.addContent(writer.getMemberDetailsTree(memberDetails));
   }
 }
  private int getComponentNumNamed(String s) {
    for (int i = 0; i < getContentManager().getContentCount(); i++) {
      final Content content = getContentManager().getContent(i);
      if (content != null && s.equals(content.getDisplayName())) {
        return i;
      }
    }

    return -1;
  }
  /**
   * Finds a <tt>Channel</tt> of this <tt>Conference</tt> which receives a specific SSRC and is with
   * a specific <tt>MediaType</tt>.
   *
   * @param receiveSSRC the SSRC of a received RTP stream whose receiving <tt>Channel</tt> in this
   *     <tt>Conference</tt> is to be found
   * @param mediaType the <tt>MediaType</tt> of the <tt>Channel</tt> to be found
   * @return the <tt>Channel</tt> in this <tt>Conference</tt> which receives the specified
   *     <tt>ssrc</tt> and is with the specified <tt>mediaType</tt>; otherwise, <tt>null</tt>
   */
  public Channel findChannelByReceiveSSRC(long receiveSSRC, MediaType mediaType) {
    for (Content content : getContents()) {
      if (mediaType.equals(content.getMediaType())) {
        Channel channel = content.findChannelByReceiveSSRC(receiveSSRC);

        if (channel != null) return channel;
      }
    }
    return null;
  }
 @Nullable
 private static Content getRunContentByDescriptor(
     final ContentManager contentManager, final RunContentDescriptor descriptor) {
   final Content[] contents = contentManager.getContents();
   for (final Content content : contents) {
     if (descriptor.equals(content.getUserData(DESCRIPTOR_KEY))) {
       return content;
     }
   }
   return null;
 }
 public final void internalToString(final StringBuilder repr, final String prefix) {
   repr.append(prefix).append("gems=");
   if (this.gems.isEmpty()) {
     repr.append("{}").append('\n');
   } else {
     repr.append("(").append(this.gems.size()).append(" elements)...\n");
     for (int i = 0; i < this.gems.size(); ++i) {
       final Content gems_element = this.gems.get(i);
       gems_element.internalToString(repr, prefix + i + "/ ");
     }
   }
 }
 @Nullable
 private RunContentDescriptor getDescriptorBy(ProcessHandler handler, Executor runnerInfo) {
   ContentManager contentManager = getContentManagerForRunner(runnerInfo);
   Content[] contents = contentManager.getContents();
   for (Content content : contents) {
     RunContentDescriptor runContentDescriptor = content.getUserData(DESCRIPTOR_KEY);
     if (runContentDescriptor.getProcessHandler() == handler) {
       return runContentDescriptor;
     }
   }
   return null;
 }
 public void showRunContent(
     @NotNull final Executor info,
     RunContentDescriptor descriptor,
     RunContentDescriptor contentToReuse) {
   if (contentToReuse != null) {
     final Content attachedContent = contentToReuse.getAttachedContent();
     if (attachedContent.getManager() != null) {
       descriptor.setAttachedContent(attachedContent);
     }
   }
   showRunContent(info, descriptor);
 }
 /**
  * {@inheritDoc}
  *
  * <p>Creates a <tt>TransportManager</tt> instance suitable for an <tt>SctpConnection</tt> (e.g.
  * with 1 component only).
  */
 protected TransportManager createTransportManager(String xmlNamespace) throws IOException {
   if (IceUdpTransportPacketExtension.NAMESPACE.equals(xmlNamespace)) {
     Content content = getContent();
     return new IceUdpTransportManager(
         content.getConference(), isInitiator(), 1 /* num components */, content.getName());
   } else if (RawUdpTransportPacketExtension.NAMESPACE.equals(xmlNamespace)) {
     // TODO: support RawUdp once RawUdpTransportManager is updated
     // return new RawUdpTransportManager(this);
     throw new IllegalArgumentException("Unsupported Jingle transport " + xmlNamespace);
   } else {
     throw new IllegalArgumentException("Unsupported Jingle transport " + xmlNamespace);
   }
 }
 /** Generate the package use list. */
 protected void generatePackageUseFile() throws IOException {
   Content body = getPackageUseHeader();
   HtmlTree div = new HtmlTree(HtmlTag.DIV);
   div.addStyle(HtmlStyle.contentContainer);
   if (usingPackageToUsedClasses.isEmpty()) {
     div.addContent(getResource("doclet.ClassUse_No.usage.of.0", pkgdoc.name()));
   } else {
     addPackageUse(div);
   }
   body.addContent(div);
   addNavLinks(false, body);
   addBottom(body);
   printHtmlDocument(null, true, body);
 }
 @Override
 public boolean unserialize(final ByteBuffer buffer) {
   final int gems_size = buffer.getShort() & 0xFFFF;
   this.gems.clear();
   this.gems.ensureCapacity(gems_size);
   for (int i = 0; i < gems_size; ++i) {
     final Content gems_element = new Content();
     final boolean gems_element_ok = gems_element.unserialize(buffer);
     if (!gems_element_ok) {
       return false;
     }
     this.gems.add(gems_element);
   }
   return true;
 }
 /**
  * Add the package use information.
  *
  * @param pkg the package that used the given package
  * @param contentTree the content tree to which the information will be added
  */
 protected void addPackageUse(PackageDoc pkg, Content contentTree) throws IOException {
   Content tdFirst =
       HtmlTree.TD(
           HtmlStyle.colFirst,
           getHyperLink(Util.getPackageName(pkg), new StringContent(Util.getPackageName(pkg))));
   contentTree.addContent(tdFirst);
   HtmlTree tdLast = new HtmlTree(HtmlTag.TD);
   tdLast.addStyle(HtmlStyle.colLast);
   if (pkg != null && pkg.name().length() != 0) {
     addSummaryComment(pkg, tdLast);
   } else {
     tdLast.addContent(getSpace());
   }
   contentTree.addContent(tdLast);
 }
 /** {@inheritDoc} */
 public Content getSignature(ConstructorDoc constructor) {
   Content pre = new HtmlTree(HtmlTag.PRE);
   writer.addAnnotationInfo(constructor, pre);
   addModifiers(constructor, pre);
   if (configuration.linksource) {
     Content constructorName = new StringContent(constructor.name());
     writer.addSrcLink(constructor, constructorName, pre);
   } else {
     addName(constructor.name(), pre);
   }
   int indent = pre.charCount();
   addParameters(constructor, pre, indent);
   addExceptions(constructor, pre, indent);
   return pre;
 }
 private Content createNewContent(
     final ContentManager contentManager,
     final RunContentDescriptor descriptor,
     Executor executor) {
   final String processDisplayName = descriptor.getDisplayName();
   final Content content =
       ContentFactory.SERVICE
           .getInstance()
           .createContent(descriptor.getComponent(), processDisplayName, true);
   content.putUserData(DESCRIPTOR_KEY, descriptor);
   content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
   contentManager.addContent(content);
   new CloseListener(content, executor);
   return content;
 }
 @Override
 public boolean serialize(final ByteBuffer buffer) {
   if (this.gems.size() > 65535) {
     return false;
   }
   buffer.putShort((short) this.gems.size());
   for (int i = 0; i < this.gems.size(); ++i) {
     final Content gems_element = this.gems.get(i);
     final boolean gems_element_ok = gems_element.serialize(buffer);
     if (!gems_element_ok) {
       return false;
     }
   }
   return true;
 }
  /**
   * Expires this <tt>Conference</tt>, its <tt>Content</tt>s and their respective <tt>Channel</tt>s.
   * Releases the resources acquired by this instance throughout its life time and prepares it to be
   * garbage collected.
   */
  public void expire() {
    synchronized (this) {
      if (expired) return;
      else expired = true;
    }

    EventAdmin eventAdmin = videobridge.getEventAdmin();
    if (eventAdmin != null) eventAdmin.sendEvent(EventFactory.conferenceExpired(this));

    setRecording(false);
    if (recorderEventHandler != null) {
      recorderEventHandler.close();
      recorderEventHandler = null;
    }

    Videobridge videobridge = getVideobridge();

    try {
      videobridge.expireConference(this);
    } finally {
      // Expire the Contents of this Conference.
      for (Content content : getContents()) {
        try {
          content.expire();
        } catch (Throwable t) {
          logger.warn(
              "Failed to expire content " + content.getName() + " of conference " + getID() + "!",
              t);
          if (t instanceof InterruptedException) Thread.currentThread().interrupt();
          else if (t instanceof ThreadDeath) throw (ThreadDeath) t;
        }
      }

      // Close the transportManagers of this Conference. Normally, there
      // will be no TransportManager left to close at this point because
      // all Channels have expired and the last Channel to be removed from
      // a TransportManager closes the TransportManager. However, a
      // Channel may have expired before it has learned of its
      // TransportManager and then the TransportManager will not close.
      closeTransportManagers();

      if (logger.isInfoEnabled()) {
        logger.info(
            "Expired conference " + getID() + ". " + videobridge.getConferenceCountString());
      }
    }
  }
 /**
  * Get the header for the package use listing.
  *
  * @return a content tree representing the package use header
  */
 protected Content getPackageUseHeader() {
   String packageText = configuration.getText("doclet.Package");
   String name = pkgdoc.name();
   String title = configuration.getText("doclet.Window_ClassUse_Header", packageText, name);
   Content bodyTree = getBody(true, getWindowTitle(title));
   addTop(bodyTree);
   addNavLinks(true, bodyTree);
   ContentBuilder headContent = new ContentBuilder();
   headContent.addContent(getResource("doclet.ClassUse_Title", packageText));
   headContent.addContent(new HtmlTree(HtmlTag.BR));
   headContent.addContent(name);
   Content heading =
       HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, HtmlStyle.title, headContent);
   Content div = HtmlTree.DIV(HtmlStyle.header, heading);
   bodyTree.addContent(div);
   return bodyTree;
 }
 /**
  * Build the member summary contents of the page.
  *
  * @param node the XML element that specifies which components to document
  * @param annotationContentTree the content tree to which the documentation will be added
  */
 public void buildMemberSummary(XMLNode node, Content annotationContentTree) throws Exception {
   Content memberSummaryTree = writer.getMemberTreeHeader();
   configuration
       .getBuilderFactory()
       .getMemberSummaryBuilder(writer)
       .buildChildren(node, memberSummaryTree);
   annotationContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree));
 }
 /**
  * Add the navigation summary link.
  *
  * @param members members to be linked
  * @param visibleMemberMap the visible inherited members map
  * @param liNav the content tree to which the navigation summary link will be added
  */
 protected void addNavSummaryLink(
     List<?> members, VisibleMemberMap visibleMemberMap, Content liNav) {
   if (members.size() > 0) {
     liNav.addContent(getNavSummaryLink(null, true));
     return;
   }
   ClassDoc icd = classdoc.superclass();
   while (icd != null) {
     List<?> inhmembers = visibleMemberMap.getMembersFor(icd);
     if (inhmembers.size() > 0) {
       liNav.addContent(getNavSummaryLink(icd, true));
       return;
     }
     icd = icd.superclass();
   }
   liNav.addContent(getNavSummaryLink(null, false));
 }
 public static void showImage(Long id) {
   Content content = Content.findById(id);
   notFoundIfNull(content);
   response.setContentTypeIfNotSet(content.image.type());
   File file = content.image.getFile();
   notFoundIfNull(file);
   renderBinary(file);
 }