18 package org.turro.elephant.impl.util;
20 import java.io.BufferedReader;
22 import java.io.IOException;
23 import java.io.OutputStreamWriter;
24 import java.io.PrintWriter;
25 import org.turro.elephant.context.ElephantContext;
26 import org.turro.elephant.context.IAction;
27 import org.turro.elephant.impl.abstracts.AbstractAction;
35 public static final String
51 if(
"list-folders".equals(action)) {
52 if(realPath.exists()) {
53 return listFolders(realPath);
59 else if(
"list-files".equals(action)) {
60 if(realPath.exists()) {
61 return listFiles(realPath, selectable);
67 else if(
"list-attachments".equals(action)) {
68 if(realPath.exists()) {
69 return listAttachments(realPath, selectable);
75 else if(
"remove-attachments".equals(action)) {
76 return removeAttachments(selectable, realPath);
78 else if(
"file-content".equals(action)) {
79 if(realPath.exists()) {
80 return fileContent(realPath);
86 else if(
"save-content".equals(action)) {
87 return saveContent(realPath);
89 else if(
"remove-file".equals(action)) {
90 if(realPath.exists()) {
100 private int removeAttachments(
final boolean selectable,
final File realPath)
throws IOException {
103 for(
int i = 0; i < files.length; i++) {
108 return listAttachments(realPath, selectable);
111 private int saveContent(
final File realPath)
throws IOException {
115 s = s.replaceAll(
"\\*\\-am\\-\\*",
"&");
116 s = s.replaceAll(
"\\*\\-eq\\-\\*",
"=");
117 s = s.replaceAll(
"\\*\\-pl\\-\\*",
"+");
118 OutputStreamWriter osw = FileUtil.getFileWriter(realPath);
124 out.println(
"No data!");
129 private int fileContent(
final File realPath)
throws IOException {
130 BufferedReader br = FileUtil.getBufferedFile(realPath);
133 while((s = br.readLine()) !=
null) {
140 private int listAttachments(
final File realPath,
final boolean selectable)
throws IOException {
141 File[] children = realPath.listFiles();
145 for(
int i = 0; i < children.length; i++) {
146 s = children[i].getAbsolutePath();
148 out.print(
"<li path='" + ElephantContext.getRelativePath(s) +
"'>");
150 out.print(
"<input type='checkbox'/>");
152 if(children[i].isFile()) {
153 out.print(
"<a class='file'>");
155 out.print(children[i].getName());
157 out.println(
"</li>");
160 out.println(
"</ul>");
164 private int listFiles(
final File realPath,
final boolean selectable)
throws IOException {
165 File[] children = realPath.listFiles();
168 for(
int i = 0; i < children.length; i++) {
169 out.print(
"<li path='" + ElephantContext.getRelativePath(children[i].getAbsolutePath()) +
"'>");
171 out.print(
"<input type='checkbox'/>");
173 if(children[i].isDirectory()) {
174 out.print(
"<a class='folder'>");
176 else if(children[i].isFile()) {
177 out.print(
"<a class='file'>");
179 out.print(children[i].getName());
181 out.println(
"</li>");
183 out.println(
"</ul>");
187 private int listFolders(
final File realPath)
throws IOException {
188 File[] children = realPath.listFiles();
191 for(
int i = 0; i < children.length; i++) {
192 if(children[i].isDirectory()) {
193 out.print(
"<li class='collapsed' path='" + ElephantContext.getRelativePath(children[i].getAbsolutePath()) +
"'>");
194 out.print(
"<a class='folder'>");
195 out.print(children[i].getName());
197 out.println(
"</li>");
200 out.println(
"</ul>");
static String getRealPath(String path)
String getActionParameter()
static final String VALID_ATTACHMENTS
String getParameter(String param)
String getParameter(String param)