Expand my Community achievements bar.

SOLVED

how to copy page with date

Avatar

Level 1

Hi,

i would like to copy some page with the current date.

Example myPage.html -> myPage_2013-08-15_13:36.html

The following code copies the page but without date. It is because of such signs (-, :,....). How can you overcome this?

Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm" ); String testDate= df.format(date); pageManager.copy(pathOfMyPage), pathOfMyPage-"+testDate, "", true, false);
1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi there, for me this code worked just fine:

 

<% Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd_HH-mm" ); String testDate= df.format(date); String path = currentPage.getPath(); pageManager.copy(currentPage,path+testDate,null, true, false,true); %>

I know that it's not exactly the same pattern as you used but I don't really see the point in having ":" in the file name.
Thats the only difference though..

Hope this helps
Johan

View solution in original post

2 Replies

Avatar

Level 8

this page has some tips about escaping the illegal characters:

 

http://wiki.apache.org/jackrabbit/EncodingAndEscaping

 

scott

Avatar

Correct answer by
Level 7

Hi there, for me this code worked just fine:

 

<% Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd_HH-mm" ); String testDate= df.format(date); String path = currentPage.getPath(); pageManager.copy(currentPage,path+testDate,null, true, false,true); %>

I know that it's not exactly the same pattern as you used but I don't really see the point in having ":" in the file name.
Thats the only difference though..

Hope this helps
Johan