Java Code Examples for org.osgi.resource.Capability#getAttributes()

The following examples show how to use org.osgi.resource.Capability#getAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NsToHtmlBundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String toHTML(Capability capability)
{
  // Make a modifiable clone of the attributes.
  final Map<String, Object> attrs =
    new HashMap<String, Object>(capability.getAttributes());

  final StringBuffer sb = new StringBuffer(50);
  sb.append(attrs.remove(BundleRevision.BUNDLE_NAMESPACE));

  final Version version =
    (Version) attrs.remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
  if (version != null) {
    sb.append("&nbsp;");
    sb.append(version);
  }

  if (!attrs.isEmpty()) {
    sb.append("&nbsp;");
    sb.append(attrs);
  }

  return sb.toString();
}
 
Example 2
Source File: RepositoryDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * BND generated XML repository files never contains a value for the
 * optional attributes in the identity name space, also look for it in the
 * KF-name space.
 *
 * @param key
 *          Attribute key to look up.
 *
 * @return the attribute value of the resource that this node represents.
 */
private String getIdAttribute(final String key)
{
  for (final Capability idCap : idCaps) {
    final Map<String, Object> attrs = idCap.getAttributes();

    final String description = (String) attrs.remove(key);
    if (description != null && description.length() > 0) {
      return description;
    }
  }
  if (kfExtraCaps != null && kfExtraCaps.size() > 0) {
    return (String) kfExtraCaps.iterator().next().getAttributes()
        .get(key);
  }
  return null;
}
 
Example 3
Source File: NsToHtmlHost.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String toHTML(Capability capability)
{
  // Make a modifiable clone of the attributes.
  final Map<String, Object> attrs =
    new HashMap<String, Object>(capability.getAttributes());

  final StringBuffer sb = new StringBuffer(50);
  sb.append(attrs.remove(BundleRevision.HOST_NAMESPACE));

  final Version version =
    (Version) attrs.remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
  if (version != null) {
    sb.append("&nbsp;");
    sb.append(version);
  }

  if (!attrs.isEmpty()) {
    sb.append("&nbsp;");
    sb.append(attrs);
  }

  return sb.toString();
}
 
Example 4
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get the MIME-type of a repository resource.
 *
 * @param resource
 *          The resource to get the MIME type for.
 *
 * @return Resource MIME type or {@code null} if no MIME-type available.
 */
public static String getResourceMime(Resource resource)
{
  String res = null;
  for (final Capability cap : resource
      .getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) {
    final Map<String, Object> attrs = cap.getAttributes();
    final String mime =
      (String) attrs.get(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE);
    if (mime != null) {
      res = mime;
      break;
    }
  }
  return res;
}
 
Example 5
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get the location to use when installing this resource.
 *
 * If available, the resource URL will be used as the location. Otherwise we
 * simply use the hash code of the resource.
 *
 * @param resource
 *          the resource to determine the installation location for.
 * @return location to use when installing this resource or {@code null} if
 *         location is available for this resource.
 */
public static String getLocation(Resource resource)
{
  for (final Capability cap : resource
      .getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) {
    final Map<String, Object> attrs = cap.getAttributes();
    if (supportedMimeTypes.contains(attrs
        .get(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE))) {
      final String url =
        (String) attrs.get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
      if (url != null) {
        return url;
      }
    }
  }
  return null;
}
 
Example 6
Source File: NsToHtmlEE.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String toHTML(Capability capability)
{
  // Make a modifiable clone of the attributes.
  final Map<String, Object> attrs =
    new HashMap<String, Object>(capability.getAttributes());

  final StringBuffer sb = new StringBuffer(50);
  sb.append(attrs
      .remove(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE));

  @SuppressWarnings("unchecked")
  final List<Version> versions =
    (List<Version>) attrs.remove(Constants.VERSION_ATTRIBUTE);
  if (versions != null) {
    sb.append("&nbsp;");
    sb.append(versions);
  }

  if (!attrs.isEmpty()) {
    sb.append("&nbsp;");
    sb.append(attrs);
  }

  return sb.toString();
}
 
Example 7
Source File: NsToHtmlContent.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public String toHTML(Capability capability)
{
  // mime, url, size, sha

  // Make a modifiable clone of the attributes.
  final Map<String, Object> attrs =
    new HashMap<String, Object>(capability.getAttributes());

  final StringBuffer sb = new StringBuffer(50);

  Object val;

  val = attrs.remove(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
  if (val != null) {
    sb.append(Util.toHTML(val)).append("<br>");
  }

  val = attrs.remove(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE);
  if (val != null) {
    sb.append("Size: ").append(val).append("&nbsp;bytes.<br>");
  }

  val = attrs.remove(ContentNamespace.CONTENT_NAMESPACE);
  if (val != null) {
    sb.append("SHA-256: ").append(val).append("<br>");
  }

  val = attrs.remove(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE);
  if (val != null) {
    sb.append("Content-Type: ").append(val).append("<br>");
  }

  if (!attrs.isEmpty()) {
    sb.append("Other attributes: ");
    sb.append(attrs);
  }

  return sb.toString();
}
 
Example 8
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the size in bytes of a repository resource.
 *
 * @param resource
 *          The resource to get the size of.
 *
 * @return Resource size in byte or {@code -1} if no size available.
 */
public static long getResourceSize(Resource resource)
{
  long res = -1;
  for (final Capability cap : resource
      .getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) {
    final Map<String, Object> attrs = cap.getAttributes();
    final Long size =
      (Long) attrs.get(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE);
    if (size != null) {
      res = size.longValue();
    }
  }
  return res;
}
 
Example 9
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the category of a repository resource.
 *
 * The category is specified as the value of the bundle manifest entry named
 * {@link Constants#BUNDLE_CATEGORY}.
 *
 * @param resource
 *          The resource to get the category for.
 *
 * @return Resource category or {@code "[no category]"} if no category is available.
 */
public static String getResourceCategory(Resource resource)
{
  for (final Capability cap : resource
      .getCapabilities(KF_EXTRAS_NAMESPACE)) {
    final Map<String, Object> attrs = cap.getAttributes();
    final Object val = attrs.get("category");
    if (val != null) {
      return (String) val;
    }
  }
  return "[no category]";
}
 
Example 10
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the vendor of a repository resource.
 *
 * The vendor is specified as the value of the bundle manifest entry named
 * {@link Constants#BUNDLE_VENDOR}.
 *
 * @param resource
 *          The resource to get the vendor for.
 *
 * @return Resource vendor or {@code "[no vendor]"} if vendor information is
 *         not available.
 */
public static String getResourceVendor(Resource resource)
{
  for (final Capability cap : resource
      .getCapabilities(KF_EXTRAS_NAMESPACE)) {
    final Map<String, Object> attrs = cap.getAttributes();
    final Object val = attrs.get("vendor");
    if (val != null) {
      return (String) val;
    }
  }
  return "[no vendor]";
}
 
Example 11
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the icon for a repository resource.
 *
 * The icon is specified as the value of the bundle manifest entry named
 * {@code Bundle-Icon}.
 *
 * @param resource
 *          The resource to get the icon for.
 *
 * @return Resource icon string or {@code null} if icon information is
 *         not available.
 */
public static String getResourceIcon(Resource resource)
{
  for (final Capability cap : resource
      .getCapabilities(KF_EXTRAS_NAMESPACE)) {
    final Map<String, Object> attrs = cap.getAttributes();
    final Object val = attrs.get("icon");
    if (val != null) {
      return (String) val;
    }
  }
  return null;
}
 
Example 12
Source File: NsToHtmlPackage.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public String toHTML(Capability capability)
{
  final StringBuffer sb = new StringBuffer(50);

  // Make a modifiable clone of the capability attributes.
  final Map<String, Object> attrs
    = new HashMap<String, Object>(capability.getAttributes());

  sb.append(attrs.remove(BundleRevision.PACKAGE_NAMESPACE));

  final Version version = (Version) attrs
      .remove(Constants.VERSION_ATTRIBUTE);
  if (version!=null) {
    sb.append("&nbsp;");
    sb.append(version);
  }

  attrs.remove(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
  attrs.remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
  if (!attrs.isEmpty()) {
    sb.append("&nbsp;");
    sb.append(attrs);
  }

  return sb.toString();
}