Package org.wymiwyg.wrhapi.util

Examples of org.wymiwyg.wrhapi.util.EnhancedRequest


   * @see org.wymiwyg.rwcf.Handler#handle(org.wymiwyg.wrhapi.Request,
   *      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();
    }
View Full Code Here


   *      org.wymiwyg.rwcf.Response, org.wymiwyg.rwcf.HandlerChain)
   */
  public void handle(Request request, Response response, HandlerChain chain)
      throws HandlerException {
    Model resultModel = ModelFactory.createDefaultModel();
    EnhancedRequest ehRequest = new EnhancedRequest(request);
    LanguageChooser.addLanguageSeq(ehRequest, model, resultModel);
    Resource transaction = resultModel
        .createResource(TRANSACTION.Transaction);
    transaction.addProperty(DC.description, new EnhancedRequest(request)
        .getRootURL().toString());
        Resource user = VirtuserHandler.getSubject();
        if (user != null) {
            resultModel.add(JenaUtil.getExpandedResource(user, 3));
            transaction.addProperty(TRANSACTION.user, user.inModel(resultModel));
View Full Code Here

  private HandlerContext handlerContext;

  public void handleException(Exception e, Request request,
      Response response) throws HandlerException {
    handleException(e, new EnhancedRequest(request), response);
  }
View Full Code Here

    try {
      MultiPartBody body;
      body = (MultiPartBody) request.getBody();
      if (body.getParameter("action_CreateResource") != null) {
        Resource target = model.createResource(new EnhancedRequest(
            request).getRequestURLWithoutParams().toString());
        String typeString = body.getParameter("type");
        Resource type = model.createResource(typeString);
        target.addProperty(RDF.type, type);
        addSuperTypes(target, type);
View Full Code Here

   * @param chain
   * @throws HandlerException
   */
  public void handle(Request request, Response response,
      HandlerChain chain) throws HandlerException {
    String requestURLString = new EnhancedRequest(request)
        .getRequestURLWithoutParams().toString();
    Resource resource = model.createResource(requestURLString);
    if (!resource.hasProperty(RDF.type)) {
      if (model.createResource(requestURLString+"/").hasProperty(RDF.type, WEBDAV.Collection)) {
        resource = model.createResource(requestURLString+"/");
View Full Code Here

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

    logger.info("fileserver filter handling");
    // String extraPath = request.getRequestURI().getPath().toString();
    EnhancedRequest ehRequest = new EnhancedRequest(request);
    HttpResource[] resources = getResources(ehRequest
        .getRequestURLWithoutParams()); // FullRequestURL());
    if (resources.length == 0) {
      logger.warn("FileServerFileter invoked but now resource existing");
      chain.doNext(request, response);
      return;
    }
   
    Arrays.sort(resources, new ResourceComparator(ehRequest));
    //get this eraly just to fail faster
    InputStream dataIn;
    try {
      dataIn = resources[0].getInputStream();
    } catch (IOException e) {
      throw new HandlerException(e);
    }
    Locale locale = resources[0].getLocale();
    if (locale != null) {
      // check if locale in accept-language
      AcceptLanguagesIterator acceptedLangIter = ehRequest
          .getAcceptLanguages();
      boolean acceptable = false;
      while (acceptedLangIter.hasNext()) {
        if (acceptedLangIter.nextAcceptLanguageHeader()
            .getLocaleRange().match(locale)) {
View Full Code Here

  }

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

    EnhancedRequest ehRequest = new EnhancedRequest(request);
    URL requestURL = ehRequest.getRequestURLWithoutParams();
    String path = requestURL.getPath();
    int dotPos = path.indexOf('.', path.lastIndexOf('/'));
    String urlString = requestURL.toString();
    Resource requestResource;

    String extension = null;
    if (dotPos != -1) {
      extension = path.substring(dotPos);
      requestResource = model.createResource(urlString.substring(0,
          urlString.length() - extension.length()));
    } else {
      requestResource = model.createResource(urlString);
    }
    // if (!requestResource.hasProperty(RDF.type, WEBDAV.Resource)
    // && !requestResource.hasProperty(RDF.type, WEBDAV.Collection)) {
    // if (!requestResource.hasProperty(RDF.type)) {
    // all those webdav clients requesting collections without a slash are
    // buggy
    Resource slashedRequestResource = model.createResource(ehRequest
        .getRequestURLWithoutParams().toString()
        + "/");
    if (slashedRequestResource.hasProperty(RDF.type, WEBDAV.Resource)
        || slashedRequestResource.hasProperty(RDF.type,
            WEBDAV.Collection)) {
View Full Code Here

   * @see org.wymiwyg.rwcf.Handler#handle(org.wymiwyg.wrhapi.Request,
   *      org.wymiwyg.rwcf.Response, org.wymiwyg.rwcf.HandlerChain)
   */
  public void handle(Request request, Response response, HandlerChain chain)
      throws HandlerException {
    EnhancedRequest ehRequest = new EnhancedRequest(request);
    Resource resource = model.createResource(ehRequest
        .getRequestURLWithoutParams().toString());
    response
        .setHeader(HeaderName.CONTENT_TYPE,
            "application/java-instance;class=com.hp.hpl.jena.rdf.model.Model");
    Model resultModel = getExpandedResourceStoppingAtNonAnonNoFragment(resource);
View Full Code Here

   * @see org.wymiwyg.rwcf.Handler#handle(org.wymiwyg.wrhapi.Request,
   *      org.wymiwyg.rwcf.Response, org.wymiwyg.rwcf.HandlerChain)
   */
  public void handle(Request request, Response response, HandlerChain chain)
      throws HandlerException {
    Resource target = model.createResource(new EnhancedRequest(request)
        .getFullRequestURL().toString());
    try {
      MultiPartBody body;
      body = (MultiPartBody) request.getBody();
      String origContentType = body.getParameter("origContentType");
View Full Code Here

  }

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

    EnhancedRequest ehRequest = new EnhancedRequest(request);
    String urlString = ehRequest
    .getRequestURLWithoutParams().toString();
    Resource requestResource = model.createResource(urlString);
    if (requestResource.hasProperty(RDF.type, WEBDAV.Resource)
        || requestResource.hasProperty(RDF.type, WEBDAV.Collection)) {
      response.addHeader(HeaderName.DAV, "1");
View Full Code Here

TOP

Related Classes of org.wymiwyg.wrhapi.util.EnhancedRequest

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.