home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2002 October / VPR0210A.ISO / OPENOFFICE / f_0110 / Autotext.xba next >
Extensible Markup Language  |  2001-12-12  |  6KB  |  163 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3.  <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Autotext" script:language="StarBasic">Option Explicit
  4.  
  5. Public UserfieldDataType(14) as String
  6. Public oDocAuto as Object
  7. Public BulletList(7) as Integer
  8.  
  9. Sub Main()
  10.     Dim oCursor as Object
  11.     Dim oStyles as Object
  12.     Dim oSearchDesc as Object
  13.     Dim oFoundall as Object
  14.     Dim oFound as Object
  15.     Dim i as Integer
  16.     Dim sFoundString as String
  17.     Dim sFoundContent as String
  18.     Dim FieldStringThere as String
  19.     Dim ULStringThere as String
  20.     Dim PHStringThere as String
  21.  
  22.     ' Initialization...
  23.     BasicLibraries.LoadLibrary("Tools")
  24.  
  25.     UserfieldDatatype(0) = "COMPANY"
  26.     UserfieldDatatype(1) = "FIRSTNAME"
  27.     UserfieldDatatype(2) = "NAME"
  28.     UserfieldDatatype(3) = "SHORTCUT"
  29.     UserfieldDatatype(4) = "STREET"
  30.     UserfieldDatatype(5) = "COUNTRY"
  31.     UserfieldDatatype(6) = "ZIP"
  32.     UserfieldDatatype(7) = "CITY"
  33.     UserfieldDatatype(8) = "TITLE"
  34.     UserfieldDatatype(9) = "POSITION"
  35.     UserfieldDatatype(10) = "PHONE_PRIVATE"
  36.     UserfieldDatatype(11) = "PHONE_COMPANY"
  37.     UserfieldDatatype(12) = "FAX"
  38.     UserfieldDatatype(13) = "EMAIL"
  39.     UserfieldDatatype(14) = "STATE"
  40.     BulletList(0) = 149
  41.     BulletList(1) = 34
  42.     BulletList(2) = 65
  43.     BulletList(3) = 61
  44.     BulletList(4) = 49
  45.     BulletList(5) = 47
  46.     BulletList(6) = 79
  47.     BulletList(7) = 58
  48.  
  49.     oDocAuto = ThisComponent
  50.     oStyles = oDocAuto.Stylefamilies.GetByName("NumberingStyles")
  51.  
  52.     ' Prepare the Search-Descriptor
  53.     oSearchDesc = oDocAuto.createsearchDescriptor()
  54.     oSearchDesc.SearchRegularExpression = True
  55.     oSearchDesc.SearchWords = True
  56.     oSearchDesc.SearchString  = "<[^>]+>"
  57.     oFoundall = oDocAuto.FindAll(oSearchDesc)
  58.  
  59.     'Loop over the foundings
  60.     For i = 0 To oFoundAll.Count - 1
  61.         oFound = oFoundAll.GetByIndex(i)
  62.         sFoundString = oFound.String
  63.         'Extract the string inside the brackets
  64.         sFoundContent = FindPartString(sFoundString,"<",">",1)
  65.         sFoundContent = LTrim(sFoundContent)
  66.  
  67.         ' Define the Cursor and place it on the founding
  68.         oCursor = oFound.Text.CreateTextCursorbyRange(oFound)
  69.  
  70.         ' Find out, which object is to be created...
  71.         FieldStringThere = Instr(1,sFoundContent,"Field")
  72.         ULStringThere = Instr(1,sFoundContent,"UL")
  73.         PHStringThere = Instr(1,sFoundContent,"Placeholder")
  74.         If FieldStringThere = 1 Then
  75.             CreateUserDatafield(oCursor, sFoundContent)
  76.         ElseIf ULStringThere = 1 Then
  77.             CreateBullet(oCursor, oStyles)
  78.         ElseIf PHStringThere = 1 Then
  79.             CreatePlaceholder(oCursor, sFoundContent)
  80.         End If
  81.     Next i
  82. End Sub
  83.  
  84.  
  85. ' creates a User - datafield out of a string with the following structure
  86. ' "<field:Company>"
  87. Sub    CreateUserDatafield(oCursor, sFoundContent as String)
  88.     Dim MaxIndex as Integer
  89.     Dim sTextFieldNotDefined as String
  90.     Dim sFoundList(3)
  91.     Dim oUserfield as Object
  92.     Dim UserInfo as String
  93.     Dim UserIndex as Integer
  94.  
  95.     oUserfield = oDocAuto.CreateInstance("com.sun.star.text.TextField.ExtendedUser")
  96.     sFoundList() = ArrayoutofString(sFoundContent,":",MaxIndex)
  97.     UserInfo = UCase(LTrim(sFoundList(1)))
  98.     UserIndex = IndexinArray(UserInfo, UserfieldDatatype())
  99.     If UserIndex <> -1 Then
  100.         oUserField.UserDatatype = UserIndex
  101.         oCursor.Text.InsertTextContent(oCursor,oUserField,True)
  102.         oUserField.IsFixed = True
  103.     Else
  104.         If InitResources("'Template'", "tpl") Then
  105.             sTextFieldNotDefined = GetResText(1400)
  106.             Msgbox(UserInfo &": " & sTextFieldNotDefined,16, GetProductName())
  107.         End If
  108.     End If
  109. End Sub
  110.  
  111.  
  112. ' Creates a Bullet by setting a soft Formatation on the first unsorted List-Templates with a defined
  113. ' Bullet Id
  114. Sub    CreateBullet(oCursor, oStyles as Object)
  115.     Dim n, m, s as Integer
  116.     Dim StyleSet as Boolean
  117.     Dim ostyle as Object
  118.     Dim StyleName as String
  119.     Dim alevel()
  120.     StyleSet = False
  121.     For s = 0 To Ubound(BulletList())
  122.         For n = 0 To oStyles.Count - 1
  123.             ostyle = oStyles.getbyindex(n)
  124.             StyleName = oStyle.Name
  125.             alevel() = ostyle.NumberingRules.getbyindex(0)
  126.             ' The properties of the style are stored in a Name-Value-Array()
  127.             For m = 0 to Ubound(alevel())
  128.                 ' Set the first Numbering template without a bulletID
  129.                 If (aLevel(m).Name = "BulletId") Then
  130.                     If alevel(m).Value = BulletList(s) Then
  131.                         oCursor.NumberingStyle = StyleName
  132.                         oCursor.SetString("")
  133.                         exit Sub
  134.                     End if
  135.                 End If
  136.             Next m
  137.         Next n
  138.     Next s
  139.     If Not StyleSet Then
  140.         ' The Template with the demanded BulletID is not available, so take the first style in the sequence
  141.         ' that has a defined Bullet ID
  142.         oCursor.NumberingStyleName = oStyles.GetByIndex(5).Name
  143.         oCursor.SetString("")
  144.     End If
  145. End Sub
  146.  
  147.  
  148. ' Creates a placeholder out of a string with the following structure:
  149. '<placeholder:Showtext:Helptext>
  150. Sub    CreatePlaceholder(oCursor as Object, sFoundContent as String)
  151.     Dim oPlaceholder as Object
  152.     Dim MaxIndex as Integer
  153.     Dim sFoundList(3)
  154.     oPlaceholder = oDocAuto.CreateInstance("com.sun.star.text.TextField.JumpEdit")
  155.     sFoundList() = ArrayoutofString(sFoundContent, ":" & chr(34),MaxIndex)
  156.     ' Delete The Double-quotes
  157.     oPlaceholder.Hint = DeleteStr(sFoundList(2),chr(34))
  158.     oPlaceholder.placeholder =     DeleteStr(sFoundList(1),chr(34))
  159.     oCursor.Text.InsertTextContent(oCursor,oPlaceholder,True)
  160. End Sub
  161.  
  162.  
  163. </script:module>