List of usage examples for javax.activation MimeType toString
public String toString()
From source file:org.osaf.cosmo.atom.provider.ItemCollectionAdapter.java
public ResponseContext postCollection(RequestContext request) { // This adapter supports POSTing an XHTML representation ( // of a collection (no child items), POSTing an icalendar // representation of a collection (where child items will be // imported as well), or POSTing a URL that points to // an icalendar representation of a collection MimeType ct = request.getContentType(); if (ct == null) return ProviderHelper.notsupported(request, "Content-Type is required"); String mimeType = ct.toString(); if (MimeTypeHelper.isMatch(MEDIA_TYPE_XHTML, mimeType)) return createCollectionXHTML(request); else if (MimeTypeHelper.isMatch(MEDIA_TYPE_CALENDAR, mimeType)) return createCollectionICSFromData(request); else if (MimeTypeHelper.isMatch(MEDIA_TYPE_URLENCODED, mimeType)) return createCollectionICSFromURL(request); else//from w w w . j a v a2 s . co m return ProviderHelper.notsupported(request, "unsupported Content-Type"); }
From source file:org.osaf.cosmo.atom.provider.ItemCollectionAdapter.java
private boolean isAddItemToCollectionRequest(RequestContext request) { if (!(request.getTarget() instanceof CollectionTarget)) return false; MimeType ct = request.getContentType(); if (ct == null) return false; return MimeTypeHelper.isMatch(MEDIA_TYPE_URLENCODED, ct.toString()); }
From source file:org.wso2.carbon.registry.app.RegistryAdapter.java
/** * Posts a new media entry./*w w w. j a va 2 s.co m*/ * * @param mimeType the MIME type of the content. * @param slug the slug as a String. * @param inputStream the content stream. * @param request the request context. * * @return the generated media object. * @throws ResponseContextException if the operation failed. */ public Resource postMedia(MimeType mimeType, String slug, InputStream inputStream, RequestContext request) throws ResponseContextException { final Registry registry; try { registry = getSecureRegistry(request); } catch (RegistryException e) { throw new ResponseContextException(new StackTraceResponseContext(e)); } String path = ((ResourceTarget) request.getTarget()).getResource().getPath(); final String[] splitPath = (String[]) request.getAttribute(RequestContext.Scope.REQUEST, APPConstants.PARAMETER_SPLIT_PATH); if (splitPath != null && APPConstants.PARAMETER_COMMENTS.equals(splitPath[1])) { if (!mimeType.toString().equals("text/plain")) { throw new ResponseContextException("Can only post Atom or text/plain to comments!", HttpURLConnection.HTTP_BAD_REQUEST); } // Comment post org.wso2.carbon.registry.core.Comment comment; try { comment = new org.wso2.carbon.registry.core.Comment(readToString(inputStream)); } catch (IOException e) { throw new ResponseContextException(new StackTraceResponseContext(e)); } try { String commentPath = registry.addComment(path, comment); comment.setPath(commentPath); comment.setParentPath(path + RegistryConstants.URL_SEPARATOR + APPConstants.PARAMETER_COMMENTS); } catch (RegistryException e) { throw new ResponseContextException(new StackTraceResponseContext(e)); } return comment; } if (!path.endsWith("/")) { path += "/"; } path += getGoodSlug(path, slug, request); boolean isCollection = "app/collection".equals(mimeType.toString()); Resource ret; try { ret = isCollection ? registry.newCollection() : registry.newResource(); } catch (RegistryException e) { throw new ResponseContextException(new StackTraceResponseContext(e)); } ret.setMediaType(mimeType.toString()); try { if (!isCollection) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buffer = new byte[RegistryConstants.DEFAULT_BUFFER_SIZE]; try { while (inputStream.available() > 0) { int amount = inputStream.read(buffer, 0, RegistryConstants.DEFAULT_BUFFER_SIZE); bos.write(buffer, 0, amount); } } catch (IOException e) { // nothing here } String content = RegistryUtils.decodeBytes(bos.toByteArray()); ret.setContent(content); } registry.put(path, ret); } catch (RegistryException e) { throw new ResponseContextException(new StackTraceResponseContext(e)); } return ret; }