xhtml apache מפת האתר דף ראשי

«
«
«
«
«
«
«
«
«
«
«
«
«
«

SSI פקודות  « SSI  « ראשי

מאמר 4: W3C - פקודות SSI


4.1 הקדמה

את הפקודות הללו יש לכתוב בקובץ shtml. אשר מסומן כ - FileResource הקשור ל- SSIFrame.
הפקודות מתחלקות לשניים: פקודות (1-10) ופקודות בקרה (11-17).

4.2 פקודות

1. Config Command
משמשת להגדרת משתני datefmt ו- sizefmt אשר מפקחים על הפלט של גודל הקובץ והתאריכים הקשורים אליו.
פרמטרים:
datefmt - פורמט התאריך.
Sizefmt - פורמט הגודל.

דוגמא:
<!--#config sizefmt="bytes" -->

2. CookieCommand
גישה ל - cookies דרך ה - SSI.
פרמטרים:
get - שם ה - cookie שיש לקחת.
alt - ערך חלופי.
if - שם ה - cookie (רק לבדוק אם היא קיימת).
then - ערך.
דוגמא:

<!--#cookie get="C1" alt="hello" -->, 
display the value of the cookie "C1" or "hello" if the cookie 
is not in the incomming request.
<!--#cookie if="C1" then="hello" alt="bye"-->, 
display "hello" if the cookie "C1" is in the request. If not display "bye"

3. CountCommand
פקודה זו מכניסה את מספר הגישות המתועדות למשאב זה, כפי שמתועד ע" CounterFilter.
פרמטרים: אין.
דוגמא:
<!--#hitcount -->

4. EchoCommand
פקודת ה - echo של SSI.
ההרחבות כוללות את הפרמטרים "reqstate" (הדפסת מצבי בקשה של Jigsaw) ו- "reqheader" (להדפסת כותרת הבקשה).
כמו כן פקודה זו יכולה לקבל את הדגל "here", אשר נוכחותו מצביעה על כך שיש לפרש את המשתנה ברמת הבקשה העמוקה ביותר (במקרה של בקשות פנימיות בשרשרת), במקום ברמת הבקשה החיצונית. היא מכניסה את ערכו של המשתנה לתוך המסמך.
פרמטרים:
var - משתנה מסוג SSI.
reqstate - מצב בקשת Jigsaw.
reqheader - כותרת עליונה של בקשה.
here - דגל.
דוגמא:
<!--#echo var="DOCUMENT_URI" -->
display the document uri
<!--#echo reqheader="referer"  -->
display the referer header of the request
<!--#echo reqstate="pathinfo"  -->
display the request state "pahtinfo"

5. ExecCommand
זוהי פקודת ה - exec של SSI. היא מכניסה את הפלט של ה - CGI script או פקודת
ה - shell לתוך המסמך.
יש לשים לב שבארכיטקטורה של Jigsaw, CGI scripts הם רק עוד מחלקת משאב ולכן אין צורך להבחין בין ביצוע CGI script לבין הוספת קובץ.
הפרמטרים:
cmd - הפקודה שיש להריץ.
דוגמא:
<!--#exec cmd="ls -lsa" -->
display the result of the ls command

6. FLastModCommand
זוהי פקודת ה- lastmod הסטנדרטית ב- SSI.
אין פרמטרים.
דוגמא:
<!--#flastmod-->

7. FSizeCommand
זוהי פקודת ה - fsize ב - SSI. היא מכניסה את גודל הקובץ שלא עבר חלוקה וניתוח לתוך המסמך, לפי הערך הנוכחי של המשתנה sizefmt.
אין פרמטרים.
דוגמא:
<!--#fsize -->

8. IncludeCommand
זוהי פקודת ה - include ב - SSI. (ניתן גם להוסיף CGI scripts, ע"י קביעת נתיב וירטואלי למשאב בעזרת CgiFrame).
פרמטרים:
file - הקובץ אשר יתווסף.
virtual - נתיב וירטואלי.
ifheader - כותרת עליונה של בקשה.
else - קובץ.
דוגמאות:

<!--#include file="included.html" -->
include the file "included.html" in the current file
<!--#include ifheader="Referer" file="included.html" else="included2.html" -->
if the request has a Referer header then include "included.html"
else include "included2.html"

9. jdbcCommand
פקודת jdbc של ה - SSI מאפשרת להציג מסד נתונים לפי שאילתת SQL באמצעות JDBC.
בשילוב עם כמה פקודות בקרה, היא מאפשרת להציג את תוכן מסד הנתונים בקלות.
הפרמטרים:
select - בקשת ה - SQL.
url - ה - URL של מסד הנתונים.
driver - מנהל ההתקן של JDBC.
user - שם המשתמש.
password - סיסמא.
name - שם התוצאה.
column - מספר העמודה.
next - דגל.
דוגמא :
<!--#jdbc select="SELECT * FROM services" name="result"
    driver="com.imaginary.sql.msql.MsqlDriver" 
    url="jdbc:msql://www43.inria.fr:4333/services" -->
this is the setup of the command.
<!--#jdbc name="result" next="true" -->
this command move the pointer to the next line of the result set.
<!--#jdbc name="result" column="1" -->
display the first column of the current line.
<!--#jdbc name="result" column="2" -->
display the second column of the current line.
<!--#jdbc name="result" column="3" -->
display the third column of the current line.

10. ServletCommand
פקודת ה - servlet ב - SSI. ניתן להריץ פקודה זו ע"י הגדרת נתיב url למחלקת servlet.
פרמטרים:
name - המזהה של הפקודה.
code - ה - URL של ה- servlet.
param - שם הפרמטר.
value - ערך הפרמטר.

דוגמא:
<!--#servlet name="Snoop" param="p1" value="v1" -->
<!--#servlet name="Snoop" param="p2" value="v2" -->
<!--#servlet name="Snoop" param="p3" value="v3" -->
<!--#servlet name="Snoop" code="/servlet/snoop" -->

 

4.3 פקודות בקרה

1. CounterCommand
פקודת המונה ב - SSI. פקודה זו משמשת לבצע פעולות כגון cpt=cpt+1.
פרמטרים:
name - המזהה של המונה.
init - הערך הראשוני.
incr - הערך אותו יש להוסיף למונה.
value - דגל.
דוגמא:
<!--#cpt name="cpt1" init="0" -->
Initialisation: cpt1 = 0
<!--#cpt name="cpt1" incr="1" -->
cpt1 = cpt1 + 1
<!--#cpt name="cpt1" value="true" -->
display the current value of cpt1

2. ElseCommand
פרמטרים:
name - המזהה של פקודת if.
דוגמא:
<!--#else name="if2" -->

3. EndifCommand
פרמטרים:
name - המזהה של פקודת if.
דוגמא:
<!--#endif name="if2" -->

4. EndloopCommand
פרמטרים:
name - מזהה פקודת ה - loop.
דוגמא:
<!--#endloop name="loop2" -->

5. ExitloopCommand
פרמטרים:
name - מזהה פקודת ה - loop.
command - שם פקודה (cpt, jdbc).
var - מזהה פקודה.
equals - ערך מחרוזת.
דוגמא:
<!--#exitloop name="loop2" command="cpt" var="cpt1" equals="4" -->

6. IfCommand
פרמטרים:
name - מזהה הפקודה.
command - שם פקודה (jdbc, cpt).
var - מזהה פקודה.
equals - ערך מחרוזת.
דוגמא:
<!--#if name="if2" command="cpt" var="cpt1" equals="2" -->

7. LoopCommand
פרמטרים:
name - מזהה הפקודה.
דוגמא:
<!--#loop name="loop2" -->

 

4.4 דוגמא

הדוגמא הבאה תציג את ארבע העמודות הראשונות בשלושת השורות הראשונות במסד הנתונים של המשתמשים:

      <!--#jdbc name="result2" select="SELECT * FROM users"
          user="bmahe" password=""
          url="jdbc:msql://www43.inria.fr:4333/users"
          driver="com.imaginary.sql.msql.MsqlDriver"  -->
      <table border=2>
        <!--#cpt name="cpt1" init="0" -->
          <tr><td><b>Name </td><td><b>Login</td>
              <td><b>Email</td><td><b>Age  </td></tr>
          <!--#loop name="loop2" -->
          <!--#jdbc name="result2" next="true" -->
          <tr>
            <td>
              <!--#jdbc name="result2" column="1" -->
            </td><td>
              <!--#jdbc name="result2" column="2" -->
            </td><td>
              <!--#jdbc name="result2" column="3" -->
            </td><td>
              <!--#jdbc name="result2" column="4" -->
            </td>
          </tr>
          <!--#cpt name="cpt1" incr="1" -->
          <!--#exitloop name="loop2" command="cpt" var="cpt1" equals="3" -->
          <!--#endloop name="loop2" -->
      </table>
      counter value : <!--#cpt name="cpt1" value="true" -->

התוצאות יכולות להיות:
NameLoginEmail Age
25 Smith ssmith ssmith@foobar.org
25lafrim ylafrim lafrim@foobar.org
27 Teole pteoleteole@foobar.org
ערך המונה: 3