''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright (c) Microsoft Corporation. All rights reserved.
' THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE
' RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE
' USER. USE AND REDISTRIBUTION OF THIS CODE, WITH OR WITHOUT MODIFICATION, IS
' HEREBY PERMITTED.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Depending on the action specified by the user in the command line, this script
' lists the link-translation dictionaries of all Web publishing rules, lists all
' the entries defining internal-external pairs of strings in the dictionary for
' the specified Web publishing rule, removes the specified entry from the
' dictionary for the specified rule, removes the entire dictionary for the
' specified rule, adds an entry defining an internal-external pair to the
' dictionary for the specified rule.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'
' Define a constant for the GUID of the vendor parameters set that defines
' a link-translation dictionary.
'
Const LinkTranslatDicGUID = "{3563FFF5-DF93-40eb-ABC3-D24B5F14D8AA}"
Const fpcPolicyRuleWebPublishing = 2
Const Error_FileNotFound = &H80070002
Dim root ' The FPCLib.FPC root object
Main Wscript.Arguments
Sub Main(args)
Dim ruleName, action
If(0 = args.Count) Then
Usage()
End If
Set root = WScript.CreateObject("FPC.Root")
action = LCase(args(0))
Select Case action
Case "listall":
ListAllDictionaries
Case "list":
If(2 > args.Count) Then
Usage()
End If
ruleName = args(1)
ListDictionary GetWebPublishingRule(ruleName)
Case "clear":
If(2 > args.Count) Then
Usage()
End If
ruleName = args(1)
ClearDictionary GetWebPublishingRule(ruleName)
Case "add":
If(4 > args.count) Then
Usage()
End If
ruleName = args(1)
AddItemToDictionary GetWebPublishingRule(ruleName), args(2), args(3)
Case "removeentry":
If(3 > args.Count) Then
Usage()
End If
ruleName = args(1)
RemoveEntry GetWebPublishingRule(ruleName), args(2)
case Else
Usage()
End Select
End Sub
'
' List the dictionaries of all Web publishing rules.
'
Sub ListAllDictionaries()
Dim rules ' An FPCPolicyRules collection
Dim rule ' An FPCPolicyRule object
Set rules = root.GetContainingArray.ArrayPolicy.PolicyRules
For Each rule in rules
If rule.Type = fpcPolicyRuleWebPublishing Then
ListDictionary rule
End If
Next
End Sub
'
' List the content of the link-translation dictionary for the
' specified Web publishing rule.
'
Sub ListDictionary(wpRule)
Dim vpSets ' An FPCVendorParametersSets collection
Dim vpSet ' An FPCVendorParametersSet object
Dim errorCode, errorDescript, index, name
Set vpSets = wpRule.VendorParametersSets
On Error Resume Next
Set vpSet = vpSets(LinkTranslatDicGUID)
errorCode = err.Number
errorDescript = err.Description
On Error GoTo 0
Select Case errorCode
Case Error_FileNotFound:
WScript.Echo "The dictionary for the " & wpRule.Name _
& " rule is empty or does not exist."
Case 0:
' A dictionary exists for this rule.
WScript.Echo "Dictionary for the " & wpRule.Name & " rule:"
index = 1
If(IsEmpty(vpSet.AllNames)) Then
WScript.Echo " The dictionary is empty."
Else
For Each name In vpSet.AllNames
WScript.Echo " " & index & ". " & name & " - " & _
vpSet.Value(name)
index = index + 1
Next
End If
Case Else:
err.Raise errorCode,, errorDescript
End Select
End Sub
'
' Remove the vendor parameters set defining the link-translation dictionary
' of the specified Web publishing rule.
'
Sub ClearDictionary(wpRule)
Dim vpSets ' An FPCVendorParametersSets collection
Set vpSets = wpRule.VendorParametersSets
RemoveFromVPSs vpSets, LinkTranslatDicGUID
vpSets.Save
End Sub
'
' Remove a single entry from the dictionary (The entry name is the internal
' string).
'
Sub RemoveEntry(wpRule, name)
Dim vpSets ' An FPCVendorParametersSets collection
Dim vpSet ' An FPCVendorParametersSet object
Dim errorCode, errorDescript
' Get the vendor parameters set defining the link-translation dictionary.
Set vpSets = wpRule.VendorParametersSets
On Error Resume Next
Set vpSet = vpSets(LinkTranslatDicGUID)
errorCode = err.Number
errorDescript = err.Description
On Error GoTo 0
Select Case errorCode
Case Error_FileNotFound:
WScript.Echo "No dictionary exists for this rule."
Exit Sub
Case 0:
' OK
Case Else
err.Raise errorCode,, errorDescript
End Select
' Remove the specified entry.
' Note: The key is case-sensitive.
On Error Resume Next
vpSet.RemoveValue name
errorCode = err.Number
errorDescript = err.Description
On Error GoTo 0
Select Case errorCode
Case Error_FileNotFound:
WScript.Echo "An entry for " & name _
& " was not found in the dictionary."
Case 0:
vpSet.Save ' OK, save the changes.
Case Else
err.Raise errorCode,, errorDescript
End Select
End Sub
'
' Add an entry (internal string - external string) to the link-translation
' dictionary of the specified rule.
'
Sub AddItemToDictionary(wpRule, internalString, externalString)
Dim vpSets ' An FPCVendorParametersSets collection
Dim vpSet ' An FPCVendorParametersSet object
Dim errorCode, errorDescript
Set vpSets = wpRule.VendorParametersSets
On Error Resume Next
Set vpSet = vpSets(LinkTranslatDicGUID)
errorCode = err.Number
errorDescript = err.Description
On Error GoTo 0
Select Case errorCode
Case Error_FileNotFound:
' Create the dictionary if it does not exist.
Set vpSet = vpSets.Add(LinkTranslatDicGUID, False)
Case 0:
' OK, set was found.
Case Else
err.Raise errorCode,, errorDescript
End Select
' Add the internal-external entry.
vpSet.Value(internalString) = externalString
vpSets.Save
End Sub
'
' Retrieve the specified Web publishing rule.
'
Function GetWebPublishingRule(ruleName)
Dim rules ' An FPCPolicyRules collection
Dim rule ' An FPCPolicyRule object
Dim errorCode, errorDescript
Set rules = root.GetContainingArray.ArrayPolicy.PolicyRules
On Error Resume Next
Set rule = rules(ruleName)
Select Case err.Number
Case Error_FileNotFound:
WScript.Echo "The " & ruleName _
& " Web publishing rule was not found."
Wscript.Quit
Case 0:
' OK
Case Else
err.Raise err.Number,, err.Description
End Select
On Error GoTo 0
If rule.Type <> fpcPolicyRuleWebPublishing Then
WScript.Echo "The " & ruleName & " rule is not a Web publishing rule."
Wscript.Quit
End If
Set GetWebPublishingRule = rule
End Function
'
' Remove the link-translation dictionary from the vendor parameters sets
' collection of the specified rule.
'
Sub RemoveFromVPSs(vpSets, setName)
Dim errorCode, errorDescript
On Error Resume Next
vpSets.Remove setName
errorCode = err.Number
errorDescript = err.Description
On Error GoTo 0
Select Case errorCode
Case 0:
vpSets.Save ' OK, save the changes.
Case Error_FileNotFound:
' Ignore the error if the object was not found
' or was already removed.
Case Else
err.raise errorCode,,errorDescript
End Select
End Sub
Sub Usage()
Dim sUsage
sUsage = "Usage:" & vbCrLf _
& " LinkTranslation_EditDictionary.vbs Action [RuleName] [IntString]" _
& " [ExtString]" & vbCrLf _
& vbCrLf _
& " Action:" & vbCrLf _
& " ListAll - List dictionaries for all Web publishing" _
& " rules." & vbCrLf _
& " List - List dictionary for the specified rule." _
& vbCrLf _
& " Clear - Clear all entries from the search-replace" _
& " dictionary for the specified rule." & vbCrLf _
& " Add - Add an entry (internal string - external" _
& " string) to the dictionary of the specified rule." _
& vbCrLf _
& " RemoveEntry - Remove the entry for the specified internal" _
& " string from the dictionary of the specified rule." _
& vbCrLf _
& vbCrLf _
& " RuleName: Specify the Web publishing rule. " & vbCrLf
WScript.Echo sUsage
WScript.Quit
End Sub