List of usage examples for javax.activation MimeType getParameters
public MimeTypeParameterList getParameters()
From source file:org.apache.abdera2.common.protocol.ClientResponseImpl.java
@SuppressWarnings("rawtypes") public String getCharacterEncoding() { MimeType mt = this.getContentType(); if (mt != null) { MimeTypeParameterList list = mt.getParameters(); Enumeration names = list.getNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (name.equalsIgnoreCase("charset")) return list.get(name); }//from ww w. j a v a 2s .com } return "UTF-8"; }
From source file:org.xcmis.restatom.collections.CmisObjectCollection.java
@SuppressWarnings("unchecked") protected org.xcmis.spi.utils.MimeType convertMimeType(MimeType abderaMimeType) { if (abderaMimeType == null) { return new org.xcmis.spi.utils.MimeType(); }/* w w w. j a v a2 s . c o m*/ MimeTypeParameterList abderaParameters = abderaMimeType.getParameters(); Map<String, String> paremeters = new HashMap<String, String>(); for (Enumeration<String> names = abderaParameters.getNames(); names.hasMoreElements();) { String name = names.nextElement(); paremeters.put(name, abderaParameters.get(name)); } return new org.xcmis.spi.utils.MimeType(abderaMimeType.getPrimaryType(), abderaMimeType.getSubType(), paremeters); }
From source file:org.xcmis.restatom.collections.CmisObjectCollection.java
/** * Get content stream from entry.//from www . j av a 2 s .c o m * * @param entry source entry * @param request request context * @return content stream as <code>ContentStream</code> or null if there is * no 'content' in entry * @throws IOException if any i/o error occurs * @throws ResponseContextException other errors */ protected ContentStream getContentStream(Entry entry, RequestContext request) throws IOException, ResponseContextException { ContentStream contentStream = null; ContentTypeElement cmisContent = entry.getExtension(AtomCMIS.CONTENT); if (cmisContent != null) { CmisContentType content = cmisContent.getContent(); InputStream is = content.getBase64(); contentStream = new BaseContentStream(is, is.available(), null, org.xcmis.spi.utils.MimeType.fromString(content.getMediatype())); } else { Content content = entry.getContentElement(); if (content != null) { final IRI src = content.getSrc(); if (src != null) { if (src.equals(new IRI(getContentLink(getId(request), request)))) { // If 'src' attribute provides URI is the same to current // object (document). This may happen when client does 'check-in' // or 'check-out' operation. } else { URL url = null; try { url = src.toURL(); } catch (URISyntaxException e) { String msg = "Invalid src attribute: " + src; throw new ResponseContextException(createErrorResponse(msg, 400)); } // HTTP only HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); httpConnection.setRequestMethod("GET"); httpConnection.setDoOutput(false); httpConnection.setDoInput(true); int status = httpConnection.getResponseCode(); if (200 == status) { contentStream = new BaseContentStream(new HttpConnectionStream(httpConnection), null, org.xcmis.spi.utils.MimeType .fromString(httpConnection.getHeaderField("Content-Type"))); } else { httpConnection.disconnect(); String msg = "Unable get content from URI : " + src.toString() + ". Response status is " + status; throw new ResponseContextException(createErrorResponse(msg, 500)); } } } else { Type contentType = content.getContentType(); org.xcmis.spi.utils.MimeType mediaType; if (contentType == Type.XML || contentType == Type.XHTML || contentType == Type.HTML || contentType == Type.TEXT) { switch (contentType) { case XHTML: mediaType = new org.xcmis.spi.utils.MimeType("application", "xhtml+xml"); break; case HTML: mediaType = new org.xcmis.spi.utils.MimeType("text", "html"); break; case TEXT: mediaType = new org.xcmis.spi.utils.MimeType("text", "plain"); break; case XML: mediaType = convertMimeType(content.getMimeType()); break; default: // Must never happen. mediaType = new org.xcmis.spi.utils.MimeType(); } byte[] data; // XXX CMISSpaces sends XML content as Base64 encoded but // Abdera waits for plain text. // Done just for research work. Find good solution to fix this. if (SPACES_AIR_SPECIFIC_REFERER.equalsIgnoreCase(request.getHeader("referer"))) { data = Base64.decodeBase64(content.getText().getBytes()); } else { String charset = mediaType.getParameter(CmisConstants.CHARSET); if (charset == null) { // workaround mediaType.getParameters().put(CmisConstants.CHARSET, "UTF-8"); } data = content.getValue().getBytes(charset == null ? "UTF-8" : charset); } contentStream = new BaseContentStream(data, null, mediaType); } else { contentStream = new BaseContentStream(content.getDataHandler().getInputStream(), null, convertMimeType(content.getMimeType())); } } } } return contentStream; }