跳轉至內容

XQuery/釋出概覽

來自華夏公益教科書

您有一個工作流程,允許內部團隊在將網路內容傳輸到公共網站之前對其進行審查。當文件被標記為“已批准釋出”時,它們必須以受控的方式傳輸到公共網路伺服器。

有很多方法可以將 XML 文件從一臺伺服器傳輸到另一臺伺服器。本文件將描述一組基本方法,這些方法可能會根據您的本地配置而有所不同。在本檔案中,將使用以下圖表。

Configuration of Internal Content Management Systems and Publishing Server in DMZ
內部內容管理系統和 DMZ 中的釋出伺服器配置

簡單釋出工作流程

[編輯 | 編輯原始碼]

許多組織對誰有權將內容釋出到公共網站都有嚴格的政策指南。在將內容傳輸到公共網站之前,打算釋出的文件通常會經過一系列階段

  • 草稿 - 處於質量控制過程早期階段的文件
  • 稽核中 - 由編輯團隊稽核質量的文件,例如內容質量、拼寫和排版錯誤
  • 已批准釋出 - 已批准在公共網站上釋出的文件。

所有已標記為已批准釋出的文件都可以從內部內容站點傳輸到公共網路伺服器。通常,只有具有特定角色的指定使用者才能將文件標記為已批准釋出

簡單釋出指令碼

[編輯 | 編輯原始碼]

建立釋出指令碼有幾種選擇。我們將從一個非常簡單的指令碼開始,然後新增功能。

使用 HTTP PUT 和 DELETE 進行釋出

[編輯 | 編輯原始碼]

釋出文件最簡單的方法是使用 eXist(或 EXQuery)[1] 庫。此庫具有 PUT 和 DELETE 操作,可用於以程式設計方式在您的釋出伺服器上新增和刪除網路內容。

以下是如何使用 httpclient:put() 函式的示例

  httpclient:put($url as xs:anyURI,
                 $content as node(),
                 $persist as xs:boolean,
                 $request-headers as element()?) item()

優點:非常易於使用 缺點:沒有誰在何時釋出了什麼內容的中央審計跟蹤

使用 POST 服務進行釋出

[編輯 | 編輯原始碼]

另一種方法是在公共網站上建立一箇中央釋出服務,以協調所有釋出事件。這可以透過使用 HTTP POST 客戶端函式來完成,然後編寫一個單一的釋出伺服器來捕獲和記錄所有釋出事件。

  httpclient:post($url as xs:anyURI,
                 $content as node(),
                 $persist as xs:boolean,
                 $request-headers as element()?) item()

您必須記住為 URL 使用強制轉換為 xs:anyURI。例如

  let $post-status :=
     httpclient:post(xs:anyURI('http://example.com/db/get-doc.xq'), $doc-to-publish, true(), ())

使用回撥進行釋出

[編輯 | 編輯原始碼]

通常,在公共網路伺服器上指示一個網路服務,您現在有一個新的資源已準備好釋出,但不要在請求中推送整個檔案到公共網站。只有資源的 URL 被髮送到公共網路伺服器,其中包含四個引數

  • 釋出文件的使用者
  • 任何身份驗證憑據
  • 型別(釋出或刪除)
  • 關於釋出或刪除原因的評論
  • 要從中央內容管理系統由公共網路伺服器拉取的文件識別符號,或要刪除的文件的 ID

然後,公共網路伺服器呼叫一個函式,從系統內部的內容管理系統載入該資源。這可以透過標準的 URL 引數來完成。請注意,在這種情況下,密碼將位於網路日誌檔案中。

使用 publish-with-callback.xq 獲取 URL 引數的示例

(: The user that will execute the login :)
let $user := request:get-parameter('user', '')

(: The pass that will execute the login :)
let $pass := request:get-parameter('pass', '')

(: The full URL of the document we are going to bring over :)
let $url := request:get-parameter('url', '')

(: the /db location we are going to put the new document into :)
let $db-loc := request:get-parameter('db-loc', '')

(: This is the document fetch from the internal CMS server :)
let $get-doc := doc($url)

請注意,這種樣式更安全,因為只有存在於內部內容管理系統中的文件才適合釋出。

釋出審計日誌

[編輯 | 編輯原始碼]

如果您使用中央網路服務進行釋出,您現在可以在一個集中式的日誌檔案中記錄所有釋出事件。然後,可以使用此檔案來報告和稽核誰在何時更改了公共網站上的哪些內容。

以下示例顯示如何將所有釋出事件新增到日誌檔案中,該檔案顯示哪些使用者釋出了哪些檔案以及它們何時釋出或刪除。在以下示例中,型別程式碼應設定為釋出或刪除。

let $audit-log :=
<publish-event>
   <type-code>publish|delete</type-code>
   <user>{$user}</user>
   <dateTime>{current-dateTime()}</dateTime>
   <db-loc>{$db-loc}</db-loc>
</publish-event>

(: check that the log file exists and if not then create it :)
let $check-log-exists :=
  if (doc-available($log-file))
     then ()
     else
        xmldb:store(
           functx:substring-before-last($log-file, '/'), 
           functx:substring-after-last($log-file, '/'), 
           <publish-events/> )

(: this inserts the audit record at the end of the log file :)
let $update := update insert $audit-log into doc($log-file)/publish-events

使用證書

[編輯 | 編輯原始碼]

有時無法在內部 CMS 系統和釋出網站之間建立安全連線。另一種方法是為每個有權向釋出伺服器釋出文件的系統提供證書。

華夏公益教科書