Files manipulation tags ver. 2.6

    Custom JSP tags. This library supports manipulations with server side files.

copyFile

copies file on your server. Parameters are:

1) source. Describes a path to source file
2) target. Describes a destination directory or file

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<!-- copy file c:\a.txt to c:\tmp -->
<file:copyFile source="c:\\a.txt" target="c:\\tmp"/>

xcopy

copies directory (and sub-directories) on your server. Parameters are:

1) source. Describes a path to source directory
2) target. Describes a destination directory

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<!-- copy directory c:\tmp\user to c:\users\guest -->
<file:xcopy source="c:\\tmp\\user" target="c:\\users\\guest"/>

moveFile

moves file on your server. Parameters are:

1) source. Describes a path to source file
2) target. Describes a destination directory or file

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<!-- move file c:\a.txt to c:\tmp -->
<file:moveFile source="c:\\a.txt" target="c:\\tmp"/>

deleteFile

deletes file on your server. Parameter is:

1) source. Describes a path to source file

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<!-- delete file c:\a.txt -->
<file:deleteFile source="c:\\a.txt"/>

writeFile

Body tag writes data to the file on your server. Data may be defined as a parameter for this tag and/or as a body of this tag. Parameters are:

1) source Describes a path to source file
2) append Optional attribute. Possible values are true or false. Describes a writing mode for data. If this value is true data will be appended to the end of the file. Default value is false.
3) serialized. Possible values are true or false. Describes data writing mode. If this value is true all updates are synchronized. Default value is false. Set this value to true if more than one client may write to your file
4) contents Describes your data. Default value is null.
4) encoding Optional attribute. Describes an encoding for your data.

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>

<!-- write string to c:\a.txt -->
<file:writeFile source="c:\\a.txt" contents="test string"/>

<!-- append string to c:\a.txt -->
<file:writeFile source="c:\\a.txt" append="true" contents="test string"/>

<!-- write xml code into c:\a.txt -->
<file:writeFile source="c:\\a.txt">
  <user>Guest</user>
  <type>client</type>
</file:writeFile>

createDirectory

creates a directory on your server. Parameter is:

1) source. Describes a path to new directory

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<!-- create directory c:\tmp\a -->
<file:createDirectory source="c:\\tmp\\a"/>

deleteDirectory

deletes a directory on your server. Parameter is:

1) source. Describes a path to your directory

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<!-- delete directory /tmp/a -->
<file:deleteDirectory source="<%=getSevletConfig().getServletContext().getRealPath(\"/tmp/a\")%>" />

rename

renames file (directory). Parameters are:

1) oldName Describes an old name
2) newName Describes a new name

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<!-- rename c:\tmp\a to c:\tmp\b -->
<file:rename oldName="c:\\tmp\\a" newName="c:\\tmp\\b" />

isFile

Body tag. Tests file and executes own body if file exits. Parameters are:

1) source. Describes a path to your file
2) id. Describes a name for new page scope variable that will be created by this tag. Type is java.lang.Boolean. Default value is empty (does not create a variable).

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<!-- tests file and prints true or false -->
<file:isFile source="c:\\tmp\\a.txt"/>

<!-- tests file and prints nothing but creates a Boolean variable b -->
<file:isFile source="c:\\tmp\\a.txt" id="b"/>
<% if (b.booleanValue()) { .... } %>

<!-- do something with existing file -->
<file:isFile source="c:\\tmp\\a.txt">
  <!-- your action is here ... -->
</file:isFile>

isNotFile

Body tag. Tests file and executes own body if file does not exit. Parameters are:

1) source. Describes a path to your file
2) id. Describes a name for new page scope variable that will be created by this tag. Type is java.lang.Boolean. Default value is empty (does not create a variable).

isDirectory

Body tag. Tests directory and executes own body if directory exists. Parameters are:

1) source. Describes a path to your directory
2) id. Describes a name for new page scope variable that will be created by this tag. Type is java.lang.Boolean. Default value is empty (does not create a variable).

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<!-- tests directory and prints true or false -->
<file:isDirectory source="c:\\tmp"/>

<!-- tests directory and prints nothing but creates a Boolean variable b -->
<file:isDirectory source="c:\\tmp\\" id="b"/>
<% if (b.booleanValue()) { .... } %>

size

Prints/returns size of file. Parameters are:

1) source. Describes a path to your file
2) id. Describes a name for new page scope variable that will be created by this tag. Type is java.lang.Long. Default value is empty (does not create a variable).
3) unit. Optional parameter. Describes an unit for size (bytes, kilobytes). Possible values are b or kb. Default value is b (file size in bytes.)

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<file:size source="c:/tmp/myfile.pdf"/>

<!-- saves data in the page scope variable -->
<file:size source="c:/tmp/myfile.pdf" id="A" unit="b" />
Bytes: <%=A%>

lastModified

Prints/returns 'last modified' date. Parameters are:

1) source. Describes a path to your file/directory
2) id. Describes a name for new page scope variable (type is java.util.Date or java.lang.String depends on the format attribute presence) that will be created by this tag. Default value is empty (does not create a variable).
3) format. Optional parameter. Describes format for the printed (returned) date.

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<file:lastLastModified source="c:/tmp/myfile.pdf"/>
<file:lastModified source="c:/tmp/file.zip" format="dd/MM/yyyy hh:mm"/>

<!-- saves date in the page scope variable -->
<file:size source="c:/tmp/myfile.pdf" id="A"/>
Last modified: <%=A%>

setLastModified

Changes 'last modified' date. Parameters are:

1) source. Describes a path to your file/directory
2) time. Optional parameter. Describes a new date. You can use java.util.Date, java.util.Calendar or long value in milliseconds here. By default tag will use current date.

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<file:setLastLastModified source="c:/tmp/myfile.pdf"/>

forEachLine

Body tag executes own body for the each line in text file. The nested page scope variable line (type is java.lang.String) describes the current line. Parameters are:

1) source Describes a name for your file

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<file:forEachLine source="c:/tmp/myfile.txt">
  Line is <%=line%>
</file:forEachLine>

readFile

Tag lets you read text file and save content in the page scope variable or just print it as is. Parameters are:

1) source Describes a name for your file
2) id Optional attribute. Describes a name for your page scope variable (type is java.lang.String).

for example:
 


<%@ taglib uri="taglib.tld" prefix="file" %>
<file:readFile source="/WEB-INF/web.xml"/>

for downloading:

Library: filetags.jar    Description: taglib.tld

 © Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: