001: /* Generated By:JavaCC: Do not edit this line. DavIf.java */
002: /*
003: * $Id : $
004: * $Source : $
005: * $Log: DavIf.java,v $
006: * Revision 1.5 2005/11/30 11:27:24 ss150821
007: * 6356996 - Srap Code base needs to save files in the unix file format and not windows
008: *
009: * Revision 1.4 2005/02/23 09:03:11 ss150821
010: * RFE 6223490 - SRA Should use JDK based logging
011: *
012: * Revision 1.3 2004/07/27 12:56:19 vt126379
013: * RFE#5075809, CRT#99
014: *
015: * Revision 1.2 2003/08/11 13:36:59 mm132998
016: * Bug : 4893409
017: *
018: * Revision 1.1 2003/04/15 05:22:09 mm132998
019: * WebDAV support
020: *
021: *
022: */
023: package com.sun.portal.rproxy.connectionhandler.webdav;
024:
025: import java.io.StringReader;
026: import java.util.Stack;
027: import java.util.logging.Level;
028: import java.util.logging.Logger;
029:
030: import com.sun.portal.log.common.PortalLogger;
031:
032: public class DavIf implements DavIfConstants {
033:
034: private Stack st = new Stack();
035:
036: // private static Logger logger =
037: // Logger.getLogger("com.sun.portal.sra.rproxy");
038: private static Logger logger = PortalLogger.getLogger(DavIf.class);
039:
040: public DavIf(String inputString) {
041: this (new StringReader(inputString));
042: }
043:
044: private String parseMe(String toParse, String gwUrl,
045: boolean removeGWURL) throws ParseException {
046:
047: String result = toParse;
048: If(toParse);
049: // Now parse the string using the linked list.
050: if (st.size() > 0) {
051: StringBuffer newStr = new StringBuffer();
052: newStr.append(result);
053: while (st.size() > 0) {
054: Token t = (Token) st.pop();
055: if (removeGWURL) {
056: String tStr = newStr.substring(t.beginColumn,
057: t.endColumn);
058:
059: String unwrittenStr = UnRewriter.unrewrite(tStr);
060: if (unwrittenStr.length() != (t.endColumn - t.beginColumn)) {
061: newStr.delete(t.beginColumn, t.endColumn);
062: newStr.insert(t.beginColumn, unwrittenStr);
063: }
064: } else {
065: newStr.insert(t.beginColumn - 1, gwUrl);
066: }
067: }
068: result = newStr.toString();
069: }
070: return result;
071: }
072:
073: public static String parseIfHeader(String ifHeader, String gwUrl,
074: boolean removeGWURL) throws ParseException {
075:
076: if (!gwUrl.endsWith("/")) {
077: gwUrl += "/";
078: }
079:
080: DavIf parser = new DavIf(ifHeader);
081: // System.out.println("Orginal string : "+ifHeader);
082: String outputString = parser.parseMe(ifHeader, gwUrl,
083: removeGWURL);
084: // System.out.println("Parsed string : "+outputString);
085: // logger.info("Orginal string for IF header parser : " + ifHeader);
086: Object[] params0 = { ifHeader };
087: logger.log(Level.INFO, "PSSRRPROXY_CSPRCW000", params0);
088: // logger.info("Parsed string : " + outputString);
089: Object[] params1 = { outputString };
090: logger.log(Level.INFO, "PSSRRPROXY_CSPRCW001", params1);
091: return outputString;
092: }
093:
094: public static void main(String args[]) throws ParseException {
095:
096: String ifHeader = "If: CodedURL ( CodedURL [ Entity-Tag-String]) ([Entity-Tag-String]) CodedURL ([Entity-Tag-String])";
097: DavIf parser = new DavIf(ifHeader);
098: System.out.println("Orginal string : " + ifHeader);
099: System.out.println("Parsed string : "
100: + parser.parseMe(ifHeader, "https://MridulM/", false));
101: }
102:
103: final public String If(String header) throws ParseException {
104: jj_consume_token(IFTOKEN);
105: jj_consume_token(COLON);
106: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
107: case LEFTBRACKET:
108: label_1: while (true) {
109: header = NoTagList(header);
110: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
111: case LEFTBRACKET:
112: ;
113: break;
114: default:
115: jj_la1[0] = jj_gen;
116: break label_1;
117: }
118: }
119: break;
120: case 12:
121: label_2: while (true) {
122: header = TaggedList(header);
123: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
124: case 12:
125: ;
126: break;
127: default:
128: jj_la1[1] = jj_gen;
129: break label_2;
130: }
131: }
132: break;
133: default:
134: jj_la1[2] = jj_gen;
135: jj_consume_token(-1);
136: throw new ParseException();
137: }
138: jj_consume_token(0);
139: {
140: if (true)
141: return header;
142: }
143: throw new Error("Missing return statement in function");
144: }
145:
146: final public String NoTagList(String header) throws ParseException {
147: header = List(header);
148: {
149: if (true)
150: return header;
151: }
152: throw new Error("Missing return statement in function");
153: }
154:
155: final public String TaggedList(String header) throws ParseException {
156: header = Resource(header);
157: label_3: while (true) {
158: header = List(header);
159: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
160: case LEFTBRACKET:
161: ;
162: break;
163: default:
164: jj_la1[3] = jj_gen;
165: break label_3;
166: }
167: }
168: {
169: if (true)
170: return header;
171: }
172: throw new Error("Missing return statement in function");
173: }
174:
175: final public String Resource(String header) throws ParseException {
176: header = CodedURL(header);
177: {
178: if (true)
179: return header;
180: }
181: throw new Error("Missing return statement in function");
182: }
183:
184: final public String List(String header) throws ParseException {
185: jj_consume_token(LEFTBRACKET);
186: label_4: while (true) {
187: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
188: case 11:
189: case 12:
190: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
191: case 11:
192: jj_consume_token(11);
193: break;
194: default:
195: jj_la1[4] = jj_gen;
196: ;
197: }
198: header = StateToken(header);
199: break;
200: case LEFTSQUAREBRACKET:
201: EntityTag();
202: break;
203: default:
204: jj_la1[5] = jj_gen;
205: jj_consume_token(-1);
206: throw new ParseException();
207: }
208: switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
209: case LEFTSQUAREBRACKET:
210: case 11:
211: case 12:
212: ;
213: break;
214: default:
215: jj_la1[6] = jj_gen;
216: break label_4;
217: }
218: }
219: jj_consume_token(RIGHTBRACKET);
220: {
221: if (true)
222: return header;
223: }
224: throw new Error("Missing return statement in function");
225: }
226:
227: final public String StateToken(String header) throws ParseException {
228: header = CodedURL(header);
229: {
230: if (true)
231: return header;
232: }
233: throw new Error("Missing return statement in function");
234: }
235:
236: final public String CodedURL(String header) throws ParseException {
237: Token x;
238: x = jj_consume_token(12);
239: st.push(x);
240: {
241: if (true)
242: return header.toString();
243: } // "something else";
244:
245: throw new Error("Missing return statement in function");
246: }
247:
248: final public void EntityTag() throws ParseException {
249: jj_consume_token(LEFTSQUAREBRACKET);
250: jj_consume_token(13);
251: jj_consume_token(RIGHTSQUAREBRACKET);
252: }
253:
254: public DavIfTokenManager token_source;
255:
256: SimpleCharStream jj_input_stream;
257:
258: public Token token, jj_nt;
259:
260: private int jj_ntk;
261:
262: private int jj_gen;
263:
264: final private int[] jj_la1 = new int[7];
265:
266: final private int[] jj_la1_0 = { 0x80, 0x1000, 0x1080, 0x80, 0x800,
267: 0x1a00, 0x1a00, };
268:
269: public DavIf(java.io.InputStream stream) {
270: jj_input_stream = new SimpleCharStream(stream, 1, 1);
271: token_source = new DavIfTokenManager(jj_input_stream);
272: token = new Token();
273: jj_ntk = -1;
274: jj_gen = 0;
275: for (int i = 0; i < 7; i++)
276: jj_la1[i] = -1;
277: }
278:
279: public void ReInit(java.io.InputStream stream) {
280: jj_input_stream.ReInit(stream, 1, 1);
281: token_source.ReInit(jj_input_stream);
282: token = new Token();
283: jj_ntk = -1;
284: jj_gen = 0;
285: for (int i = 0; i < 7; i++)
286: jj_la1[i] = -1;
287: }
288:
289: public DavIf(java.io.Reader stream) {
290: jj_input_stream = new SimpleCharStream(stream, 1, 1);
291: token_source = new DavIfTokenManager(jj_input_stream);
292: token = new Token();
293: jj_ntk = -1;
294: jj_gen = 0;
295: for (int i = 0; i < 7; i++)
296: jj_la1[i] = -1;
297: }
298:
299: public void ReInit(java.io.Reader stream) {
300: jj_input_stream.ReInit(stream, 1, 1);
301: token_source.ReInit(jj_input_stream);
302: token = new Token();
303: jj_ntk = -1;
304: jj_gen = 0;
305: for (int i = 0; i < 7; i++)
306: jj_la1[i] = -1;
307: }
308:
309: public DavIf(DavIfTokenManager tm) {
310: token_source = tm;
311: token = new Token();
312: jj_ntk = -1;
313: jj_gen = 0;
314: for (int i = 0; i < 7; i++)
315: jj_la1[i] = -1;
316: }
317:
318: public void ReInit(DavIfTokenManager tm) {
319: token_source = tm;
320: token = new Token();
321: jj_ntk = -1;
322: jj_gen = 0;
323: for (int i = 0; i < 7; i++)
324: jj_la1[i] = -1;
325: }
326:
327: final private Token jj_consume_token(int kind)
328: throws ParseException {
329: Token oldToken;
330: if ((oldToken = token).next != null)
331: token = token.next;
332: else
333: token = token.next = token_source.getNextToken();
334: jj_ntk = -1;
335: if (token.kind == kind) {
336: jj_gen++;
337: return token;
338: }
339: token = oldToken;
340: jj_kind = kind;
341: throw generateParseException();
342: }
343:
344: final public Token getNextToken() {
345: if (token.next != null)
346: token = token.next;
347: else
348: token = token.next = token_source.getNextToken();
349: jj_ntk = -1;
350: jj_gen++;
351: return token;
352: }
353:
354: final public Token getToken(int index) {
355: Token t = token;
356: for (int i = 0; i < index; i++) {
357: if (t.next != null)
358: t = t.next;
359: else
360: t = t.next = token_source.getNextToken();
361: }
362: return t;
363: }
364:
365: final private int jj_ntk() {
366: if ((jj_nt = token.next) == null)
367: return (jj_ntk = (token.next = token_source.getNextToken()).kind);
368: else
369: return (jj_ntk = jj_nt.kind);
370: }
371:
372: private java.util.Vector jj_expentries = new java.util.Vector();
373:
374: private int[] jj_expentry;
375:
376: private int jj_kind = -1;
377:
378: final public ParseException generateParseException() {
379: jj_expentries.removeAllElements();
380: boolean[] la1tokens = new boolean[14];
381: for (int i = 0; i < 14; i++) {
382: la1tokens[i] = false;
383: }
384: if (jj_kind >= 0) {
385: la1tokens[jj_kind] = true;
386: jj_kind = -1;
387: }
388: for (int i = 0; i < 7; i++) {
389: if (jj_la1[i] == jj_gen) {
390: for (int j = 0; j < 32; j++) {
391: if ((jj_la1_0[i] & (1 << j)) != 0) {
392: la1tokens[j] = true;
393: }
394: }
395: }
396: }
397: for (int i = 0; i < 14; i++) {
398: if (la1tokens[i]) {
399: jj_expentry = new int[1];
400: jj_expentry[0] = i;
401: jj_expentries.addElement(jj_expentry);
402: }
403: }
404: int[][] exptokseq = new int[jj_expentries.size()][];
405: for (int i = 0; i < jj_expentries.size(); i++) {
406: exptokseq[i] = (int[]) jj_expentries.elementAt(i);
407: }
408: return new ParseException(token, exptokseq, tokenImage);
409: }
410:
411: final public void enable_tracing() {
412: }
413:
414: final public void disable_tracing() {
415: }
416:
417: }
|