project BLF > class TDocumentLink > method CopyResource
Description
Create a resource which contents is a copy of an existing resource. This resource can be a collection.
Parameters
icCreatePath | input | character | |
icCopyPath | input | character | |
ocResponse | output | character | |
Internal usage
BLF
program code (program1/tdocumentlink.p)
if num-entries (icCreatePath,"/") > 1
then do:
vcCreateCollection = substring (icCreatePath,1,r-index(icCreatePath,"/") - 1,"CHARACTER").
<M-72 run CollectionExists
(input vcWebdavRoot + vcCreateCollection (icPath),
output vlExists (olExists)) in TDocumentLink>
if vcWebdavResponse <> ""
then return.
if vlExists = no
then do:
vcPath = vcWebdavRoot.
do viC1 = 1 to num-entries(vcCreateCollection,"/") - 1:
vcPath = vcPath + entry(viC1,vcCreateCollection,"/") + "/".
<M-33 run CollectionExists
(input vcPath (icPath),
output vlExists (olExists)) in TDocumentLink>
if vcWebdavResponse <> ""
then return.
if vlExists = no
then do:
<M-94 run CreateCollection (input vcPath (icPath)) in TDocumentLink>
if vcWebdavResponse <> ""
then return.
end.
end.
<M-84 run CreateCollection (input vcWebdavRoot + vcCreateCollection (icPath)) in TDocumentLink>
if vcWebdavResponse <> ""
then return.
end.
end.
<M-75 run Connect () in TDocumentLink>
if vcWebdavResponse <> ""
then return.
vcommand = "COPY " + vcWebdavRoot + icCopyPath + " HTTP/1.0"
+ "~nDestination: " + vcWebdavRoot + icCreatePath + "~n~n".
set-size (vmSend) = length (vcommand,"RAW") + 1.
put-string (vmSend,1) = vcommand.
vhWebdavSocket:write (vmSend,1,get-size(vmSend)).
wait-for read-response of vhWebdavSocket pause 60.
if index (vcWebdavResponse," 201 ") > 0 /* CREATED */
or index (vcWebdavResponse," 204 ") > 0 /* REPLACED */
then vcWebdavResponse = "".
finally:
set-size (vmSend) = 0.
if vhWebdavSocket <> ?
then do:
vhWebdavSocket:disconnect ().
delete object vhWebdavSocket.
vhWebdavSocket = ?.
end.
ocResponse = vcWebdavResponse.
end finally.