⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpegxmpframe.java

📁 很棒的web服务器源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		return true;	    else		return false;	}    }    protected HttpAccept getMatchingAccept(HttpAccept accepts[],					   MimeType mime)     {	int jmatch = -1 ;	int jidx   = -1 ;	for (int i = 0 ; i < accepts.length ; i++) {	    try {		int match = mime.match(accepts[i].getMimeType());		if ( match > jmatch ) {		    jmatch = match ;		    jidx   = i ;		}	    } catch (HttpInvalidValueException ivex) {		// There is a bad acept header here		// let's be cool and ignore it		// FIXME we should answer with a Bad Request	    }	}	if (jidx < 0)	    return null;	return accepts[jidx];    }    /**     * Perform a HEAD request for the associated FileResource.     * @param request the incomming request.     * @return A Reply instance     * @exception ProtocolException If processsing the request failed.     * @exception ResourceException If the resource got a fatal error.     */    protected Reply headFileResource(Request request) 	throws ProtocolException, ResourceException    {	if (fresource == null) 	    throw new ResourceException("this frame is not attached to a "+					    "FileResource. ("+					    resource.getIdentifier()+")");	Reply reply = null;	fresource.checkContent();	updateCachedHeaders();	// hack, if ;text/html is there,	// it will be added at first place of the accept 	String param = null;	String sfile = request.getURL().getFile();	int pos = sfile.indexOf(';');	if (pos != -1) {	    param = (String) request.getState("type");	}	if (param != null) {	    HttpAccept acc[] = request.getAccept();	    HttpAccept newacc[] = null;	    if (acc != null) {		newacc = new HttpAccept[acc.length+1];		System.arraycopy(acc, 0, newacc, 1, acc.length);	    } else {		newacc = new HttpAccept[1];	    }	    try {		newacc[0] = HttpFactory.makeAccept(new MimeType(param), 1.1);		request.setAccept(newacc);	    } catch (MimeTypeFormatException ex) {		// not a valid mime type... maybe something else, do not care	    }	}	boolean xmpOnly = negotiate(request);	HttpEntityTag etag = null;	if (xmpOnly)	    etag = getXMPETag();	else	    etag = getETag();	// Check validators:	int cim = checkIfMatch(request, etag);	if ((cim == COND_FAILED) || (cim == COND_WEAK)) {	    reply = request.makeReply(HTTP.PRECONDITION_FAILED);	    reply.setContent("Pre-conditions failed.");	    reply.setContentMD5(null);	    return reply;	}	if ( checkIfUnmodifiedSince(request) == COND_FAILED ) {	    reply = request.makeReply(HTTP.PRECONDITION_FAILED);	    reply.setContent("Pre-conditions failed.");	    reply.setContentMD5(null);	    return reply;	}	if (checkValidators(request, etag) == COND_FAILED) {	    reply = createDefaultReply(request, HTTP.NOT_MODIFIED);	    reply.setETag(etag);	    reply.setContentMD5(null);	    return reply;	}		if (! fresource.getFile().exists()) {	    return deleteMe(request);	} else {	    if (xmpOnly) {		reply = createXMPReply(request);		reply.setStream((InputStream) null);	    } else {		reply = createDefaultReply(request, HTTP.OK);		reply.setVary(vary);	    }	    if (request.hasState(STATE_CONTENT_LOCATION))		reply.setContentLocation(getURL(request).toExternalForm());	    return reply;	}    }    /**     * Get for FileResource     * @param request the incomming request.     * @return A Reply instance     * @exception ProtocolException If processsing the request failed.     * @exception ResourceException If the resource got a fatal error.     */    protected Reply getFileResource(Request request) 	throws ProtocolException, ResourceException    {	if (fresource == null) 	    throw new ResourceException("this frame is not attached to a "+					"FileResource. ("+					resource.getIdentifier()+")");	Reply reply = null;	File file = fresource.getFile() ;	fresource.checkContent();	updateCachedHeaders();	String param = null;	String sfile = request.getURL().getFile();	int pos = sfile.indexOf(';');	if (pos != -1) {	    param = (String) request.getState("type");	}	if (param != null) {	    HttpAccept acc[] = request.getAccept();	    HttpAccept newacc[] = null;	    if (acc != null) {		newacc = new HttpAccept[acc.length+1];		System.arraycopy(acc, 0, newacc, 1, acc.length);	    } else {		newacc = new HttpAccept[1];	    }	    try {		newacc[0] = HttpFactory.makeAccept(new MimeType(param), 1.1);		request.setAccept(newacc);	    } catch (MimeTypeFormatException ex) {		// not a valid mime type... maybe something else, do not care	    }	}	boolean xmpOnly = negotiate(request);	HttpEntityTag etag = null;	if (xmpOnly)	    etag = getXMPETag();	else	    etag = getETag();	// Check validators:	int cim = checkIfMatch(request, etag);	if ((cim == COND_FAILED) || (cim == COND_WEAK)) {	    reply = request.makeReply(HTTP.PRECONDITION_FAILED);	    reply.setContent("Pre-conditions failed.");	    reply.setContentMD5(null);	    return reply;	}	if ( checkIfUnmodifiedSince(request) == COND_FAILED ) {	    reply = request.makeReply(HTTP.PRECONDITION_FAILED);	    reply.setContent("Pre-conditions failed.");	    reply.setContentMD5(null);	    return reply;	}	if (checkValidators(request, etag) == COND_FAILED) {	    reply = createDefaultReply(request, HTTP.NOT_MODIFIED);	    reply.setETag(etag);	    reply.setContentMD5(null);	    return reply;	}	// Does this file really exists, if so send it back	if ( file.exists() ) {	    if (xmpOnly) {		reply = createXMPReply(request);	    } else {		reply = createFileReply(request);	    }	    if (request.hasState(STATE_CONTENT_LOCATION))		reply.setContentLocation(getURL(request).toExternalForm());	    return reply;	} else {	    return deleteMe(request);	}    }    /**     * Allow PUT based only on ETags, otherwise PUT is done on the image itself     * @see HTTPFrame.putFileResource     */    protected Reply putFileResource(Request request)	throws ProtocolException, ResourceException    {	// check if it is the right resource below!	if (!(fresource instanceof ImageFileResource)) {	    return super.putFileResource(request);	}	Reply reply = null;	int status = HTTP.OK;	fresource.checkContent();	updateCachedHeaders();	// Is this resource writable ?	if ( ! getPutableFlag() ) {	    Reply error = request.makeReply(HTTP.NOT_ALLOWED) ;	    error.setContent("Method PUT not allowed.") ;	    throw new HTTPException (error) ;	}	HttpEntityTag etag = getXMPETag();	// no IfMatch, or no matching ETag, maybe a PUT on the image	int cim = checkIfMatch(request, etag);	if ((request.getIfMatch() == null) || 	    (cim == COND_FAILED) || (cim == COND_WEAK)) {	    return super.putFileResource(request);	}	// check all the others validator	// Check remaining validators (checking if-none-match is lame	// as we already require the If-Match	if ((checkIfNoneMatch(request, etag) == COND_FAILED)	    || (checkIfModifiedSince(request) == COND_FAILED)	    || (checkIfUnmodifiedSince(request) == COND_FAILED)) {	    Reply r = request.makeReply(HTTP.PRECONDITION_FAILED);	    r.setContent("Pre-condition failed.");	    return r;	}	// Check the request:	InputStream in = null;	try {	    in = request.getInputStream();	    if ( in == null ) {		Reply error = request.makeReply(HTTP.BAD_REQUEST) ;		error.setContent ("<p>Request doesn't have a valid content.");		throw new HTTPException (error) ;	    }	} catch (IOException ex) {	    throw new ClientException(request.getClient(), ex);	}	// We do not support (for the time being) put with ranges:	if ( request.hasContentRange() ) {	    Reply error = request.makeReply(HTTP.BAD_REQUEST);	    error.setContent("partial PUT not supported.");	    throw new HTTPException(error);	}	// Check that if some type is provided it doesn't conflict:	if ( request.hasContentType() ) {	    MimeType rtype = request.getContentType() ;	    MimeType type  = xmptype ;	    if ( type == null ) {		setValue (ATTR_CONTENT_TYPE, rtype) ;	    } else if ( rtype.match (type) < 0 ) {		if (debug) {		    System.out.println("No match between: ["+				       rtype.toString()+"] and ["+				       type.toString()+"]");		}		Reply error = request.makeReply(HTTP.UNSUPPORTED_MEDIA_TYPE) ;		error.setContent ("<p>Invalid content type: "+type.toString());		throw new HTTPException (error) ;	    }	}	ImageFileResource ifresource = (ImageFileResource) fresource;	// Write the body back to the file:	try {	    // We are about to accept the put, notify client before continuing	    Client client = request.getClient();	    if ( client != null  && request.getExpect() != null ) {		client.sendContinue();	    }	    if ( ifresource.newMetadataContent(request.getInputStream()) )		status = HTTP.CREATED;	    else		status = HTTP.NO_CONTENT;	} catch (IOException ex) {	    throw new ClientException(request.getClient(), ex);	}	if ( status == HTTP.CREATED ) {	    reply = createXMPReply(request, status);	    reply.setContent("<P>Resource succesfully created");	    if (request.hasState(STATE_CONTENT_LOCATION))		reply.setContentLocation(getURL(request).toExternalForm());            // Henrik's fix, create the Etag on 201	    if (fresource != null) {		// We only take car eof etag here:		if ( etag == null ) {		    reply.setETag(getXMPETag());		}	    }	    reply.setLocation(getURL(request));	    reply.setContent ("<p>Entity body saved succesfully !") ;	} else {	    reply = createXMPReply(request, status);	}	return reply ;    }	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -