Activity - fileWritingActivity
Activity Type: File
Description
The use of this activity requires the jar: "jakarta-oro-2.0.8.jar" to be loaded on the server,
for the handling of regular expressions.
Edit the contents of a file:
- Insert content.
 
- Append content.
 
- Delete content.
 
- Replace content.
 
Examples
<!-- Insert "!!" at the first character position of the file -->
<fileWritingActivity name="insert">
  <file>path/file.ext</file>
  <locate>
    <offset>1</offset>
  </locate>
  <insert text="!!"/>
  <output name="out"/>
</fileWritingActivity>
<!-- Insert "!!" at the beginning of the file -->
<fileWritingActivity name="insert">
  <file>path/file.ext</file>
  <locate>
    <offset>start</offset>
    <perLine>true</perLine>
  </locate>
  <insert text="!!" />
  <output name="out"/>
</fileWritingActivity>
<!-- Append "!!" to the end of the file -->
<fileWritingActivity name="append">
  <file>path/file.ext</file>
  <append text="!!"/>
  <output name="out"/>
</fileWritingActivity>
<!-- Append "!!" to the end of each line -->
<fileWritingActivity name="append">
  <file>path/file.ext</file>
  <locate>
    <perLine>true</perLine>
  </locate>
  <append text="!!"/>
  <output name="out"/>
</fileWritingActivity>
<!-- Delete characters 1 to 4 inclusive from the file -->
<fileWritingActivity name="delete">
  <file>path/file.ext</file>
  <locate>
    <offset>1</offset>
    <length>3</length>
  </locate>
  <delete/>
  <output name="out"/>
</fileWritingActivity>
<!-- Delete the first three occurrences of the string "zonk" -->
<fileWritingActivity name="delete">
  <file>path/file.ext</file>
  <locate>
    <regexp>zonk</regexp>
    <match>1-3</match>
  </locate>
  <delete/>
  <output name="out"/>
</fileWritingActivity>
<!-- Replace the first, fourth, ninth, sixteenth occurrences -->
<!-- of the string "zonk"                                    -->
<fileWritingActivity name="matchSequence">
  <file>path/file.ext</file>
  <locate>
    <regexp>zonk</regexp>
    <match>1:4:9:...</match>
    <perLine>false</perLine>
  </locate>
  <replace text="!!" />
  <output name="out"/>
</fileWritingActivity>
<!-- Replace the third to final characters of the file with -->
<!-- input from the "data" activity output stream.          -->
<fileWritingActivity name="replaceOffsetPerLine">
  <file>path/file.ext</file>
  <locate>
    <offset>3</offset>
    <length>toEnd</length>
    <perLine>false</perLine>
  </locate>
  <replace from="data"/>
  <output name="out"/>
</fileWritingActivity>
Specification
Element fileWritingActivity:
- 
Attribute name - unique name for the
activity within the scope of a request. 
 
- 
Element file (required) - 
contains the path to the file to access. This path should be
relative to the top-level directory exposed by the associated 
OGSA-DAI service and must not attempt to traverse up the directory 
hierarchy higher than this directory. 
 
- 
Element locate (zero or one) - contains an
expression selecting part of the file, either a regular expression or
a character span: 
- A regular expression:
- 
Element regexp (required) - contains a
regular expression.
 
- 
Element match (zero or one) - which instances 
of text matching the regular expression are to be used. A
comma-separated list of values. Each value can be any of:
- 
Positive integer e.g. 3
 
- 
Range of positive integers e.g. 2-7
 
- 
Infinite range of positive integers e.g. 3-
 
- 
Strictly increasing infinite sequences of positive integers e.g.
1:4:9:...
 
 
- 
Element perLine (zero or one) - specify that
the action to be taken on the selection is to be performed per-line
(true) or per-file (false). 
 
 
- A character span:
- 
Element offset (zero or one) - the start of
the selected text area. Contains one of:
- 
An integer representing a character position within the file.
 
- 
end for the
end of the file. Note that if the value of 
perLine is true 
then these actually mean the end of the line.
 
- 
start for the
start of the file.
 
 
- 
Element length (zero or one) - number of
characters from the offset to be
selected. Contains one of:
- 
An integer specifying the number of characters from the offset to be selected.
 
- toEnd indicating that all characters from
the offset to the end of the file are to be
selected. 
 
 
- 
Element perLine (zero or one) - specify that
the action to be taken on the selection is to be performed per-line
(true) or per-file (false). 
 
 
 
- 
One of the following four elements (required):
- 
Element insert - insert text after the
selected text.
- 
One of the following two attributes:
- 
Attribute text - text to insert. 
 
- 
Attribute from - name of an input stream
providing the text to insert.
 
 
- 
Attribute optimiseTime - optimise time 
(true) or memory (false) use.
 
 
- 
Element append - append text to the end of 
the file or line.
- 
For this option no locate element need be
provided. 
 
- 
One of the following two attributes:
- 
Attribute text - text to append. 
 
- 
Attribute from - name of an input stream
providing the text to append.
 
 
- 
Attribute optimiseTime - optimise time 
(true) or memory (false) use. 
 
 
- 
Element delete - delete the selected
text. 
- 
Attribute optimiseTime - optimise time 
(true) or memory (false) use.
 
 
- 
Element replace - replace the selected
text. 
- 
One of the following two attributes:
- 
Attribute text - text to replace the selected 
text. 
 
- 
Attribute from - name of an input stream
providing the text to replace the selected text.
 
 
- 
Attribute optimiseTime - optimise time 
(true) or memory (false) use.
 
 
 
- 
Element output (required) - a dummy
output which receives the value 1
after the action is complete.
 
  Input and Output Types
   
     - Input: replace from:
     
      - 
        java.lang.String
      
 
      - 
        byte[] - these are converted to a
        java.lang.String
      
 
      - 
        org.w3c.dom.Node - these are parsed into a
        java.lang.String
      
 
      - 
        Any other objects are converted to a
        java.lang.String
        via java.lang.Object.toString()
      
 
    
     
     - Output: output - java.lang.String
  - always the string 1.
   
Warning to Service Deployers
This activity can be used by clients to potentially access 
any directory on your server below 
that exposed by the associated OGSA-DAI service. 
Data Resource Accessor
This activity requires a data resource accessor that implements the following
interface:
uk.org.ogsadai.dataresource.FileAccessProvider
XML Schema
OGSA-DAI/schema/ogsadai/xsd/activities/file_writing.xsd
Class
uk.org.ogsadai.activity.files.FileWritingActivity
Client Toolkit Classes