BrightSide Workbench Full Report + Source Code
org.turro.elephant.impl.util.FileUtil Class Reference
Inheritance diagram for org.turro.elephant.impl.util.FileUtil:
Collaboration diagram for org.turro.elephant.impl.util.FileUtil:

Public Member Functions

 FileUtil ()
 
int execute () throws Exception
 
- Public Member Functions inherited from org.turro.elephant.impl.abstracts.AbstractAction
 AbstractAction ()
 
void setConstructor (IConstructor constructor)
 
IConstructor getConstructor ()
 
String getContextParameter ()
 
String getIdelParameter ()
 
String getActionParameter ()
 
String getParameter (String param)
 
String getParameter (String param, boolean encode)
 
String getStringParameter (String param)
 
String getValueParameter (String param)
 
boolean getBooleanParameter (String param)
 
int getIntParameter (String param, int defaultValue)
 
double getDoubleParameter (String param, double defaultValue)
 
Date getDateParameter (String param, Date defaultValue)
 

Static Public Member Functions

static CharSequence getCharSequenceFile (String filename) throws IOException
 
static BufferedReader getBufferedFile (String folder, String file) throws java.io.IOException
 
static BufferedReader getBufferedFile (String file) throws java.io.IOException
 
static BufferedReader getBufferedFile (File file) throws java.io.IOException
 
static OutputStreamWriter getFileWriter (String folder, String file) throws java.io.IOException
 
static OutputStreamWriter getFileWriter (String file) throws java.io.IOException
 
static OutputStreamWriter getFileWriter (File file) throws java.io.IOException
 
static OutputStreamWriter getFileWriter (File file, boolean append) throws java.io.IOException
 
static Properties getProperties (File file) throws java.io.IOException
 
static Properties getOrderedProperties (File file) throws java.io.IOException
 
static String substituteLang (String file, String lang)
 
static String baseName (String file)
 
static String extension (String name)
 
static String crudeName (String file)
 
static Locale getLocale (String file)
 
static String getLang (String file)
 
static String getRealContext (String context)
 
static String getContent (File file) throws IOException
 
static String getContentWithLineBreaks (File file) throws IOException
 
static void setContent (File file, String value) throws IOException
 
static void appendContent (File file, String value) throws IOException
 
static File getFolderFile (File file)
 
static String checkFileName (File folder, String name)
 
static String checkFileName (String path, String name)
 
static boolean existsFile (String requestURI)
 
- Static Public Member Functions inherited from org.turro.elephant.impl.abstracts.AbstractAction
static String makeDateParameter (Date date)
 
static String makeDateParameter (Timestamp date)
 
static String getValuePortion (String key, String value)
 

Static Public Attributes

static final String VALID_EXT_REGEXP = "\\.(jsp|html|htm|txt|zul|zhtml)"
 
- Static Public Attributes inherited from org.turro.elephant.context.IAction
static final int DONE = 0
 
static final int NO_DATA = 1
 
static final int ERROR = 2
 

Additional Inherited Members

- Protected Attributes inherited from org.turro.elephant.impl.abstracts.AbstractAction
IConstructor constructor
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 49 of file FileUtil.java.

Constructor & Destructor Documentation

◆ FileUtil()

org.turro.elephant.impl.util.FileUtil.FileUtil ( )

Creates a new instance of FileUtil

Definition at line 56 of file FileUtil.java.

56  {
57  }

Member Function Documentation

◆ appendContent()

static void org.turro.elephant.impl.util.FileUtil.appendContent ( File  file,
String  value 
) throws IOException
static

Definition at line 282 of file FileUtil.java.

282  {
283  if(value != null) {
284  OutputStreamWriter osw = getFileWriter(file, true);
285  osw.write(value);
286  osw.close();
287  }
288  }
static OutputStreamWriter getFileWriter(String folder, String file)
Definition: FileUtil.java:158
Here is the call graph for this function:
Here is the caller graph for this function:

◆ baseName()

static String org.turro.elephant.impl.util.FileUtil.baseName ( String  file)
static

Definition at line 191 of file FileUtil.java.

191  {
192  if(file.matches(".*" + VALID_EXT_REGEXP)) {
193  String extension = file.substring(file.lastIndexOf("."));
194  return file.replaceAll(VALID_LOCALE_REGEXP + VALID_EXT_REGEXP + "$", extension);
195  }
196  return null;
197  }
static final String VALID_EXT_REGEXP
Definition: FileUtil.java:52
static String extension(String name)
Definition: FileUtil.java:199
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkFileName() [1/2]

static String org.turro.elephant.impl.util.FileUtil.checkFileName ( File  folder,
String  name 
)
static

Definition at line 295 of file FileUtil.java.

295  {
296  return checkFileName(folder.getAbsolutePath(), name);
297  }
static String checkFileName(File folder, String name)
Definition: FileUtil.java:295

◆ checkFileName() [2/2]

static String org.turro.elephant.impl.util.FileUtil.checkFileName ( String  path,
String  name 
)
static

Definition at line 299 of file FileUtil.java.

299  {
300  if(!path.contains("WEB-INF")) {
301  name = Strings.unpunctuate(name);
302  }
303  return name;
304  }

◆ crudeName()

static String org.turro.elephant.impl.util.FileUtil.crudeName ( String  file)
static

Definition at line 207 of file FileUtil.java.

207  {
208  if(file.matches(".*" + VALID_EXT_REGEXP)) {
209  return file.replaceAll(VALID_LOCALE_REGEXP + VALID_EXT_REGEXP + "$", "");
210  }
211  return null;
212  }
Here is the caller graph for this function:

◆ execute()

int org.turro.elephant.impl.util.FileUtil.execute ( ) throws Exception

Called by constructor in request for one action.

Exceptions
java.lang.Exception
Returns
Action's result.

Implements org.turro.elephant.context.IAction.

Definition at line 60 of file FileUtil.java.

60  {
61  String context = getParameter("context"),
62  file = getParameter("file"),
63  lang = getParameter("lang"),
64  action = getActionParameter();
65 
66  if("edit".equals(action)) {
67  if(!constructor.isInRole("default:edit")) return IAction.ERROR;
68  if(!(constructor.isInRole("lang:" + lang) || constructor.isInRole("lang:all"))) return IAction.ERROR;
69  }
70  else if("new".equals(action)) {
71  if(!constructor.isInRole("default:new")) return IAction.ERROR;
72  file = "000" + ObjectString.formatObject(new Date(), "yyyyMMddHHmmssSSS", false) + lang + ".html";
73  }
74  else if("delete".equals(action)) {
75  if(!constructor.isInRole("default:delete")) return IAction.ERROR;
76  removeFiles(context, crudeName(file));
78  return IAction.DONE;
79  }
80  else if("preview".equals(action)) {
81  if(!constructor.isInRole("default:edit")) return IAction.ERROR;
82  if(!(constructor.isInRole("lang:" + lang) || constructor.isInRole("lang:all"))) return IAction.ERROR;
83  createPreview();
84  return IAction.DONE;
85  }
86 
87  file = substituteLang(file, lang);
88 
89  File result = new File(ElephantContext.getRealPath(context + "/" + file));
90  IContact user = constructor.getUser();
91  String actual = crudeName(file) +
92  "." +
93  ObjectString.formatObject(new Date(), "yyyyMMddHHmmssSSS", false) +
94  "." +
95  user.getId() +
96  lang +
97  ".wiki";
98  File wiki = new File(ElephantContext.getRealPath(context + "/" + actual));
99 
100  saveContent(wiki, result);
101 
103  return IAction.DONE;
104  }
static String substituteLang(String file, String lang)
Definition: FileUtil.java:186
static String getRealContext(String context)
Definition: FileUtil.java:237
static String crudeName(String file)
Definition: FileUtil.java:207
String getParameter(String param)
Here is the call graph for this function:

◆ existsFile()

static boolean org.turro.elephant.impl.util.FileUtil.existsFile ( String  requestURI)
static

Definition at line 306 of file FileUtil.java.

306  {
307  File f = new File(requestURI);
308  return f.exists() && f.isFile();
309  }

◆ extension()

static String org.turro.elephant.impl.util.FileUtil.extension ( String  name)
static

Definition at line 199 of file FileUtil.java.

199  {
200  int p = name.lastIndexOf(".");
201  if(p > -1 && p < name.length()) {
202  return name.substring(p + 1);
203  }
204  return null;
205  }
Here is the caller graph for this function:

◆ getBufferedFile() [1/3]

static BufferedReader org.turro.elephant.impl.util.FileUtil.getBufferedFile ( File  file) throws java.io.IOException
static

Definition at line 154 of file FileUtil.java.

154  {
155  return new BufferedReader(new InputStreamReader(new FileInputStream(file), ElephantContext.getEncoding()));
156  }
Here is the call graph for this function:

◆ getBufferedFile() [2/3]

static BufferedReader org.turro.elephant.impl.util.FileUtil.getBufferedFile ( String  file) throws java.io.IOException
static

Definition at line 150 of file FileUtil.java.

150  {
151  return getBufferedFile(new File(file));
152  }
static BufferedReader getBufferedFile(String folder, String file)
Definition: FileUtil.java:146
Here is the call graph for this function:

◆ getBufferedFile() [3/3]

static BufferedReader org.turro.elephant.impl.util.FileUtil.getBufferedFile ( String  folder,
String  file 
) throws java.io.IOException
static

Definition at line 146 of file FileUtil.java.

146  {
147  return getBufferedFile(folder + "/" + file);
148  }
Here is the caller graph for this function:

◆ getCharSequenceFile()

static CharSequence org.turro.elephant.impl.util.FileUtil.getCharSequenceFile ( String  filename) throws IOException
static

Definition at line 138 of file FileUtil.java.

138  {
139  FileInputStream fis = new FileInputStream(filename);
140  FileChannel fc = fis.getChannel();
141  ByteBuffer bbuf = fc.map(FileChannel.MapMode.READ_ONLY, 0, (int)fc.size());
142  CharBuffer cbuf = Charset.forName(ElephantContext.getEncoding()).newDecoder().decode(bbuf);
143  return cbuf;
144  }
Here is the call graph for this function:

◆ getContent()

static String org.turro.elephant.impl.util.FileUtil.getContent ( File  file) throws IOException
static

Definition at line 245 of file FileUtil.java.

245  {
246  if(file.exists()) {
247  BufferedReader br = getBufferedFile(file);
248  StringBuilder sb = new StringBuilder();
249  String s;
250  while((s = br.readLine()) != null) {
251  sb.append(s);
252  }
253  br.close();
254  return sb.toString();
255  }
256  return null;
257  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getContentWithLineBreaks()

static String org.turro.elephant.impl.util.FileUtil.getContentWithLineBreaks ( File  file) throws IOException
static

Definition at line 259 of file FileUtil.java.

259  {
260  if(file.exists()) {
261  BufferedReader br = getBufferedFile(file);
262  StringBuilder sb = new StringBuilder();
263  String s;
264  while((s = br.readLine()) != null) {
265  sb.append(s);
266  sb.append("\n");
267  }
268  br.close();
269  return sb.toString();
270  }
271  return null;
272  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFileWriter() [1/4]

static OutputStreamWriter org.turro.elephant.impl.util.FileUtil.getFileWriter ( File  file) throws java.io.IOException
static

Definition at line 166 of file FileUtil.java.

166  {
167  return getFileWriter(file, false);
168  }
Here is the call graph for this function:

◆ getFileWriter() [2/4]

static OutputStreamWriter org.turro.elephant.impl.util.FileUtil.getFileWriter ( File  file,
boolean  append 
) throws java.io.IOException
static

Definition at line 170 of file FileUtil.java.

170  {
171  return new OutputStreamWriter(new FileOutputStream(file, append), ElephantContext.getEncoding());
172  }
Here is the call graph for this function:

◆ getFileWriter() [3/4]

static OutputStreamWriter org.turro.elephant.impl.util.FileUtil.getFileWriter ( String  file) throws java.io.IOException
static

Definition at line 162 of file FileUtil.java.

162  {
163  return getFileWriter(new File(file));
164  }
Here is the call graph for this function:

◆ getFileWriter() [4/4]

static OutputStreamWriter org.turro.elephant.impl.util.FileUtil.getFileWriter ( String  folder,
String  file 
) throws java.io.IOException
static

Definition at line 158 of file FileUtil.java.

158  {
159  return getFileWriter(folder + "/" + file);
160  }
Here is the caller graph for this function:

◆ getFolderFile()

static File org.turro.elephant.impl.util.FileUtil.getFolderFile ( File  file)
static

Definition at line 290 of file FileUtil.java.

290  {
291  String filePath = file.getAbsolutePath();
292  return new File(filePath.substring(0, filePath.lastIndexOf('/')));
293  }
Here is the caller graph for this function:

◆ getLang()

static String org.turro.elephant.impl.util.FileUtil.getLang ( String  file)
static

Definition at line 228 of file FileUtil.java.

228  {
229  file = file.substring(0, file.lastIndexOf("."));
230  int p = file.indexOf("_");
231  if(p > -1)
232  return file.substring(p);
233  else
234  return "";
235  }
Here is the caller graph for this function:

◆ getLocale()

static Locale org.turro.elephant.impl.util.FileUtil.getLocale ( String  file)
static

Definition at line 214 of file FileUtil.java.

214  {
215  file = file.substring(0, file.lastIndexOf("."));
216  int p = file.indexOf("_");
217  if(p > -1) {
218  try {
219  return Locale.forLanguageTag(file.substring(p + 1));
220  } catch(Exception ex) {
221  return Locale.ENGLISH;
222  }
223  } else {
224  return Locale.ENGLISH;
225  }
226  }

◆ getOrderedProperties()

static Properties org.turro.elephant.impl.util.FileUtil.getOrderedProperties ( File  file) throws java.io.IOException
static

Definition at line 180 of file FileUtil.java.

180  {
181  Properties properties = new LinkedProperties();
182  properties.load(new InputStreamReader(new FileInputStream(file), ElephantContext.getEncoding()));
183  return properties;
184  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getProperties()

static Properties org.turro.elephant.impl.util.FileUtil.getProperties ( File  file) throws java.io.IOException
static

Definition at line 174 of file FileUtil.java.

174  {
175  Properties properties = new Properties();
176  properties.load(new InputStreamReader(new FileInputStream(file), ElephantContext.getEncoding()));
177  return properties;
178  }
Here is the call graph for this function:

◆ getRealContext()

static String org.turro.elephant.impl.util.FileUtil.getRealContext ( String  context)
static

Definition at line 237 of file FileUtil.java.

237  {
238  int p;
239  if((p = context.indexOf("/_internal")) > -1) {
240  return context.substring(0, p);
241  }
242  return context;
243  }
Here is the caller graph for this function:

◆ setContent()

static void org.turro.elephant.impl.util.FileUtil.setContent ( File  file,
String  value 
) throws IOException
static

Definition at line 274 of file FileUtil.java.

274  {
275  if(value != null) {
276  OutputStreamWriter osw = getFileWriter(file);
277  osw.write(value);
278  osw.close();
279  }
280  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ substituteLang()

static String org.turro.elephant.impl.util.FileUtil.substituteLang ( String  file,
String  lang 
)
static

Definition at line 186 of file FileUtil.java.

186  {
187  String extension = file.substring(file.lastIndexOf("."));
188  return file.replaceAll(VALID_LOCALE_REGEXP + VALID_EXT_REGEXP + "$", lang + extension);
189  }
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ VALID_EXT_REGEXP

final String org.turro.elephant.impl.util.FileUtil.VALID_EXT_REGEXP = "\\.(jsp|html|htm|txt|zul|zhtml)"
static

Definition at line 52 of file FileUtil.java.


The documentation for this class was generated from the following file: