Package javax.activation

Examples of javax.activation.MimeType


   */
  public static boolean isXml(String a) {
    boolean answer = isMatch(Constants.XML_MEDIA_TYPE, a) || isMatch("text/xml", a);
    if (!answer) {
      try {
        MimeType mta = new MimeType(a);
        answer =
          (("application".equalsIgnoreCase(mta.getPrimaryType()) ||
            "text".equalsIgnoreCase(mta.getPrimaryType())) &&
            mta.getSubType().equals("xml") ||
            mta.getSubType().endsWith("+xml"));
      } catch (Exception e) {}
    }
    return answer;
  }
View Full Code Here


   * Returns true if this is a valid media type
   */
  public static boolean isMimeType(String a) {
    boolean answer = false;
    try {
      new MimeType(a);
      answer = true;
    } catch (javax.activation.MimeTypeParseException e) {
      answer = false;
    }
    return answer;
View Full Code Here

  @SuppressWarnings("unchecked")
  public static <T extends Base>String getMimeType(T base) {
    String type = null;
    if (base instanceof Document) {
      Document doc = (Document)base;     
      MimeType mt = doc.getContentType();
      type = (mt != null) ? mt.toString() : getMimeType(doc.getRoot());
    } else if (base instanceof Element) {
      Element el = (Element)base;
      if (el.getDocument() != null) {
        MimeType mt = el.getDocument().getContentType();
        type = (mt != null) ? mt.toString() : null;
      }    
      if (type == null) {
        if (el instanceof Feed)
          type = Constants.FEED_MEDIA_TYPE;
        else if (el instanceof Entry)
View Full Code Here

  /**
   * Compare two media types according to their relative level of specificity
   */
  public static int compare(String t1, String t2) {
    try {
      MimeType mt1 = new MimeType(t1);
      MimeType mt2 = new MimeType(t2);
      return compare(mt1,mt2);
    } catch (Exception e) {}
    return 0;
  }
View Full Code Here

                for (Map.Entry<String, String> entry : mediaRanges.entrySet()) {
                    if (entry.getKey().equalsIgnoreCase("entry")) {
                        addSimpleExtension(ACCEPT, "application/atom+xml;type=entry");
                    } else {
                        try {
                            Element accept = addSimpleExtension(ACCEPT, new MimeType(entry.getKey()).toString());
                            if (entry.getValue() != null) {
                                accept.setAttributeValue(ALTERNATE, entry.getValue());
                            }
                        } catch (javax.activation.MimeTypeParseException e) {
                            throw new org.apache.abdera.util.MimeTypeParseException(e);
View Full Code Here

        complete();
        if (mediaRanges != null) {
            for (Map.Entry<String, String> entry : mediaRanges.entrySet()) {
                if (!accepts(entry.getKey())) {
                    try {
                        Element accept = addSimpleExtension(ACCEPT, new MimeType(entry.getKey()).toString());
                        if (entry.getValue() != null) {
                            accept.setAttributeValue(ALTERNATE, entry.getValue());
                        }
                    } catch (Exception e) {
                    }
View Full Code Here

    }

    public MimeType getMimeType() {
        try {
            String type = getAttributeValue(TYPE);
            return (type != null) ? new MimeType(type) : null;
        } catch (javax.activation.MimeTypeParseException e) {
            throw new org.apache.abdera.util.MimeTypeParseException(e);
        }
    }
View Full Code Here

    public Link setMimeType(String type) {
        complete();
        try {
            if (type != null)
                setAttributeValue(TYPE, (new MimeType(type)).toString());
            else
                removeAttribute(TYPE);
        } catch (javax.activation.MimeTypeParseException e) {
            throw new org.apache.abdera.util.MimeTypeParseException(e);
        }
View Full Code Here

    public Content setContent(Element element, String mediaType) {
        try {
            if (MimeTypeHelper.isText(mediaType))
                throw new IllegalArgumentException();
            FOMFactory factory = (FOMFactory)this.factory;
            Content content = factory.newContent(new MimeType(mediaType));
            content.setValueElement(element);
            setContentElement(content);
            return content;
        } catch (javax.activation.MimeTypeParseException e) {
            throw new org.apache.abdera.util.MimeTypeParseException(e);
View Full Code Here

     * @throws MimeTypeParseException
     */
    public Content setContent(String value, String mediatype) {
        try {
            FOMFactory factory = (FOMFactory)this.factory;
            Content content = factory.newContent(new MimeType(mediatype));
            content.setValue(value);
            content.setMimeType(mediatype);
            setContentElement(content);
            return content;
        } catch (javax.activation.MimeTypeParseException e) {
View Full Code Here

TOP

Related Classes of javax.activation.MimeType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.