Package org.wymiwyg.rwcf.form

Examples of org.wymiwyg.rwcf.form.MultiPartBody


   */
  public void handle(Request request, Response response, HandlerChain chain)
      throws HandlerException {

    try {
      MultiPartBody body;
      body = (MultiPartBody) request.getBody();
      if (body.getParameter("action_DeleteItem") != null) {
        Resource target = model.createResource(new EnhancedRequest(
            request).getFullRequestURL().toString());
        perform(target, request);
      }
    } catch (ClassCastException e) {
View Full Code Here



  private void perform(Resource target, Request request)
      throws HandlerException {
   
    MultiPartBody requestBody = (MultiPartBody) request.getBody();
    String item = requestBody.getParameter("item");
    URL itemURL;
    try {
      itemURL = new URL(new URL(target.getURI()), item);
    } catch (MalformedURLException e) {
      throw new HandlerException(e);
View Full Code Here

   *      org.wymiwyg.rwcf.Response, org.wymiwyg.rwcf.HandlerChain)
   */
  public void handle(Request request, Response response, HandlerChain chain)
      throws HandlerException {
      EnhancedRequest ehRequest = new EnhancedRequest(request);
    MultiPartBody body = (MultiPartBody) request.getBody();
    String remove = body.getParameter("remove");
    if (remove != null) {
        model.getResource(remove).removeProperties();
    } else {
      String serializedModel = body.getParameter("model");
      Model importing = ModelFactory.createDefaultModel();
      importing.read(new StringReader(serializedModel), ehRequest
          .getRequestURLWithoutParams().toString(), "RDF/XML")
      ResIterator importCriterionIter = importing.listSubjectsWithProperty(RDF.type, MAILPUSH.MailingList);
      while (importCriterionIter.hasNext()) {
View Full Code Here

   * @see org.wymiwyg.rwcf.Handler#handle(org.wymiwyg.rwcf.Request, org.wymiwyg.rwcf.Response, org.wymiwyg.rwcf.HandlerChain)
   */
  public void handle(Request request, Response response, HandlerChain chain)
      throws HandlerException {
    log.info("Posting new default values");
    MultiPartBody body = (MultiPartBody) request.getBody();
    String defaultChildStrengthString = body.getParameter("defaultChildStrength");
    String defaultStrengthReductionString = body.getParameter("defaultStrengthReduction");
    String defaultMininmalRelevanceString = body.getParameter("defaultMinimalRelevance");
    String notificationEmail = body.getParameter("notificationEmail");
    int itemsPerTopic = Integer.parseInt(body.getParameter("itemsPerTopic"));
    boolean defalutAllowComments = "allow".equals(body.getParameter("comments"));
    String defaultTimeZoneString = body.getParameter("defaultTimeZone");
    float defaultChildStrength = Float.parseFloat(defaultChildStrengthString);
    if ((defaultChildStrength > 1) || (defaultChildStrength < 0)) {
      throw new HandlerException("Invalid value");
    }
    float defaultStrengthReduction = Float.parseFloat(defaultStrengthReductionString);
View Full Code Here

   *      org.wymiwyg.rwcf.Response, org.wymiwyg.rwcf.HandlerChain)
   */
  public void handle(Request request, Response response, HandlerChain chain)
      throws HandlerException {
    EnhancedRequest ehRequest = new EnhancedRequest(request);
    MultiPartBody body = (MultiPartBody) request.getBody();
    String codeOrig = body.getParameter("codeOrig");
    String serializedModel = body.getParameter("model");
    Model importing = ModelFactory.createDefaultModel();
    importing.read(new StringReader(serializedModel), ehRequest
        .getRequestURLWithoutParams().toString(), "RDF/XML");
    if (codeOrig != null) {
      Resource resOrig = getSpatialThingByID(codeOrig);
      resOrig.removeProperties();
    }
   
    ResIterator importCountryIter = importing.listSubjectsWithProperty(
        RDF.type, GEOF.SpatialThing);
    boolean delete;
    if (body.getParameter("delete") != null) {
      delete = true;
    } else {
      delete = false;
    }
    while (importCountryIter.hasNext()) {
      if (delete) {
        deleteSpaceThing(importCountryIter.nextResource());
      } else {
        importSpaceThing(importCountryIter.nextResource());
      }
    }
    importCountryIter.close();
    /*
     * if (uriNew != null) { Resource permission =
     * model.getResource(uriNew); permission.addProperty(RDF.type,
     * AUTHORIZATION.Permission); permission.removeAll(RDFS.comment); if
     * (!comment.equals("")) { permission.addProperty(RDFS.comment,
     * comment); } permission.removeAll(RDFS.label); if (!label.equals("")) {
     * permission.addProperty(RDFS.label, label); } }
     */
    EnhancedResponse ehResponse = new EnhancedResponse(response);
    String go = body.getParameter("go");
    if (go == null) {
      String[] referers = request.getHeaderValues(HeaderName.REFERER);
      if (referers.length == 0) {
        throw new HandlerException("no 'go' parameter specified and no htpp-referer found");
      }
View Full Code Here

   */
  public void handle(Request request, Response response, HandlerChain chain)
  throws HandlerException {

    EnhancedRequest ehRequest = new EnhancedRequest(request);
    MultiPartBody body = (MultiPartBody) request.getBody();
    String itemURIString = body.getParameter("item");
    // since this doesn't read, I assume it need no read-lock
    Resource item = model.createResource(itemURIString);
    String recipientURIStrings[] = body.getParameterValues("recipient");
    if (recipientURIStrings == null) {
      throw new HandlerException("A recipient must be specified");
    }
    AcceptLanguagesIterator acceptedLanguages = ehRequest.getAcceptLanguages();
    InternetAddress fromAddress;
    String fromString = body.getParameter("from");
    if ((fromString != null) && (!fromString.equals(""))) {
      try {
        fromAddress = getIntenetAddress(model.createResource(fromString));
      } catch (AddressException e) {
        throw new HandlerException("Couldn't get address", e);
View Full Code Here

   */
  public void handle(Request request, Response response, HandlerChain chain)
      throws HandlerException {

    try {
      MultiPartBody body;
      body = (MultiPartBody) request.getBody();
      if (body.getParameter("action_TopicPost") != null) {
                performPost(request, body);
       
      }
    } catch (ClassCastException e) {
    }
View Full Code Here

   *      org.wymiwyg.rwcf.Response, org.wymiwyg.rwcf.HandlerChain)
   */
  public void handle(Request request, Response response, HandlerChain chain)
      throws HandlerException {

    MultiPartBody body;
    if (request.getMethod().equals(Method.POST)) {
      body = (MultiPartBody) request.getBody();
      if (body.getParameter("action_NewItem") != null) {
        EnhancedRequest ehRequest = new EnhancedRequest(request);
        Resource target = model.createResource(ehRequest
            .getRequestURLWithoutParams().toString());
        addItemToTopic(target, ehRequest);
      }
View Full Code Here

  }


  public void addItemToTopic(Resource topic, EnhancedRequest request)
      throws HandlerException {
    MultiPartBody requestBody = (MultiPartBody) request.getBody();
    String strengthString = requestBody.getParameter("strength");
    float relevance;
    if ((strengthString != null) && (!strengthString.equals(""))) {
      relevance = Float.parseFloat(strengthString);
    } else {
      relevance = 1;
    }
    String strengthReductionString = requestBody
        .getParameter("strengthReduction");
    float aging;
    if ((strengthReductionString != null)
        && (!strengthReductionString.equals(""))) {
      aging = Float.parseFloat(strengthReductionString);
    } else {
      aging = DefaultValuesHandler
      .getDefaultStrengthReduction(model);
    }
    String title = requestBody.getParameter("title");
    Resource item;
    String urlSuffix = requestBody.getParameter("urlSuffix");
    if ((urlSuffix != null) && (!urlSuffix.equals(""))) {
      item = NamedResourceGenerator.createNewResourceFromSuffix(model, request
          .getRootURL(), urlSuffix);
    } else {
      item = NamedResourceGenerator.createNewResource(model, request
View Full Code Here

   *      org.wymiwyg.rwcf.Response, org.wymiwyg.rwcf.HandlerChain)
   */
  public void handle(Request request, Response response, HandlerChain chain)
      throws HandlerException {
    EnhancedRequest ehRequest = new EnhancedRequest(request);
    MultiPartBody body;
    try {
      body = (MultiPartBody) request.getBody();
    } catch (ClassCastException ex) {
      throw new HandlerException(ResponseStatus.BAD_REQUEST, "CommentPostHandler invoked with a wrong request-body format");
    }
    String serializedModel = body.getParameter("model");
    if (serializedModel == null) {
      throw new HandlerException(ResponseStatus.BAD_REQUEST,
          "No serialized model found. Is JavaScript enabled?");
    }
    Model importing = ModelFactory.createDefaultModel();
    importing.read(new StringReader(serializedModel), ehRequest
        .getRequestURLWithoutParams().toString(), "RDF/XML");

    Resource[] roots = JenaUtil.getRoots(importing);
    if (roots.length != 1) {
      throw new HandlerException(
          "Imported model must have exactly one root");
    }
    Resource relation = roots[0];
    /*
     * if (!relation.hasProperty(RDF.type, KNOBOT.CommentRelation)) { throw
     * new HandlerException("Imported resource must be of type " +
     * KNOBOT.CommentRelation); }
     */
    Resource comment = null;
    Resource source = null;
    model.enterCriticalSection(ModelLock.WRITE);
    try {
      comment = relation.getProperty(KNOBOT.target).getResource();
      if (!comment.hasProperty(DC.date)) {
        Literal currentDate = importing.createTypedLiteral(
            new W3CDateFormat().format(new Date()),
            XSDDatatype.XSDdateTime);
        comment.addProperty(DC.date, currentDate);
      }
      Statement makerStmt = comment.getProperty(FOAF.maker);
      if (makerStmt != null) {
        Resource maker = makerStmt.getResource();
        Statement mboxStmt = maker.getProperty(FOAF.mbox);
        if (mboxStmt != null) {
          Resource mbox = mboxStmt.getResource();
          Resource user = VirtuserHandler.getSubject();
          ;
          ResIterator existingAgents = model
              .listSubjectsWithProperty(FOAF.mbox, mbox);
          if (existingAgents.hasNext()) {
            Resource agent = existingAgents.nextResource();
            if (agent.hasProperty(AUTHORIZATION.pass_sha1sum)
                && !agent.equals(user)) {
              throw new AccessControlException(
                  "Posting comment with exiting users mailbox");
            }
            // remove statements othe than mbox:
            Collection removingStmt = new ArrayList();
            StmtIterator makerProperties = maker.listProperties();
            while (makerProperties.hasNext()) {
              Statement current = (Statement) makerProperties
                  .nextStatement();
              if (current.getPredicate().equals(FOAF.mbox)
                  && current.getObject().equals(mbox)) {
                continue;
              }
              if (current.getPredicate().equals(FOAF.name)) {
                RDFNode currentNameObject = current.getObject();
                if (!agent.hasProperty(FOAF.name,
                    currentNameObject)) {
                  comment.addProperty(DC.creator,
                      currentNameObject);
                }
              }

              removingStmt.add(current);
            }
            makerProperties.close();
            for (Iterator iter = removingStmt.iterator(); iter
                .hasNext();) {
              Statement current = (Statement) iter.next();
              current.remove();
            }
          }
          if (existingAgents.hasNext()) {
            log.warn("duplicate agent with " + mbox);
          }
          existingAgents.close();
        }
      }
      relation.addProperty(KNOBOT.strength, model.createTypedLiteral(1f));
      relation.addProperty(KNOBOT.childStrength, model.createTypedLiteral(0.5f));
      Literal effectiveDateLiteral = model.createTypedLiteral(
          new W3CDateFormat().format(new Date()),
          XSDDatatype.XSDdateTime);
      relation.addProperty(KNOBOT.effectiveDate, effectiveDateLiteral);
      relation.addProperty(KNOBOT.strengthReduction, model.createTypedLiteral(DefaultValuesHandler
          .getDefaultStrengthReduction(model)));
      Statement titleStatement = comment.getProperty(RSS.title);
      if (titleStatement == null) {
        throw new BadRequestException("Title is required");
      }
      Resource namedItem = (Resource) NamedResourceGenerator
          .createNewResource(model, ehRequest.getRootURL(),
              titleStatement.getString()).inModel(importing);
      JenaUtil.replace(importing, comment, namedItem);
      comment = namedItem;
      htmlize(comment);

      comment.addProperty(RDF.type, RWCF.AuthoritativelyServedResource);
      comment.addProperty(RDF.type, KNOBOT.Commentable);
      source = (Resource) relation.getProperty(KNOBOT.source)
          .getResource().inModel(model);
      if (!source.hasProperty(RDF.type, KNOBOT.Commentable)) {
        AccessController.checkPermission(new RPermission(
            AUTHORIZATION.edit));
      }
      // add same required permissions as for commented item
      addRequiredPermissions(source, comment);
      addNotificationsTargets(source, comment);
      InsertionIFPResolver.process(model, importing);
      model.add(importing);
      RelationManager.addRelation((Resource) relation.inModel(model));
    } finally {
      model.leaveCriticalSection();
    }
    sendNotification((Resource) source.inModel(model), (Resource) comment
        .inModel(model), ehRequest.getAcceptLanguages(), ehRequest
        .getRootURL());
    String go = body.getParameter("go");
    if (go == null) {
      go = source.getURI();
    }
    new EnhancedResponse(response).sendRedirect(go);
  }
View Full Code Here

TOP

Related Classes of org.wymiwyg.rwcf.form.MultiPartBody

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.