001
<%
002
Class
cBuffer
003
Private
objFSO, objFile, objDict
004
m_strPathToFile, m_TableBGColor, m_StartTime
005
m_EndTime, m_LineCount, m_intKeyMin, m_intKeyMax
006
m_CodeColor, m_CommentColor, m_StringColor, m_TabSpaces
007
008
Sub
Class_Initialize()
009
TableBGColor =
"white"
010
CodeColor =
"Blue"
011
CommentColor =
"Green"
012
StringColor =
"Gray"
013
TabSpaces =
" "
014
PathToFile =
""
015
016
m_StartTime = 0
017
m_EndTime = 0
018
m_LineCount = 0
019
020
KeyMin = 2
021
KeyMax = 8
022
023
Set
objDict = server.CreateObject(
"Scripting.Dictionary"
)
024
objDict.CompareMode = 1
025
026
CreateKeyWords
027
028
objFSO = server.CreateObject(
"Scripting.FileSystemObject"
029
End
030
031
Class_Terminate()
032
objDict =
Nothing
033
objFSO =
034
035
036
037
Public
Property
Let
CodeColor(inColor)
038
m_CodeColor =
"<font color="
& inColor &
"><Strong>"
039
040
Get
CodeColor()
041
CodeColor = m_CodeColor
042
043
044
CommentColor(inColor)
045
m_CommentColor =
">"
046
047
CommentColor()
048
CommentColor = m_CommentColor
049
050
051
StringColor(inColor)
052
m_StringColor =
053
054
StringColor()
055
StringColor = m_StringColor
056
057
058
TabSpaces(inSpaces)
059
m_TabSpaces = inSpaces
060
061
TabSpaces()
062
TabSpaces = m_TabSpaces
063
064
065
TableBGColor(inColor)
066
m_TableBGColor = inColor
067
068
069
TableBGColor()
070
TableBGColor = m_TableBGColor
071
072
073
ProcessingTime()
074
ProcessingTime = Second(m_EndTime - m_StartTime)
075
076
077
LineCount()
078
LineCount = m_LineCount
079
080
081
PathToFile()
082
PathToFile = m_strPathToFile
083
084
PathToFile(inPath)
085
m_strPathToFile = inPath
086
087
088
KeyMin(inMin)
089
m_intKeyMin = inMin
090
091
KeyMin()
092
KeyMin = m_intKeyMin
093
094
KeyMax(inMax)
095
m_intKeyMax = inMax
096
097
KeyMax()
098
KeyMax = m_intKeyMax
099
100
101
CreateKeyWords()
102
objDict.Add
"abs"
,
"Abs"
103
"and"
"And"
104
"array"
"Array"
105
"call"
"Call"
106
"cbool"
"CBool"
107
"cbyte"
"CByte"
108
"ccur"
"CCur"
109
"cdate"
"CDate"
110
"cdbl"
"CDbl"
111
"cint"
"CInt"
112
"class"
"Class"
113
"clng"
"CLng"
114
"const"
"Const"
115
"csng"
"CSng"
116
"cstr"
"CStr"
117
"date"
"Date"
118
"dim"
"Dim"
119
"do"
"Do"
120
"loop"
"Loop"
121
"empty"
"Empty"
122
"eqv"
"Eqv"
123
"erase"
"Erase"
124
"exit"
"Exit"
125
"false"
"False"
126
"fix"
"Fix"
127
"for"
"For"
128
"next"
"Next"
129
"each"
"Each"
130
"function"
"Function"
131
"global"
"Global"
132
"if"
"If"
133
"then"
"Then"
134
"else"
"Else"
135
"elseif"
"ElseIf"
136
"imp"
"Imp"
137
"int"
"Int"
138
"is"
"Is"
139
"lbound"
"LBound"
140
"len"
"Len"
141
"mod"
"Mod"
142
"new"
"New"
143
"not"
"Not"
144
"nothing"
"Nothing"
145
"null"
"Null"
146
"on"
"On"
147
"error"
"Error"
148
"resume"
"Resume"
149
"option"
"Option"
150
"explicit"
"Explicit"
151
"or"
"Or"
152
"private"
"Private"
153
"property"
"Property"
154
"get"
"Get"
155
"let"
"Let"
156
"set"
"Set"
157
"public"
"Public"
158
"redim"
"Redim"
159
"select"
"Select"
160
"case"
"Case"
161
"end"
"End"
162
"sgn"
"Sgn"
163
"string"
"String"
164
"sub"
"Sub"
165
"true"
"True"
166
"ubound"
"UBound"
167
"while"
"While"
168
"wend"
"Wend"
169
"with"
"With"
170
"xor"
"Xor"
171
172
173
Function
Min(x, y)
174
Dim
tempMin
175
If
x < y
Then
tempMin = x
Else
tempMin = y
176
Min = tempMin
177
178
179
Max(x, y)
180
tempMax
181
x > y
tempMax = x
tempMax = y
182
Max = tempMax
183
184
185
AddKeyword(inKeyWord, inToken)
186
KeyMin = Min(Len(inKeyWord), KeyMin)
187
KeyMax = Max(Len(inKeyWord), KeyMax)
188
189
objDict.Add LCase(inKeyWord), inToken
190
191
192
ParseFile(blnOutputHtml)
193
m_strReadLine, tempString, blnInScriptBlock, blnGoodExtension, i
194
blnEmptyLine
195
196
197
198
Len(PathToFile) = 0
199
Err.Raise 5,
"cBuffer: PathToFile Length Zero"
200
Exit
201
202
203
Select
Case
LCase(Right(PathToFile, 3))
204
"ASP"
"inc"
205
blnGoodExtension =
True
206
207
False
208
209
210
Not
blnGoodExtension
211
"cBuffer: File extension not ASP or inc"
212
213
214
215
objFile = objFSO.OpenTextFile(server.MapPath(PathToFile))
216
217
Response.Write
"<table nowrap bgcolor="
& TableBGColor &
" cellpadding=0 cellspacing=0>"
218
"<tr><td><PRE>"
219
220
m_StartTime = Time()
221
222
Do
While
objFile.AtEndOfStream
223
m_strReadLine = objFile.ReadLine
224
225
blnEmptyLine =
226
Len(m_strReadLine) = 0
227
228
229
230
m_strReadLine = Replace(m_strReadLine, vbTab, TabSpaces)
231
m_LineCount = m_LineCount + 1
232
tempString = LTrim(m_strReadLine)
233
234
' Check for the top script line that set's the default script language
235
' for the page.
236
left( tempString, 3 ) = Chr(60) &
"%@"
And
right(tempString, 2) =
"%"
& Chr(62)
237
"<table><tr bgcolor=yellow><td>"
238
Response.Write server.HtmlEncode(m_strReadLine)
239
"</td></tr></table>"
240
blnInScriptBlock =
241
' Check for an opening script tag
242
ElseIf
Left( tempString, 2) = Chr(60) &
243
' Check for a closing script tag on the same line
244
right( RTrim(tempString), 2 ) =
245
"<table><tr><td bgcolor=yellow><%</td>"
246
"<td>"
247
Response.Write CharacterParse(mid(m_strReadLine, 3, Len(m_strReadLine) - 4))
248
"</td>"
249
"<td bgcolor=yellow>%gt;</td></tr></table>"
250
251
252
"<table><tr bgcolor=yellow><td><%</td></tr></table>"
253
' We've got an opening script tag so set the flag to true so
254
' that we know to start parsing the lines for keyWords/comments
255
256
257
258
blnInScriptBlock
259
260
Response.Write vbCrLf
261
262
263
"<table><tr bgcolor=yellow><td>%></td></tr></table>"
264
265
266
Response.Write CharacterParse(m_strReadLine) & vbCrLf
267
268
269
270
blnOutputHtml
271
272
273
274
Response.Write server.HtmlEncode(m_strReadLine) & vbCrLf
275
276
277
278
279
Loop
280
281
' Grab the time at the completion of processing
282
m_EndTime = Time()
283
284
' Close the outside table
285
"</PRE></td></tr></table>"
286
287
' Close the file and destroy the file object
288
objFile.close
289
objFile =
290
291
292
' This function parses a line character by character
293
CharacterParse(inLine)
294
charBuffer, tempChar, i, outputString
295
insideString, workString, holdChar
296
297
insideString =
298
outputString =
299
300
For
i = 1 to Len(inLine)
301
tempChar = mid(inLine, i, 1)
302
tempChar
303
304
insideString
305
charBuffer = charBuffer &
306
charBuffer <>
307
left(charBuffer, 1) =
outputString = outputString &
308
309
' Check for a 'rem' style comment marker
310
LCase(Trim(charBuffer)) =
"rem"
311
outputString = outputString & CommentColor
312
"REM"
313
workString = mid( inLine, i, Len(inLine))
314
workString = replace(workString,
"<"
"&lt;"
315
"&gt;"
316
outputString = outputString & workString &
"</font>"
317
charBuffer =
318
319
320
321
outputString = outputString & FindReplace(Trim(charBuffer))
322
right(charBuffer, 1) =
323
324
325
326
327
328
"("
329
330
331
332
outputString = outputString & FindReplace(Trim(charBuffer)) &
333
334
Chr(60)
335
336
Chr(62)
337
338
Chr(34)
339
' catch quote chars and flip a boolean variable to denote that
340
' whether or not we're "inside" a quoted string
341
342
343
outputString = outputString & StringColor
344
"&quot;"
345
346
347
348
349
"'"
350
' Catch comments and output the rest of the line
351
' as a comment IF we're not inside a string.
352
353
354
355
356
357
outputString = outputString & workString
358
359
360
361
362
363
364
' We've dealt with special case characters so now
365
' we'll begin adding characters to our outputString
366
' or charBuffer depending on the state of the insideString
367
' boolean variable
368
369
outputString = outputString & tempChar
370
371
charBuffer = charBuffer & tempChar
372
373
374
Next
375
376
' Deal with the last part of the string in the character buffer
377
Left(charBuffer, 1) =
378
379
380
' Check for closing parentheses at the end of a string
381
")"
382
charBuffer = Left(charBuffer, Len(charBuffer) - 1)
383
CharacterParse = outputString & FindReplace(Trim(charBuffer)) &
384
385
386
387
CharacterParse = outputString & FindReplace(Trim(charBuffer))
388
389
390
' return true or false if a passed in number is between KeyMin and KeyMax
391
InRange(inLen)
392
inLen >= KeyMin
inLen <= KeyMax
393
InRange =
394
395
396
397
398
399
' Evaluate the passed in string and see if it's a keyWord in the
400
' dictionary. If it is we will add Html formatting to the string
401
' and return it to the caller. Otherwise just return the same
402
' string as was passed in.
403
FindReplace(inToken)
404
' Check the length to make sure it's within the range of KeyMin and KeyMax
405
InRange(Len(inToken))
406
objDict.Exists(inToken)
407
FindReplace = CodeColor & objDict.Item(inToken) &
"</Strong></Font>"
408
409
410
411
' KeyWord is either too short or too long or doesn't exist in the
412
' dictionary so we'll just return what was passed in to the function
413
FindReplace = inToken
414
415
416
417
%>
418
419
420
421
422
423
<!--#include file=
"token.ASP"
-->
424
' *************************************************************************
425
' This is all test/example code showing the calling syntax of the
426
' cBuffer class ... the interface to the cBuffer object is quite simple.
427
'
428
' Use it for reference ... delete it ... whatever.
429
430
431
REM
This is a rem type comment just for testing purposes!
432
433
' This variable will hold an instance of the cBuffer class
434
objBuffer
435
436
' Set up the error handling
437
On
Error
Resume
438
439
' create the instance of the cBuffer class
440
objBuffer =
New
441
442
' Set the PathToFile property of the cBuffer class
443
444
' Just for kicks we'll use the ASP file that we created
445
' in the last installment of this article serIEs for testing purposes
446
objBuffer.PathToFile =
"../081899/random.ASP"
'這是文件名啦。
447
448
' Here's an example of how to add a new keyword to the keyWord array
449
' You could add a list of your own function names, variables or whatever...cool!
450
' NOTE: You can add different Html formatting if you like, the <strong>
451
' attribute will applIEd to all keyWords ... this is likely to change
452
' in the near future.
453
454
'objBuffer.AddKeyWord "response.write", "<font color=Red>Response.Write</font>"
455
456
' Here are examples of changing the table background color, code color,
457
' comment color, string color and tab space propertIEs
458
459
'objBuffer.TableBGColor = "LightGrey" ' or
460
'objBuffer.TableBGColor = "#ffffdd" ' simple right?
461
'objBuffer.CodeColor = "Red"
462
'objBuffer.CommentColor = "Orange"
463
'objBuffer.StringColor = "Purple"
464
'objBuffer.TabSpaces = " "
465
466
' Call the ParseFile method of the cBuffer class, pass it true if you want the
467
' Html contained in the page output or false if you don't
468
objBuffer.ParseFile
'注意:顯示代碼的response.write已經在class中。這裡調用方法就可以了。
469
470
471
472
' Check for errors that may have been raised and write them out
473
Err.number <> 0
474
Response.Write Err.number &
":"
& Err.description &
& Err.source &
"<br>"
475
476
477
' Output the processing time and number of lines processed by the script
478
"<strong>Processing Time:</strong> "
& objBuffer.ProcessingTime &
" seconds<br>"
479
"<strong>Lines Processed:</strong> "
& objBuffer.LineCount &
480
481
' Destroy the instance of our cBuffer class
482
483
2).創建虛擬目錄 首先在c:\InetPub\WWWR
自從買了PPC以後每
學習目的:學會用表單元素向服務器傳送變量,然後顯示變量在客
為了提高網站的速度,公司服務器換了Windows2008
學習目的:學會ACCEES數據庫的使用,並建立一個將來要用
四.具體實現步驟 1).新建一個Html頁面 你可以使