1 package fr.paris.lutece.plugins.newsletter.modules.htmldocs.util;
2
3 import org.apache.commons.lang.StringUtils;
4
5
6
7
8 public final class NewsletterHtmlDocUtils
9 {
10
11
12
13 public static final String CONSTANT_IMG_FILE_TYPE = "image";
14
15 private static final String CONSTANT_ZERO = "0";
16
17
18
19
20 private NewsletterHtmlDocUtils( )
21 {
22
23 }
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public static String rewriteImgUrls( String strContent, String strBaseUrl, String strUnsecuredBaseUrl, String strUnsecuredFolderPath,
41 String strUnsecuredFolder )
42 {
43 if ( strContent == null )
44 {
45 return StringUtils.EMPTY;
46 }
47 HtmlDomDocNewsletterDocument doc = new HtmlDomDocNewsletterDocument( strContent, strBaseUrl );
48 doc.convertUrlsToUnsecuredUrls( HtmlDomDocNewsletterDocument.ELEMENT_IMG, strUnsecuredBaseUrl, strUnsecuredFolderPath, strUnsecuredFolder );
49 doc.convertUrlsToUnsecuredUrls( HtmlDomDocNewsletterDocument.ELEMENT_A, strUnsecuredBaseUrl, strUnsecuredFolderPath, strUnsecuredFolder );
50
51 return doc.getContent( );
52 }
53
54
55
56
57
58
59
60
61
62
63 public static String formatInteger( int nNbToformat, int nNbDigits )
64 {
65 String strNumber = Integer.toString( nNbToformat );
66 if ( strNumber.length( ) > nNbDigits )
67 {
68 return strNumber;
69 }
70 StringBuffer sbNumber = new StringBuffer( nNbDigits );
71 int i = strNumber.length( );
72 while ( i < nNbDigits )
73 {
74 sbNumber.append( CONSTANT_ZERO );
75 i++;
76 }
77 sbNumber.append( strNumber );
78 return sbNumber.toString( );
79 }
80 }