common.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * This file is part of the LibreOffice project.
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. *
  8. * This file incorporates work covered by the following license notice:
  9. *
  10. * Licensed to the Apache Software Foundation (ASF) under one or more
  11. * contributor license agreements. See the NOTICE file distributed
  12. * with this work for additional information regarding copyright
  13. * ownership. The ASF licenses this file to you under the Apache
  14. * License, Version 2.0 (the "License"); you may not use this file
  15. * except in compliance with the License. You may obtain a copy of
  16. * the License at http://www.apache.org/licenses/LICENSE-2.0 .
  17. */
  18. <%
  19. public const cnRefreshTime = 5 ' refresh time in seconds
  20. ' filename for file with all pictures and file containing the name of the current picture
  21. public const csFilePicture= "picture.txt"
  22. public const csFileCurrent= "currpic.txt"
  23. ' constants for file-access
  24. const ForReading = 1
  25. const ForWriting = 2
  26. ' new-line delimiter
  27. Dim FILE_LINE_DELIMITER
  28. FILE_LINE_DELIMITER = vbCRLF
  29. '/**
  30. ' * Get data from file using a given separator.
  31. ' */
  32. function File_getDataVirtual( sFilename, sServerPath, sSeparator )
  33. call Err.Clear()
  34. Dim aFSObject, sServerFileName
  35. Set aFSObject = CreateObject("Scripting.FileSystemObject")
  36. sServerFileName = aFSObject.BuildPath( Server.MapPath( sServerPath ), sFileName )
  37. File_getDataVirtual = ""
  38. if Err.Number = 0 then
  39. File_getDataVirtual = File_read( sServerFileName )
  40. If Not IsNull(File_getDataVirtual) Then
  41. File_getDataVirtual = Replace( File_getDataVirtual, FILE_LINE_DELIMITER, sSeparator)
  42. File_getDataVirtual = Split( File_getDataVirtual, sSeparator)
  43. End If
  44. end if
  45. end function
  46. '/**
  47. ' * Get data from a file
  48. ' */
  49. function File_read( sFilename )
  50. call Err.Clear()
  51. Dim aFSObject, aStream
  52. Set aFSObject = CreateObject( "Scripting.FileSystemObject" )
  53. Set aStream = aFSObject.OpenTextFile( sFilename, ForReading )
  54. while not aStream.AtEndOfStream
  55. File_read = File_read + aStream.ReadLine + FILE_LINE_DELIMITER
  56. wend
  57. aStream.Close
  58. end function
  59. '/**
  60. ' * Get data from a file given by filename and virtual pathname
  61. ' */
  62. Function File_readVirtual(sFileName, sServerPath)
  63. call Err.Clear()
  64. Dim aFSObject, sServerFileName
  65. Set aFSObject = CreateObject("Scripting.FileSystemObject")
  66. sServerFileName = aFSObject.BuildPath( Server.MapPath( sServerPath ), sFileName )
  67. File_readVirtual = ""
  68. if Err.Number = 0 then
  69. File_readVirtual = File_read( sServerFileName )
  70. end if
  71. End Function
  72. '/**
  73. ' * Write data to a file
  74. ' */
  75. function File_write( sFileName, sText )
  76. call Err.Clear()
  77. Dim aFSObject, aFile
  78. Set aFSObject = CreateObject( "Scripting.FileSystemObject" )
  79. if Err.Number = 0 then
  80. Set aFile = aFSObject.CreateTextFile( sFileName, TRUE )
  81. if Err.Number = 0 then
  82. aFile.Write( sText )
  83. aFile.Close
  84. end if
  85. end if
  86. File_write = ( Err.Number = 0 )
  87. end function
  88. '/**
  89. ' * Write data to a file given by filename and virtual pathname
  90. ' */
  91. function File_writeVirtual( sFileName, sServerPath, sText )
  92. call Err.Clear()
  93. Dim aFSObject, aServerFile
  94. Set aFSObject = CreateObject( "Scripting.FileSystemObject" )
  95. aServerFile = aFSObject.BuildPath( Server.MapPath( sServerPath ), sFileName )
  96. If Err.Number = 0 Then
  97. File_writeVirtual = File_write( aServerFile, sText )
  98. else
  99. File_writeVirtual = false
  100. End If
  101. end function
  102. %>