Package org.apache.clerezza.jaxrs.utils.form

Examples of org.apache.clerezza.jaxrs.utils.form.FormFile


   * resource already exists.
   */
  @POST
  @Consumes("multipart/form")
  public Response postContent(MultiPartBody form) {
    FormFile formFile = form.getFormFileParameterValues("content")[0];
    String uri = form.getTextParameterValues("uri")[0];
    byte[] content = formFile.getContent();
    if (content == null || uri == null) {
      return Response.status(400).entity("Required form field is missing").
          type(MediaType.TEXT_PLAIN_TYPE).build();
    }
    LockableMGraph contentGraph = cgProvider.getContentGraph();
    Lock readLock = contentGraph.getLock().readLock();
    readLock.lock();
    try {
      if (contentGraph.filter(new UriRef(uri), RDF.type, null).hasNext()) {
        return Response.status(Response.Status.CONFLICT).
            entity("A resource with the specified URI already exists").
            type(MediaType.TEXT_PLAIN_TYPE).build();
      }
    } finally {
      readLock.unlock();
    }
    handler.put(new UriRef(uri), formFile.getMediaType(), content);
    return Response.created(URI.create(uri)).build();
 
View Full Code Here


    String scriptName = "unnamed";

    byte[] scriptFileBytes = new byte[0];

    if(fileChoice.equals("file")) {
      FormFile formFile =
          form.getFormFileParameterValues("scriptFile")[0];
      scriptFileBytes = formFile.getContent();

      if (scriptFileBytes == null || (scriptFileBytes.length == 0)) {
        String message = "no script uploaded";
        logger.warn(message);
        throw new WebApplicationException(Response.status(
            Status.BAD_REQUEST).entity(message).build());
      }

      scriptName = formFile.getFileName();

      if(mediaType.trim().equals("")) {
        mediaType = formFile.getMediaType().toString();
      }
    } else if(fileChoice.equals("text")) {
      if(form.getTextParameterValues("scriptCode").length > 0) {
        scriptFileBytes = form.getTextParameterValues("scriptCode")[0].
            getBytes();
View Full Code Here

    String scriptCode = form.getTextParameterValues("scriptCode")[0];

    ScriptLanguageDescription sld =
        extractLanguageAndVersion(scriptLanguageAndVersion);

    FormFile formFile =
        form.getFormFileParameterValues("scriptFile")[0];
   
    byte[] scriptFileBytes = formFile.getContent();



    if (scriptFileBytes == null || (scriptFileBytes.length == 0)) {
      scriptFileBytes = scriptCode.getBytes();
      if(mediaType.trim().equals("")) {
        mediaType = "text/plain";
      }
    } else {
      if(mediaType.trim().equals("")) {
        mediaType = formFile.getMediaType().toString();
      }
      scriptName = formFile.getFileName();
    }
    saveScript(scriptUri, scriptFileBytes, scriptName, sld.getLanguage(),
        sld.getVersion(), mediaType, producedType);

    return RedirectUtil.createSeeOtherResponse(
View Full Code Here

    AccessController.checkPermission(new WebAccessPermission());
    FormFile[] formFiles = form.getFormFileParameterValues("graph");
    if (formFiles.length == 0) {
      responseWithBadRequest("form file parameter 'graph' is missing");
    }
    FormFile formFile = formFiles[0];
    byte[] graph = formFile.getContent();
    if (graph == null || (graph.length == 0)) {
      responseWithBadRequest("no triples uploaded");
    }
    MediaType mediaType = formFile.getMediaType();
    if (mediaType == null) {
      responseWithBadRequest("mime-type not specified");
    }
    if (mediaType.equals(MediaType.APPLICATION_OCTET_STREAM_TYPE)) {
      MediaType guessedType = MediaTypeGuesser.getInstance().guessTypeForName(formFile.getFileName());
      if (guessedType != null) {
        mediaType = guessedType;
      }
    }
    String graphName = getFirstTextParameterValue(form, "name", true);
View Full Code Here

    AccessController.checkPermission(new RestorePermission());
    FormFile[] files = body.getFormFileParameterValues("file");
    if (files.length != 1) {
      throw new RuntimeException("Must submit exactly one file");
    }
    final FormFile file = files[0];
    try {
      return AccessController.doPrivileged(new PrivilegedExceptionAction<Response>() {

        @Override
        public Response run() throws IOException {
          restore(new ByteArrayInputStream(file.getContent()));
          return RedirectUtil.createSeeOtherResponse("/admin/backup", uriInfo);
        }
      });
    } catch (PrivilegedActionException ex) {
      throw ex.getCause();
View Full Code Here

     */
    @POST
    public RdfViewable enhanceFile(MultiPartBody body) throws IOException, EnhancementException {
        final String[] chainValues = body.getTextParameterValues("chain");
        final String chainName = chainValues.length > 0 ? chainValues[0] : null;
        final FormFile file = body.getFormFileParameterValues("file")[0];
        final ContentSource contentSource = new ByteArraySource(
                file.getContent(),
                file.getMediaType().toString(),
                file.getFileName());
        final ContentItem contentItem = contentItemFactory.createContentItem(contentSource);
        if ((chainName == null) || chainName.trim().equals("")) {
            enhancementJobManager.enhanceContent(contentItem);
        } else {
            final Chain chain = chainManager.getChain(chainName);
View Full Code Here

        AccessController.checkPermission(new WebAccessPermission());
        FormFile[] formFiles = form.getFormFileParameterValues("graph");
        if (formFiles.length == 0) {
            responseWithBadRequest("form file parameter 'graph' is missing");
        }
        FormFile formFile = formFiles[0];
        byte[] graph = formFile.getContent();
        if (graph == null || (graph.length == 0)) {
            responseWithBadRequest("no triples uploaded");
        }
        MediaType mediaType = formFile.getMediaType();
        if (mediaType == null) {
            responseWithBadRequest("mime-type not specified");
        }
        if (mediaType.equals(MediaType.APPLICATION_OCTET_STREAM_TYPE)) {
            MediaType guessedType = MediaTypeGuesser.getInstance().guessTypeForName(formFile.getFileName());
            if (guessedType != null) {
                mediaType = guessedType;
            }
        }
        String graphName = getFirstTextParameterValue(form, "name", true);
View Full Code Here

        AccessController.checkPermission(new RestorePermission());
        FormFile[] files = body.getFormFileParameterValues("file");
        if (files.length != 1) {
            throw new RuntimeException("Must submit exactly one file");
        }
        final FormFile file = files[0];
        try {
            return AccessController.doPrivileged(new PrivilegedExceptionAction<Response>() {

                @Override
                public Response run() throws IOException {
                    restore(new ByteArrayInputStream(file.getContent()));
                    return RedirectUtil.createSeeOtherResponse("/admin/backup", uriInfo);
                }
            });
        } catch (PrivilegedActionException ex) {
            throw ex.getCause();
View Full Code Here

TOP

Related Classes of org.apache.clerezza.jaxrs.utils.form.FormFile

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.