how to copy page with date | Community
Skip to main content
max_oda
October 16, 2015
Solved

how to copy page with date

  • October 16, 2015
  • 2 replies
  • 927 views

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);
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ojjis

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

2 replies

Scott_Brodersen
Level 8
October 16, 2015

this page has some tips about escaping the illegal characters:

 

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

 

scott

Ojjis
OjjisAccepted solution
Level 7
October 16, 2015

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