001: // CCPPFrame.java
002: // $Id: CCPPFrame.java,v 1.7 2000/08/16 21:37:34 ylafon Exp $
003: // (c) COPYRIGHT MIT, INRIA and Keio, 2000.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigsaw.ccpp;
007:
008: import java.io.InputStream;
009:
010: import org.w3c.jigsaw.frames.HTTPExtFrame;
011: import org.w3c.jigsaw.http.Reply;
012: import org.w3c.jigsaw.http.Request;
013: import org.w3c.tools.resources.ProtocolException;
014: import org.w3c.tools.resources.ResourceException;
015:
016: /**
017: * @version $Revision: 1.7 $
018: * @author Benoît Mahé (bmahe@w3.org)
019: */
020: public class CCPPFrame extends HTTPExtFrame {
021:
022: static {
023: String classname = "org.w3c.jigsaw.ccpp.CCPPFrame";
024: String methods[] = { "GET", "POST", "HEAD" }; // FIXME PUT? ...
025: registerExtension(CCPP.HTTP_EXT_ID, methods, classname);
026: }
027:
028: /**
029: * Get the CC/PP Request
030: * @param request the HTTP Request
031: * @return a CCPPRequest instance
032: */
033: public CCPPRequest getCCPPRequest(Request request) {
034: return CCPPRequest.getCCPPRequest(request);
035: }
036:
037: /**
038: * Set the Ext and/or C-Ext Header if necessary.
039: * @param request the incomming request.
040: * @param reply the reply
041: * @return the acknowledged reply instance
042: */
043: protected Reply acknowledgeExtension(Request request, Reply reply) {
044: CCPPRequest ccpp = getCCPPRequest(request);
045: return ccpp.acknowledge(reply);
046: }
047:
048: /**
049: * The default GET method.
050: * @param request The request to handle.
051: * @exception ProtocolException If processsing the request failed.
052: * @exception ResourceException If the resource got a fatal error.
053: */
054:
055: public Reply get(Request request) throws ProtocolException,
056: ResourceException {
057: return test_get(request);
058: }
059:
060: /**
061: * For testing only
062: * @param request The request to handle.
063: * @exception ProtocolException If processsing the request failed.
064: * @exception ResourceException If the resource got a fatal error.
065: */
066: public Reply test_get(Request request) throws ProtocolException,
067: ResourceException {
068: CCPPRequest ccpp = getCCPPRequest(request);
069: Reply reply = super .get(request);
070:
071: ProfileRef refs[] = ccpp.getProfileReferences();
072: for (int i = 0; i < refs.length; i++) {
073: try {
074: if (refs[i].isURI()) {
075: System.out.println("Ref[" + i + "] (uri) : "
076: + refs[i].getURI());
077: ccpp.addWarning(reply, CCPP.NOT_APPLIED, refs[i]
078: .getURI());
079: } else {
080: int dn = refs[i].getDiffNumber();
081: System.out.println("Ref[" + i + "] (dif) : (" + dn
082: + ", " + refs[i].getDiffName() + ")");
083: System.out.println(" Diff[" + dn + "] : "
084: + ccpp.getProfileDiff(dn));
085: }
086: } catch (InvalidProfileException ex) {
087: System.out.println("Ref[" + i + "] (invalid) : "
088: + refs[i].getUnparsedRef());
089: }
090: }
091: return reply;
092: }
093:
094: /**
095: * CCPP HEAD method
096: */
097: public Reply head(Request request) throws ProtocolException,
098: ResourceException {
099: Reply reply = null;
100: reply = get(request);
101: reply.setStream((InputStream) null);
102: return reply;
103: }
104:
105: }
|