Package org.wymiwyg.rwcf.form

Examples of org.wymiwyg.rwcf.form.MultiPartBody


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

    Resource user = null;
    if (request.getMethod().equals(org.wymiwyg.wrhapi.Method.POST)) {
      MultiPartBody body = (MultiPartBody) request.getBody();
      String shortName = null;
      try {
        shortName = body.getParameterValues("shortName")[0];
      } catch (Exception ex) {
      }
      if (shortName == null) {
        throw new HandlerException("Must specify a shortName parameter");
      }
      String password = body.getParameterValues("password")[0];
      String create = null;
      try {
        create = body.getParameterValues("create")[0];
      } catch (Exception ex) {
      }
      ResIterator users = model.listSubjectsWithProperty(
          AUTHORIZATION.shortName, shortName);
      if (users.hasNext()) {
        user = users.nextResource();
      }
      /*
       * RDF.type, AUTHORIZATION.User); while (users.hasNext()) { Resource
       * current = users.nextResource(); if
       * (shortName.equals(current.getProperty(
       * AUTHORIZATION.shortName).getString())) { user = current; } }
       */
      users.close();

      if ((user == null) && ("true".equals(create))) {
        user = model.createResource();
        user.addProperty(RDF.type, AUTHORIZATION.User);
        user.addProperty(AUTHORIZATION.shortName, shortName);
      }
      boolean delete = false;
      try {
        delete = "delete".equals(body.getParameterValues("delete")[0]);
      } catch (Exception ex) {
      }

      if (delete) {
        user.removeProperties();
        new org.wymiwyg.rwcf.util.EnhancedResponse(response)
            .sendRedirect("/admin/user_manager");
        return;
      }
      user.removeAll(AUTHORIZATION.password);
      user.removeAll(AUTHORIZATION.pass_sha1sum);
      user.addProperty(AUTHORIZATION.pass_sha1sum, Util.sha1(password));
      String[] permissionStrings = body.getParameterValues("permission");
      user.removeAll(AUTHORIZATION.permission);
      if (permissionStrings != null) {
        for (int i = 0; i < permissionStrings.length; i++) {
          user.addProperty(AUTHORIZATION.permission, model
              .createResource(permissionStrings[i]));
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 {
    MultiPartBody body;
    body = (MultiPartBody) request.getBody();

    byte[] content = body.getFileContent("insertion");
    if (content == null) {
      log.error("No file specified, availabe Params are");
      throw new HandlerException("No file specified");
    }
    String base = body.getParameter("base");
    if (base == null) {
      base = "";
    }
    String format = body.getParameter("format");
    if (format == null) {
      format = "RDF/XML";
    }
    boolean replaceNonTemporary = false;
    try {
      replaceNonTemporary = body.getParameter("replace_non_temporary")
          .equals("on");
    } catch (NullPointerException ex) {
    }
    boolean resolveIFP = false;
    try {
        resolveIFP = body.getParameter("resolve_ifp").equals("on");
    } catch (NullPointerException ex) {
    }
    boolean removeTemporaryInInsertion = false;
    try {
      removeTemporaryInInsertion = body.getParameter("remove_temporary_in_insertion")
          .equals("on");
    } catch (NullPointerException ex) {
    }
    Model insertion = ModelFactory.createDefaultModel();
    insertion.read(new ByteArrayInputStream(content), base, format);
View Full Code Here

   * @param request
   * @param response
   * @throws HandlerException
   */
  private void handlePost(Request request, Response response) throws HandlerException {
    MultiPartBody body = (MultiPartBody) request.getBody();
    String abbreviation = body.getParameter("abbreviation");
    String action = body.getParameter("action");
    if ("delete".equals(action)) {
      getLanguageResource(abbreviation).removeProperties();
    }
    if ("new".equals(action)) {
      if (getLanguageResource(abbreviation) != null) {
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_ChangeItem") != null) {
        EnhancedRequest ehRequest = new EnhancedRequest(request);
        Resource target = model.createResource(ehRequest
            .getRequestURLWithoutParams().toString());
        setItemOrTopicProperties(target, ehRequest);
      }
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_SetStrength") != null) {
        MultiPartBody requestBody = (MultiPartBody) request.getBody();
        String strengthString = requestBody.getParameter("strength");
        String childStrengthString = requestBody.getParameter("childStrength");
        Resource target = model.createResource(new EnhancedRequest(
            request).getRequestURLWithoutParams().toString());
        perform(target, request, strengthString, childStrengthString);
        if ("background".equals(body.getParameter("postMethod"))) {
            //response.setBody(new StringReader("<p>Commited</p>"));
View Full Code Here

   * @see ch.osar.cms.rssedit.RSSPostAction#perform(com.hp.hpl.jena.rdf.model.Resource,
   *           org.wymiwyg.commons.util.http.MultiPartServletRequest)
   */
  private void perform(Resource relationSource, Request request, String strengthString, String childStrengthString)
      throws HandlerException {
    MultiPartBody requestBody = (MultiPartBody) request.getBody();
    String language = requestBody.getParameter("language");
    String relationTargetString = requestBody.getParameter("target");
    String relationSourceString = requestBody.getParameter("source");
    if ((relationSourceString != null)
        && (!"".equals(relationSourceString))) {
      relationSource = model.createResource(relationSourceString);
    }
    boolean inline = "inline".equals(requestBody.getParameter("linkType"));
    boolean highlight = "checked".equals(requestBody
        .getParameter("highlight"));
    boolean comment = "checked".equals(requestBody
        .getParameter("comment"));
    Resource relationTarget;
    if (relationTargetString != null) {
      String relationTargetURL;
      try {
        if (relationTargetString.startsWith("http:")) {
          relationTargetURL = new URL(relationTargetString)
              .toString();
        } else {
          relationTargetURL = new URL(
              new URL(relationSource.getURI()),
              relationTargetString).toString();
        }
        relationTarget = model.createResource(relationTargetURL);
      } catch (MalformedURLException e) {
        throw new HandlerException(e);
      }
    } else {
      String targetDescriptionString = requestBody.getParameter("targetDescription");
      URL targetDescriptionURL;
      try {
        if (targetDescriptionString.startsWith("http")) {
          targetDescriptionURL = new URL(targetDescriptionString);
        } else {
          targetDescriptionURL = new URL(new URL(relationSource
              .getURI()), targetDescriptionString);
        }
        Resource targetDescription = model
            .createResource(targetDescriptionURL.toString());
        relationTarget = BaseItemPostHandler.lookUpByIFP(model,
            FOAF.isPrimaryTopicOf, targetDescription);
      } catch (MalformedURLException e) {
        throw new HandlerException(e);
      }
    }

   
    float strength;
    if ((strengthString != null) && (!strengthString.equals(""))) {
        strength = Float.parseFloat(strengthString);
    } else {
        strength = 1;
    }
    float strengthOrig = Float.parseFloat(requestBody
        .getParameter("strengthOrig"));

   
    String childStrengthOrig = requestBody
        .getParameter("childStrengthOrig");
    //    if the user did not modify the strength the strength isn't changed,
    // i.e. the time reduced value is kept
    boolean keepStrength = (strength == strengthOrig)
        && ((childStrengthString == null) || (childStrengthString
            .equals(childStrengthOrig)));
    Resource relation = getRelation(relationSource, relationTarget);
        String effectiveDateString = requestBody.getParameter("effectiveDate");
        Literal effectiveDateLiteral;
        if (effectiveDateString == null) {
            effectiveDateLiteral = model.createTypedLiteral(new W3CDateFormat()
                    .format(new Date()), XSDDatatype.XSDdateTime);
        } else {
            effectiveDateLiteral = model.createTypedLiteral(effectiveDateString, XSDDatatype.XSDdateTime);
        }
       
    if (relation == null) {
      relation = model.createResource();
     
      relation.addProperty(KNOBOT.effectiveDate, effectiveDateLiteral);
      Literal strengthLit = model.createTypedLiteral(strength);
      relation.addProperty(KNOBOT.strength, strengthLit);
    } else {
        cleanRelation(relation, keepStrength, language);
      if (!keepStrength) {
        relation.addProperty(KNOBOT.effectiveDate, effectiveDateLiteral);
        relation.addProperty(KNOBOT.strength,  model.createTypedLiteral(strength));
      }
    }    
    if (inline) {
        relation.addProperty(RDF.type, KNOBOT.InlineRelation);
    }
    relation.addProperty(RDF.type, KNOBOT.Relation);
    String targetLabel = requestBody.getParameter("targetLabel");
    if ((targetLabel != null) && (!targetLabel.equals(""))) {
      relation.addProperty(KNOBOT.targetLabel, targetLabel, language);
    }
    String sourceLabel = requestBody.getParameter("sourceLabel");
    if ((sourceLabel != null) && (!sourceLabel.equals(""))) {
      relation.addProperty(KNOBOT.sourceLabel, sourceLabel, language);
    }
   
    String strengthReductionString = requestBody
    .getParameter("strengthReduction");
    float strengthReduction;
    if ((strengthReductionString != null) && (!strengthReductionString.equals(""))) {
        strengthReduction = Float.parseFloat(strengthReductionString);
    } else {
        strengthReduction = DefaultValuesHandler.getDefaultStrengthReduction(model);
    }
    relation.addProperty(KNOBOT.strengthReduction, model.createTypedLiteral(strengthReduction));
    float childStrength = 0;
    if ((!keepStrength) && (childStrengthString != null)
        && (!childStrengthString.equals(""))) {
      childStrength = Float.parseFloat(childStrengthString);
      relation.addProperty(KNOBOT.childStrength, model.createTypedLiteral(childStrength));
    }
    String childStrengthReduction = requestBody
        .getParameter("minimumChildStrengthReduction");
    if ((childStrengthReduction != null)
        && (!childStrengthReduction.equals(""))) {
      relation.addProperty(KNOBOT.minimumChildStrengthReduction, model.createTypedLiteral(Float
          .parseFloat(childStrengthReduction)));
    }
    String comparativeStrengthString = requestBody
        .getParameter("comparativeStrength");
    if ((!keepStrength) && (comparativeStrengthString != null)
        && (!comparativeStrengthString.equals(""))) {
      float comparativeStrength = Float
          .parseFloat(comparativeStrengthString);
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 = getCountryByCode(codeOrig);
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_NewRelation") != null) {
        Resource target = model.createResource(new EnhancedRequest(
            request).getRequestURLWithoutParams().toString());
        perform(target, request);
      }
    } catch (ClassCastException e) {
View Full Code Here

   * @see ch.osar.cms.rssedit.RSSPostAction#perform(com.hp.hpl.jena.rdf.model.Resource,
   *           org.wymiwyg.commons.util.http.MultiPartServletRequest)
   */
  private void perform(Resource relationSource, Request request)
      throws HandlerException {
    MultiPartBody requestBody = (MultiPartBody) request.getBody();
    String language = requestBody.getParameter("language");
    String targetString = requestBody.getParameter("target");
    String targetTypeString = requestBody.getParameter("targetType");
    String relationSourceString = requestBody.getParameter("source");
    boolean inline = "inline".equals(requestBody.getParameter("linkType"));
    if ((relationSourceString != null)
        && (!"".equals(relationSourceString))) {
      try {
        relationSource = model.createResource(new URL(new URL(
            relationSource.toString()), relationSourceString)
            .toString());
      } catch (MalformedURLException e) {
        throw new HandlerException(e);
      }
    }
    if (targetString.equals("http://") || targetString.equals("")) {
      throw new HandlerException("Must specify a target");
    }
    Resource relationTarget;
    try {
      relationTarget = getTarget(targetTypeString, targetString, new URL(
          relationSource.getURI()));
    } catch (MalformedURLException e) {
      throw new HandlerException(e);
    }
    ResIterator relations = model.listSubjectsWithProperty(KNOBOT.target,
        relationTarget);
    while (relations.hasNext()) {
      Resource current = relations.nextResource();
      if (current.hasProperty(KNOBOT.source, relationSource)) {
        RelationManager.removeRelation(current);
        current.removeProperties();
      } else {
        log.debug("Resource unequal: "
            + current.getProperty(KNOBOT.source).getResource()
            + " ," + relationSource);
      }
    }
    relations.close();
    Resource newRelation = model.createResource(KNOBOT.Relation);

    float strength;
    try {
      strength = Float.parseFloat(requestBody.getParameter("strength"));
    } catch (Exception ex) {
      strength = (float) 1;//0.9;
    }
    newRelation.addProperty(KNOBOT.strength,  model.createTypedLiteral(strength));
    float strengthReduction;
    try {
      strengthReduction = Float.parseFloat(requestBody
          .getParameter("strengthReduction"));
    } catch (Exception ex) {
      strengthReduction = DefaultValuesHandler.getDefaultStrengthReduction(model);
    }
    newRelation.addProperty(KNOBOT.strengthReduction, model.createTypedLiteral(strengthReduction));
    String childStrengthString = requestBody.getParameter("childStrength");
    float childStrength;
    if (childStrengthString != null) {
      if (!childStrengthString.equals("")) {
        childStrength = Float.parseFloat(childStrengthString);

      } else {
        childStrength = DefaultValuesHandler
            .getDefaultChildStrength(model);
      }
      newRelation.addProperty(KNOBOT.childStrength, model.createTypedLiteral(childStrength));
    } else {
      childStrength = 0; //so it does not try to aggregate the
      // source
    }
    String childStrengthReduction = requestBody
        .getParameter("minimumChildStrengthReduction");
    if ((childStrengthReduction != null)
        && (!childStrengthReduction.equals(""))) {
      newRelation.addProperty(KNOBOT.minimumChildStrengthReduction, model.createTypedLiteral(Float
          .parseFloat(childStrengthReduction)));
    }
    newRelation.addProperty(KNOBOT.source, relationSource);
    newRelation.addProperty(KNOBOT.target, relationTarget);
    Literal effectiveDateLiteral = model.createTypedLiteral(new W3CDateFormat()
                .format(new Date()), XSDDatatype.XSDdateTime);
    newRelation.addProperty(KNOBOT.effectiveDate, effectiveDateLiteral);
    if (inline) {
        newRelation.addProperty(RDF.type, KNOBOT.InlineRelation);
    }
    String targetLabel = requestBody.getParameter("targetLabel");
    if (targetLabel == null) {
      targetLabel = requestBody.getParameter("label");
    }
    if ((targetLabel != null) && (!targetLabel.equals(""))) {
      newRelation.addProperty(KNOBOT.targetLabel, targetLabel, language);
    }
    String sourceLabel = requestBody.getParameter("sourceLabel");
    if ((sourceLabel != null) && (!sourceLabel.equals(""))) {
      newRelation.addProperty(KNOBOT.sourceLabel, sourceLabel, language);
    }
    String feedURLParam = requestBody.getParameter("feedURL");
    if ((feedURLParam != null) && (!feedURLParam.equals(""))) {
      try {
        relationTarget.addProperty(AGGREGATOR.feed, model
            .createResource(new URL(feedURLParam).toString()));
      } catch (MalformedURLException e1) {
        throw new RuntimeException(e1);
      }
    }
    if ("true".equals(requestBody.getParameter("isChannel"))) {
      log.warn("usage of deprecated isChannel argument");
      relationTarget.addProperty(RDF.type, RSS.channel);
    }
    RelationManager.addRelation(newRelation);
    if (childStrength > 0) {
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;
    body = (MultiPartBody) request.getBody();
    boolean stop;
    if (body.getParameter("action_StopAggregate") != null) {
      stop = true;
    } else {
      if (body.getParameter("action_SetAggregate") != null) {
        stop = false;
      } else {
        chain.doNext(request, response);
        return;
      }
    }
    String aggregatedParam = body.getParameter("channel");
    Resource relationSource = model.createResource(new EnhancedRequest(
        request).getFullRequestURL().toString());
    String aggregatedURL;
    try {
      aggregatedURL = new URL(new URL(relationSource.getURI()),
          aggregatedParam).toString();
    } catch (MalformedURLException e) {
      log.error("Error setting/removing aggregation", e);
      throw new RuntimeException(e);
    }
   
   
    Resource aggregated = model.createResource(aggregatedURL);
    ResIterator aggregations = model.listSubjectsWithProperty(
        AGGREGATOR.aggregated, aggregated);
    while (aggregations.hasNext()) {
      Resource current = aggregations.nextResource();
      current.removeProperties();
    }
    if (!stop) {
      int interval = Integer.parseInt(body.getParameter("interval"));
      Resource newAggregator = model.createResource(AGGREGATOR.Aggregator);
      newAggregator.addProperty(AGGREGATOR.aggregated, aggregated);
      newAggregator.addProperty(AGGREGATOR.interval, model.createTypedLiteral(interval));
      newAggregator.addProperty(AGGREGATOR.nextDownload, model.createTypedLiteral(System
          .currentTimeMillis()));
      String feedURLParam = body.getParameter("feedURL");
      if ((feedURLParam != null) && (!feedURLParam.equals(""))) {
        try {
          aggregated.addProperty(AGGREGATOR.feed, model.createResource(
              new URL(feedURLParam).toString()));
        } catch (MalformedURLException e1) {
          throw new RuntimeException(e1);
        }
      }
      String defaultLanguageParam = body.getParameter("defaultLanguage");
      if ((defaultLanguageParam != null) && (!defaultLanguageParam.equals(""))) {
        newAggregator.addProperty(AGGREGATOR.defaultLanguage, defaultLanguageParam);
      }
    }
    chain.doNext(request, response);
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.