18 package org.turro.elephant.impl.util;
20 import java.io.BufferedReader;
22 import java.io.FileInputStream;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.io.InputStreamReader;
26 import java.io.OutputStreamWriter;
27 import java.nio.ByteBuffer;
28 import java.nio.CharBuffer;
29 import java.nio.channels.FileChannel;
30 import java.nio.charset.Charset;
31 import java.util.Date;
32 import java.util.Locale;
33 import java.util.Properties;
34 import javax.servlet.ServletException;
35 import org.turro.string.ObjectString;
36 import org.turro.string.Strings;
37 import org.turro.collections.LinkedProperties;
38 import org.turro.elephant.context.ElephantContext;
39 import org.turro.elephant.context.IAction;
40 import org.turro.elephant.impl.abstracts.AbstractAction;
41 import org.turro.i18n.I_;
42 import org.turro.parser.wiki.WikiCompiler;
43 import org.turro.plugin.contacts.IContact;
51 public static final String
53 VALID_LOCALE_REGEXP =
"(_[a-zA-Z]{2})?(_[a-zA-Z]{2})?(_[a-zA-Z]{2})?";
66 if(
"edit".equals(action)) {
70 else if(
"new".equals(action)) {
72 file =
"000" + ObjectString.formatObject(
new Date(),
"yyyyMMddHHmmssSSS",
false) + lang +
".html";
74 else if(
"delete".equals(action)) {
80 else if(
"preview".equals(action)) {
93 ObjectString.formatObject(
new Date(),
"yyyyMMddHHmmssSSS",
false) +
100 saveContent(wiki, result);
106 private void createPreview() throws IOException, ServletException {
111 "<INPUT align='right' type='button' value='" +
113 "' onClick='window.close()' /><hr />");
114 constructor.
getOut().print(
"<div class='default-element'><div class='default-body'>");
120 private void saveContent(File wiki, File result)
throws IOException {
128 private void removeFiles(String context, String prefix) {
129 File folder =
new File(ElephantContext.getRealPath(context));
130 File files[] = folder.listFiles();
131 for(
int i = 0; i < files.length; i++) {
132 if(files[i].getName().matches(prefix +
".*")) {
139 FileInputStream fis =
new FileInputStream(filename);
140 FileChannel fc = fis.getChannel();
141 ByteBuffer bbuf = fc.map(FileChannel.MapMode.READ_ONLY, 0, (
int)fc.size());
146 public static BufferedReader
getBufferedFile(String folder, String file)
throws java.io.IOException {
150 public static BufferedReader
getBufferedFile(String file)
throws java.io.IOException {
158 public static OutputStreamWriter
getFileWriter(String folder, String file)
throws java.io.IOException {
162 public static OutputStreamWriter
getFileWriter(String file)
throws java.io.IOException {
166 public static OutputStreamWriter
getFileWriter(File file)
throws java.io.IOException {
170 public static OutputStreamWriter
getFileWriter(File file,
boolean append)
throws java.io.IOException {
174 public static Properties
getProperties(File file)
throws java.io.IOException {
175 Properties properties =
new Properties();
181 Properties properties =
new LinkedProperties();
187 String
extension = file.substring(file.lastIndexOf(
"."));
193 String
extension = file.substring(file.lastIndexOf(
"."));
200 int p = name.lastIndexOf(
".");
201 if(p > -1 && p < name.length()) {
202 return name.substring(p + 1);
215 file = file.substring(0, file.lastIndexOf(
"."));
216 int p = file.indexOf(
"_");
219 return Locale.forLanguageTag(file.substring(p + 1));
220 }
catch(Exception ex) {
221 return Locale.ENGLISH;
224 return Locale.ENGLISH;
229 file = file.substring(0, file.lastIndexOf(
"."));
230 int p = file.indexOf(
"_");
232 return file.substring(p);
239 if((p = context.indexOf(
"/_internal")) > -1) {
240 return context.substring(0, p);
245 public static String
getContent(File file)
throws IOException {
248 StringBuilder sb =
new StringBuilder();
250 while((s = br.readLine()) !=
null) {
254 return sb.toString();
262 StringBuilder sb =
new StringBuilder();
264 while((s = br.readLine()) !=
null) {
269 return sb.toString();
274 public static void setContent(File file, String value)
throws IOException {
282 public static void appendContent(File file, String value)
throws IOException {
291 String filePath = file.getAbsolutePath();
292 return new File(filePath.substring(0, filePath.lastIndexOf(
'/')));
300 if(!path.contains(
"WEB-INF")) {
301 name = Strings.unpunctuate(name);
307 File f =
new File(requestURI);
308 return f.exists() && f.isFile();
static String getRealPath(String path)
static String getEncoding()
String getActionParameter()
static OutputStreamWriter getFileWriter(File file, boolean append)
static String getLang(String file)
static boolean existsFile(String requestURI)
static String substituteLang(String file, String lang)
static String baseName(String file)
static Locale getLocale(String file)
static OutputStreamWriter getFileWriter(String folder, String file)
static String getContentWithLineBreaks(File file)
static String getRealContext(String context)
static OutputStreamWriter getFileWriter(File file)
static CharSequence getCharSequenceFile(String filename)
static final String VALID_EXT_REGEXP
static Properties getOrderedProperties(File file)
static String checkFileName(File folder, String name)
static void appendContent(File file, String value)
static void setContent(File file, String value)
static String checkFileName(String path, String name)
static Properties getProperties(File file)
static String crudeName(String file)
static OutputStreamWriter getFileWriter(String file)
static BufferedReader getBufferedFile(String folder, String file)
static File getFolderFile(File file)
static String extension(String name)
static BufferedReader getBufferedFile(String file)
static BufferedReader getBufferedFile(File file)
static String getContent(File file)
static String get(String msg)
String getParameter(String param)
void processOutput(String text)
void redirect(String path)
String getParameter(String param)
boolean isInRole(String role)