Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
*/
package fr.paris.lutece.plugins.newsletter.service;

import java.security.SecureRandom;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -189,7 +189,7 @@ public void doSubscription( HttpServletRequest request ) throws SiteMessageExcep
if ( properties.isValidationActive( ) )
{
// generate validation key
Random random = new Random( );
SecureRandom random = new SecureRandom( );
int nAlea = random.nextInt( );
// add pair in db
AwaitingActivationHome.create( subscriber.getId( ), nAlea, getPlugin( ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;

import javax.xml.XMLConstants;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
Expand Down Expand Up @@ -206,29 +206,24 @@ public String getContent( )
StringWriter writer = new StringWriter( );
StreamResult result = new StreamResult( writer );
TransformerFactory tf = TransformerFactory.newInstance( );
tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
Transformer transformer;

try
{
transformer = tf.newTransformer( );
transformer.transform( domSource, result );
}
catch( TransformerConfigurationException e )
{
AppLogService.error( e.getMessage( ) );

return null;
}
catch( TransformerException e )
{
AppLogService.error( e.getMessage( ) );

return null;
}

String stringResult = writer.toString( );
return writer.toString( );

return stringResult;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -444,7 +445,9 @@ public String doModifyNewsletterTemplate( HttpServletRequest request )
String strPathFileNewsletterTemplate = AppPathService.getPath( PROPERTY_PATH_TEMPLATE )
+ AppPropertiesService.getProperty( NewsLetterConstants.PROPERTY_PATH_FILE_NEWSLETTER_TEMPLATE );
File file = new File( strPathFileNewsletterTemplate + File.separator + newsletterTemplate.getFileKey() );
file.delete( );
if( file.exists( ) ) {
Files.delete( file.toPath( ) );
}
}
newsletterTemplate.setFileKey( templateFileKey );
}
Expand All @@ -462,7 +465,9 @@ public String doModifyNewsletterTemplate( HttpServletRequest request )
{
String strPathFileNewsletterTemplate = AppPathService.getPath( PROPERTY_PATH_IMAGE_NEWSLETTER_TEMPLATE );
File file = new File( strPathFileNewsletterTemplate + File.separator + newsletterTemplate.getPictureKey() );
file.delete( );
if( file.exists( ) ) {
Files.delete( file.toPath( ) );
}
}
newsletterTemplate.setPictureKey( strImageKey );
}
Expand Down Expand Up @@ -536,7 +541,9 @@ public String getModifyNewsLetterTemplateFile( HttpServletRequest request )
fileWriter.close( );
fileReader = new BufferedReader( new FileReader( file ) );
// delete the temporary file
file.delete( );
if( file.exists( ) ) {
Files.delete( file.toPath( ) );
}
String strFileName = luteceTemplateFile.getTitle( );
model.put( NewsLetterConstants.MARK_TEMPLATE_FILE_NAME, strFileName );
model.put( fr.paris.lutece.plugins.newsletter.util.NewsLetterConstants.MARK_TEMPLATE_FILE, luteceTemplateFile.getPhysicalFile().getValue() );
Expand Down Expand Up @@ -641,7 +648,9 @@ public String doModifyNewsletterTemplateFile( HttpServletRequest request )
{
String strPathFileNewsletterTemplate = AppPathService.getPath( PROPERTY_PATH_IMAGE_NEWSLETTER_TEMPLATE );
File file = new File( strPathFileNewsletterTemplate + File.separator + strOldImageName );
file.delete( );
if( file.exists( ) ) {
Files.delete(file.toPath());
}
}
}

Expand Down Expand Up @@ -671,7 +680,9 @@ public String doModifyNewsletterTemplateFile( HttpServletRequest request )
luteceFile.setPhysicalFile( physicalFile );
String newFileKey = NewsletterFileService.storeFile( luteceFile );
newsletterTemplate.setFileKey( newFileKey );
file.delete();
if( file.exists( ) ) {
Files.delete( file.toPath( ) );
}

}

Expand Down Expand Up @@ -756,30 +767,34 @@ public String doRemoveNewsLetterTemplate( HttpServletRequest request )
return AdminMessageService.getMessageUrl( request, Messages.USER_ACCESS_DENIED, AdminMessage.TYPE_ERROR );
}

String strFileName = newsLetterTemplate.getFileKey( );
String strPictureName = newsLetterTemplate.getPictureKey( );
try {
String strFileName = newsLetterTemplate.getFileKey( );
String strPictureName = newsLetterTemplate.getPictureKey( );

// removes the file
String strPathFileNewsletterTemplate = AppPathService.getPath( PROPERTY_PATH_TEMPLATE )
+ AppPropertiesService.getProperty( NewsLetterConstants.PROPERTY_PATH_FILE_NEWSLETTER_TEMPLATE );
File file = new File( strPathFileNewsletterTemplate + NewsLetterConstants.CONSTANT_SLASH + strFileName );
// removes the file
String strPathFileNewsletterTemplate = AppPathService.getPath( PROPERTY_PATH_TEMPLATE )
+ AppPropertiesService.getProperty( NewsLetterConstants.PROPERTY_PATH_FILE_NEWSLETTER_TEMPLATE );
File file = new File( strPathFileNewsletterTemplate + NewsLetterConstants.CONSTANT_SLASH + strFileName );

if ( file.exists( ) )
{
file.delete( );
}
if ( file.exists( ) )
{
Files.delete( file.toPath( ) );
}

// removes the picture
String strPathImageNewsletterTemplate = AppPathService.getPath( PROPERTY_PATH_IMAGE_NEWSLETTER_TEMPLATE );
File picture = new File( strPathImageNewsletterTemplate + NewsLetterConstants.CONSTANT_SLASH + strPictureName );
// removes the picture
String strPathImageNewsletterTemplate = AppPathService.getPath( PROPERTY_PATH_IMAGE_NEWSLETTER_TEMPLATE );
File picture = new File( strPathImageNewsletterTemplate + NewsLetterConstants.CONSTANT_SLASH + strPictureName );

if ( picture.exists( ) )
{
picture.delete( );
}
if ( picture.exists( ) )
{
Files.delete( picture.toPath( ) );
}

// removes the newsletter template from the database
NewsLetterTemplateHome.remove( nNewsletterTemplateId, getPlugin( ) );
// removes the newsletter template from the database
NewsLetterTemplateHome.remove( nNewsletterTemplateId, getPlugin( ) );
} catch (IOException e) {
AppLogService.error( e.getMessage( ), e );
}

// loads the newsletter templates management page
// If the operation occurred well returns on the info of the newsletter
Expand Down