Package org.w3c.tools.resources

Examples of org.w3c.tools.resources.FramedResource


      return null;
  }
  synchronized (this) {
      int num = 0;
      HTTPFrame refframe = null;
      FramedResource resource = null;
      do {
    try {
        resource = (FramedResource)variants[num].unsafeLock();
        refframe = (HTTPFrame) resource.getFrame(httpFrameClass);
    } catch (InvalidResourceException ex) {
        //ex.printStackTrace();
        //FIXME
    } catch (Exception fex) {
        fex.printStackTrace();
    } finally {
        variants[num].unlock();
    }
    num++;
      } while ((refframe == null) && (num < variants.length));
      // not enough variants, abort
      if (variants.length - num < 1)
    return null;
 
      String language = refframe.getContentLanguage();
      String encoding = refframe.getContentEncoding();
      String charset  = refframe.getCharset();
      MimeType mtype  = refframe.getContentType();
     
      HTTPFrame itsframe = null;
      for (int i = num; i < variants.length; i++) {
    try {
        resource = (FramedResource)variants[i].unsafeLock();
        itsframe = (HTTPFrame)
                     resource.unsafeGetFrame(httpFrameClass);
        if (language != null) {
      if (!language.equals(itsframe.getContentLanguage())) {
          b_language = true;
      }
        } else {
View Full Code Here


      DirectoryResource parent= (DirectoryResource)r_parent.unsafeLock();
      for (int i = 0 ; i < variants.length ; i++) {
    tmpres = parent.lookup(variants[i]) ;
    if (tmpres != null) {
        try {
      FramedResource resource =
            (FramedResource)tmpres.unsafeLock() ;
      NegotiatedFrame itsframe = (NegotiatedFrame)
            resource.getFrame(negotiatedFrameClass);
      if (itsframe == null) {
          checked.addElement (variants[i]);
      }
        } catch (InvalidResourceException ex) {
        } finally {
View Full Code Here

      HttpAcceptEncoding encodings[] = request.getAcceptEncoding() ;
      for (int i = 0 ; i < states.size() ; i++) {
    VariantState state    = (VariantState) states.elementAt(i) ;
    ResourceReference rr  = state.getResource();
    try {
        FramedResource resource = (FramedResource)rr.unsafeLock() ;
        HTTPFrame itsframe =
      (HTTPFrame) resource.unsafeGetFrame(httpFrameClass);
        if (itsframe != null) {
      String ve;
      ve = (String) itsframe.unsafeGetValue(
                                ATTR_CONTENT_ENCODING, null);
      if ( ve == null ) {
View Full Code Here

      for (int i = 0 ; i < states.size() ; i++ ) {
    VariantState state = (VariantState) states.elementAt(i) ;
    // Get the most specific match for this variant:
    ResourceReference rr = state.getResource();
    try {
        FramedResource resource = (FramedResource)rr.unsafeLock() ;
        HTTPFrame itsframe =
      (HTTPFrame) resource.unsafeGetFrame(httpFrameClass);
        if (itsframe != null) {
      MimeType vt;
      vt = (MimeType) itsframe.unsafeGetValue(
                                    ATTR_CONTENT_TYPE, null);
      String fcharset = vt.getParameterValue("charset");
View Full Code Here

      boolean  varyLang    = false ;
      for (int i = 0 ; i < states.size() ; i++) {
    VariantState state    = (VariantState) states.elementAt(i) ;
    ResourceReference rr  = state.getResource();
    try {
        FramedResource resource = (FramedResource)rr.unsafeLock() ;
        HTTPFrame itsframe =
      (HTTPFrame) resource.getFrame(httpFrameClass);
        if (itsframe != null) {
      String lang;
      lang = (String) itsframe.unsafeGetValue(
                                ATTR_CONTENT_LANGUAGE, null);
      if ( lang == null ) {
View Full Code Here

      for (int i = 0 ; i < states.size() ; i++ ) {
    VariantState state = (VariantState) states.elementAt(i) ;
    // Get the most specific match for this variant:
    ResourceReference rr = state.getResource();
    try {
        FramedResource resource = (FramedResource)rr.unsafeLock() ;
        HTTPFrame itsframe =
      (HTTPFrame) resource.unsafeGetFrame(httpFrameClass);
        if (itsframe != null) {
      MimeType vt;
      vt = (MimeType) itsframe.unsafeGetValue(
                                    ATTR_CONTENT_TYPE, null);
      int jmatch = -1 ;
View Full Code Here

  // Build a vector of variant negociation states, one per variants:
  Vector states = new Vector (variants.length) ;
  for (int i = 0 ; i < variants.length ; i++) {
      double qs = 1.0 ;
      try {
    FramedResource resource =
        (FramedResource) variants[i].unsafeLock() ;
    HTTPFrame itsframe =
        (HTTPFrame) resource.unsafeGetFrame(httpFrameClass);
    if (itsframe != null) {
        if ( itsframe.unsafeDefinesAttribute (ATTR_QUALITY) )
      qs = itsframe.unsafeGetQuality() ;
        if ( qs > REQUIRED_QUALITY )
      states.addElement(new VariantState (variants[i], qs)) ;
    }
      } catch (InvalidResourceException ex) {
    //FIXME
      } finally {
    variants[i].unlock();
      }
  }
  // Content-encoding negociation:
  if ( debug ) {
      printNegotiationState ("init:", states) ;
  }
  if ( negotiateContentEncoding (states, request) ) {
      // Remains a single acceptable variant:
      return ((VariantState) states.elementAt(0)).getResource() ;
  }
  if ( debug ) {
      printNegotiationState ("encoding:", states) ;
  }
  // Charset quality negociation:
  if ( negotiateCharsetQuality (states, request) ) {
      // Remains a single acceptable variant:
      return ((VariantState) states.elementAt(0)).getResource() ;
  }
  if ( debug ) {
      printNegotiationState ("charset:", states) ;
  }
  // Language quality negociation:
  if ( negotiateLanguageQuality (states, request) ) {
      // Remains a single acceptable variant:
      return ((VariantState) states.elementAt(0)).getResource() ;
  }
  if ( debug ) {
      printNegotiationState ("language:", states) ;
  }
  // Content-type negociation:
  if ( negotiateContentType (states, request) ) {
      // Remains a single acceptable variant:
      return ((VariantState) states.elementAt(0)).getResource() ;
  }
  if ( debug ) {
      printNegotiationState ("type:", states) ;
  }
  // If we reached this point, this means that multiple variants are
  // acceptable at this point. Keep the ones that have the best quality.
  if ( debug ) {
      printNegotiationState ("before Q selection:", states) ;
  }
  double qmax = REQUIRED_QUALITY ;

  for (int i=0; i< states.size() ; ) {
      VariantState state = (VariantState) states.elementAt(i) ;
      if ( state.getQ() > qmax ) {
    for (int j = i ; j > 0 ; j--)
        states.removeElementAt(0) ;
    qmax = state.getQ() ;
    i = 1 ;
      } else {
    if ( state.getQ() < qmax)
        states.removeElementAt(i) ;
    else
        i++;
      }
  }
  if ( debug )
      printNegotiationState ("After Q selection:", states) ;
  if ( qmax == REQUIRED_QUALITY ) {

      Reply reply = request.makeReply(HTTP.NOT_ACCEPTABLE) ;
       HtmlGenerator g = new HtmlGenerator("No acceptable");
       g.append("<P>The resource cannot be served according to the "
          + "headers sent</P>");
       reply.setStream (g) ;
      throw new HTTPException (reply) ;
  } else if ( states.size() == 1 ) {
      return ((VariantState) states.elementAt(0)).getResource() ;
  } else {
      // Respond with multiple choice (for the time being, there should
      // be a parameter to decide what to do.
      Reply reply = request.makeReply(HTTP.MULTIPLE_CHOICE) ;
      HtmlGenerator g = new HtmlGenerator ("Multiple choice for "+
             resource.getIdentifier()) ;
      g.append ("<ul>") ;
      for (int i = 0 ; i < states.size() ; i++) {
    VariantState state = (VariantState) states.elementAt(i) ;
    String name = null;
    ResourceReference rr = state.getResource();
View Full Code Here

      etags = t_etags;
  }

  if (etags != null) {
      // yeah go for it!
      FramedResource resource;
      HttpEntityTag frametag;
      for (int i = 0 ; i < variants.length ; i++) {
    try {
        resource = (FramedResource)variants[i].unsafeLock() ;
        itsframe = (HTTPFrame)resource.getFrame(httpFrameClass);
        if (itsframe != null) {
      frametag = itsframe.getETag();
      if (frametag == null) {
          continue;
      }
      // Do we have a winner?
      try {
          for (int j=0; j<etags.length; j++)
        if(frametag.getTag().equals(etags[j].getTag()))
            return variants[i];
      } catch (NullPointerException ex) {
          // if the list of etag contains a null
          // it should never happen and the try doesn't cost
      }
        }
    } catch (InvalidResourceException ex) {
        //FIXME
    } finally {
        variants[i].unlock();
    }
      }
      // no matching variants...
      Reply reply = request.makeReply(HTTP.NOT_FOUND);
      reply.setContent ("<h1>Document not found</h1>"+
            "<p>The document "+request.getURL()+
            " has no acceptable variants "+
            "according to the ETag sent");
      throw new HTTPException (reply);
  }
  // if we are strict, don't go any further, etags
  // is the mandatory thing, otherwise PUT on the direct version
  if (getPutPolicy()) {
      Reply reply = request.makeReply(HTTP.NOT_FOUND);
      reply.setContent ("<h1>Document not found</h1>"+
            "<p>The document "+request.getURL()+
            " has no acceptable variants "+
            " for a PUT, as no ETags were sent");
      throw new HTTPException (reply);
  }
  // now filter out variants
  nb_v = variants.length;
  MimeType type = request.getContentType();
  String encodings[] = request.getContentEncoding();
  String languages[] = request.getContentLanguage();
  ResourceReference rr;

  if (type != null || encodings != null || languages != null) {
      // the request is not too bad ;)
      for (int i = 0 ; i < variants.length ; i++) {
    if (variants[i] == null)
        continue;
    rr = variants[i];
    try {
        resource = (FramedResource)rr.unsafeLock() ;
        itsframe = (HTTPFrame)resource.getFrame(httpFrameClass);
        if (itsframe == null) {
      nb_v--;
      variants[i] = null;
      continue;
        }
        // remove the non matching mime types
        if (type != null) {
      MimeType fmt = itsframe.getContentType();
      if (fmt == null || (fmt.match(type) !=
              MimeType.MATCH_SPECIFIC_SUBTYPE)) {
          nb_v--;
          variants[i] = null;
          continue;
      }
        }
        // remove the non matching languages
        if (languages != null) {
      String language = itsframe.getContentLanguage();
      nb_v--;
      variants[i] = null;
      if (language == null) {
          continue;
      }
      for (int j=0; j<languages.length; j++) {
          if (language.equals(languages[j])) {
        nb_v++;
        variants[i] = rr;
        break;
          }
      }
        }
        // remove the non matching encodings       
        if (encodings != null) {
      String encoding = itsframe.getContentEncoding();
      nb_v--;
      variants[i] = null;
      if (encoding == null) {
          continue;
      }
      for (int j=0; j<encodings.length; j++) {
          if (encoding.equals(languages[j])) {
        nb_v++;
        variants[i] = rr;
        break;
          }
      }
        }
    } catch (InvalidResourceException ex) {
        //FIXME
    } finally {
        rr.unlock();
    }
      }
      // a winner!
      if (nb_v == 1) {
    for (int i=0; i< variants.length; i++) {
        if (variants[i] != null)
      return variants[i];
    }
      }
      // no document matching
      if (nb_v <= 0 ) {
    Reply reply = request.makeReply(HTTP.NOT_FOUND);
    reply.setContent ("<h1>Document not found</h1>"+
          "<p>The document "+request.getURL()+
          " has no acceptable variants "+
          " for a PUT");
    throw new HTTPException (reply);
      }
  }
  // now we have multiple choice :(
  String name;
  Reply reply = request.makeReply(HTTP.MULTIPLE_CHOICE) ;
  HtmlGenerator g = new HtmlGenerator ("Multiple choice for "+
               resource.getIdentifier()) ;
  g.append ("<ul>") ;
  for (int i = 0 ; i < variants.length ; i++) {
      if (variants[i] != null) {
    try {
        name = variants[i].unsafeLock().getIdentifier();
View Full Code Here

    // the failure will be processed in perform
    return false;
      }
      if (selected != null) {
    try {
        FramedResource resource =
      (FramedResource) selected.unsafeLock();
        resource.lookup(ls, lr);
    } catch (InvalidResourceException ex) {
        // the failure will be processed in perform
    } finally {
        selected.unlock();
    }
View Full Code Here

      error.setContent("Error negotiating among resource's variants.");
      throw new HTTPException(error) ;
  }

  try {
      FramedResource resource = (FramedResource) selected.unsafeLock();
      Reply reply = (Reply)resource.perform(request) ;
      reply.setHeaderValue(reply.H_VARY, getVary());
      HTTPFrame itsframe =
    (HTTPFrame) resource.unsafeGetFrame(httpFrameClass);
      if (itsframe != null) {
    reply.setContentLocation(
          itsframe.getURL(request).toExternalForm()) ;
    return reply;
      }
View Full Code Here

TOP

Related Classes of org.w3c.tools.resources.FramedResource

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.