You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2012/07/02 07:10:11 UTC
svn commit: r1356068 [3/3] - in /incubator/openmeetings/trunk/singlewebapp:
WebContent/src/base/hibernate/ src/org/openmeetings/app/
src/org/openmeetings/app/data/file/
src/org/openmeetings/app/data/flvrecord/converter/
src/org/openmeetings/app/data/fl...
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupExport.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupExport.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupExport.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupExport.java Mon Jul 2 05:10:03 2012
@@ -19,13 +19,10 @@
package org.openmeetings.servlet.outputhandler;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
-import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
@@ -38,6 +35,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.transaction.util.FileHelper;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
@@ -84,6 +82,7 @@ import org.openmeetings.app.persistence.
import org.openmeetings.app.persistence.beans.user.UserContacts;
import org.openmeetings.app.persistence.beans.user.Users;
import org.openmeetings.app.sip.api.impl.asterisk.dao.AsteriskDAOImpl;
+import org.openmeetings.utils.OmFileHelper;
import org.openmeetings.utils.math.CalendarPatterns;
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
@@ -144,8 +143,8 @@ public class BackupExport {
@Autowired
private AsteriskDAOImpl asteriskDAOImpl;
- public void performExport(String filePath, File backup_dir,
- boolean includeFiles, String omFilesDir) throws Exception {
+ public void performExport(File filePath, File backup_dir,
+ boolean includeFiles) throws Exception {
if (!backup_dir.exists()) {
backup_dir.mkdirs();
@@ -420,7 +419,7 @@ public class BackupExport {
targetDir.mkdir();
}
- File sourceDir = new File(omFilesDir, OpenmeetingsVariables.UPLOAD_DIR);
+ File sourceDir = OmFileHelper.getUploadDir();
File[] files = sourceDir.listFiles();
for (File file : files) {
@@ -433,7 +432,7 @@ public class BackupExport {
log.debug("### " + file.getName());
- copyDirectory(file, targetDir);
+ FileHelper.copyRec(file, targetDir);
}
}
}
@@ -447,10 +446,9 @@ public class BackupExport {
targetDirRec.mkdir();
}
- File sourceDirRec = new File(omFilesDir, OpenmeetingsVariables.STREAMS_DIR
- + File.separatorChar + "hibernate" + File.separatorChar);
+ File sourceDirRec = OmFileHelper.getStreamsHibernateDir();
- copyDirectory(sourceDirRec, targetDirRec);
+ FileHelper.copyRec(sourceDirRec, targetDirRec);
}
List<File> fileList = new ArrayList<File>();
@@ -505,12 +503,7 @@ public class BackupExport {
* ##################### Create Base Folder structure
*/
- String current_dir = servletCtx.getRealPath("/");
- File working_dir = new File(new File(current_dir, OpenmeetingsVariables.UPLOAD_DIR), "backup");
-
- if (!working_dir.exists()) {
- working_dir.mkdir();
- }
+ File working_dir = OmFileHelper.getUploadBackupDir();
String dateString = "backup_"
+ CalendarPatterns.getTimeForStreamId(new Date());
@@ -519,12 +512,8 @@ public class BackupExport {
String requestedFile = dateString + ".zip";
File backupFile = new File(backup_dir, requestedFile);
- String full_path = backupFile.getAbsolutePath();
try {
- performExport(full_path, backup_dir, includeFiles, current_dir);
-
- RandomAccessFile rf = new RandomAccessFile(full_path, "r");
-
+ performExport(backupFile, backup_dir, includeFiles);
httpServletResponse.reset();
httpServletResponse.resetBuffer();
@@ -533,18 +522,10 @@ public class BackupExport {
httpServletResponse.setHeader("Content-Disposition",
"attachment; filename=\"" + requestedFile + "\"");
httpServletResponse.setHeader("Content-Length",
- "" + rf.length());
+ "" + backupFile.length());
OutputStream out = httpServletResponse.getOutputStream();
-
- byte[] buffer = new byte[1024];
- int readed = -1;
-
- while ((readed = rf.read(buffer, 0, buffer.length)) > -1) {
- out.write(buffer, 0, readed);
- }
-
- rf.close();
+ OmFileHelper.copyFile(backupFile, out);
out.flush();
out.close();
@@ -553,12 +534,11 @@ public class BackupExport {
}
if (backupFile.exists()) {
- // log.debug("DELETE :1: "+backupFile.getAbsolutePath());
+ // log.debug("DELETE :1: "+backupFile.getCanonicalPath());
backupFile.delete();
}
- deleteDirectory(backup_dir);
-
+ FileHelper.removeRec(backup_dir);
}
} else {
log.debug("ERROR LangExport: not authorized FileDownload "
@@ -649,26 +629,6 @@ public class BackupExport {
return document;
}
- public boolean deleteDirectory(File path) throws IOException {
-
- // log.debug("deleteDirectory :: "+path);
-
- if (path.exists()) {
- File[] files = path.listFiles();
- for (int i = 0; i < files.length; i++) {
- if (files[i].isDirectory()) {
- deleteDirectory(files[i]);
- } else {
- files[i].delete();
- }
- }
- }
-
- // log.debug("DELETE :3: "+path.getAbsolutePath());
-
- return (path.delete());
- }
-
public void getAllFiles(File dir, List<File> fileList) throws IOException {
try {
File[] files = dir.listFiles();
@@ -707,42 +667,9 @@ public class BackupExport {
}
}
- public void copyDirectory(File sourceLocation, File targetLocation)
- throws IOException {
-
- // log.debug("^^^^ "+sourceLocation.getName()+" || "+targetLocation.getName());
-
- if (sourceLocation.isDirectory()) {
- if (!targetLocation.exists()) {
- targetLocation.mkdir();
- }
-
- String[] children = sourceLocation.list();
- for (int i = 0; i < children.length; i++) {
- copyDirectory(new File(sourceLocation, children[i]), new File(
- targetLocation, children[i]));
- }
- } else {
-
- InputStream in = new FileInputStream(sourceLocation);
- OutputStream out = new FileOutputStream(targetLocation);
-
- // Copy the bits from instream to outstream
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- in.close();
- out.close();
- }
- }
-
public void addToZip(File directoryToZip, File file, ZipOutputStream zos)
throws FileNotFoundException, IOException {
- FileInputStream fis = new FileInputStream(file);
-
// we want the zipEntry's path to be a relative path that is relative
// to the directory being zipped, so chop off the rest of the path
String zipFilePath = file.getCanonicalPath().substring(
@@ -752,14 +679,8 @@ public class BackupExport {
ZipEntry zipEntry = new ZipEntry(zipFilePath);
zos.putNextEntry(zipEntry);
- byte[] bytes = new byte[1024];
- int length;
- while ((length = fis.read(bytes)) >= 0) {
- zos.write(bytes, 0, length);
- }
-
+ OmFileHelper.copyFile(file, zos);
zos.closeEntry();
- fis.close();
}
public Document createAppointementDocument(List<Appointment> aList)
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/BackupImportController.java Mon Jul 2 05:10:03 2012
@@ -19,11 +19,8 @@
package org.openmeetings.servlet.outputhandler;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -39,6 +36,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.transaction.util.FileHelper;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
@@ -88,6 +86,7 @@ import org.openmeetings.app.persistence.
import org.openmeetings.app.persistence.beans.user.Users;
import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
import org.openmeetings.app.sip.api.impl.asterisk.dao.AsteriskDAOImpl;
+import org.openmeetings.utils.OmFileHelper;
import org.openmeetings.utils.math.CalendarPatterns;
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
@@ -158,34 +157,22 @@ public class BackupImportController exte
USERS, ORGANISATIONS, APPOINTMENTS, ROOMS, MESSAGEFOLDERS, USERCONTACTS, FILEEXPLORERITEMS
};
- public void performImport(InputStream is, String current_dir) throws Exception {
- File working_dir = new File(current_dir, OpenmeetingsVariables.UPLOAD_DIR
- + File.separatorChar + "import");
+ public void performImport(InputStream is) throws Exception {
+ File working_dir = OmFileHelper.getUploadImportDir();
if (!working_dir.exists()) {
working_dir.mkdir();
}
- File f = new File(working_dir, "import_" + CalendarPatterns.getTimeForStreamId(new Date()));
-
- int recursiveNumber = 0;
- do {
- if (f.exists()) {
- f = new File(f.getAbsolutePath() + (recursiveNumber++));
- }
- } while (f.exists());
- f.mkdir();
+ File f = OmFileHelper.getNewDir(working_dir, "import_" + CalendarPatterns.getTimeForStreamId(new Date()));
log.debug("##### WRITE FILE TO: " + f);
ZipInputStream zipinputstream = new ZipInputStream(is);
- byte[] buf = new byte[1024];
ZipEntry zipentry = zipinputstream.getNextEntry();
while (zipentry != null) {
// for each entry to be extracted
- int n;
- FileOutputStream fileoutputstream;
File fentryName = new File(f, zipentry.getName());
if (zipentry.isDirectory()) {
@@ -228,13 +215,7 @@ public class BackupImportController exte
}
- fileoutputstream = new FileOutputStream(fentryName);
-
- while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
- fileoutputstream.write(buf, 0, n);
- }
-
- fileoutputstream.close();
+ FileHelper.copy(zipinputstream, fentryName);
zipinputstream.closeEntry();
zipentry = zipinputstream.getNextEntry();
@@ -452,11 +433,11 @@ public class BackupImportController exte
/*
* ##################### Import real files and folders
*/
- importFolders(current_dir, f);
+ importFolders(f);
log.info("File explorer item import complete, clearing temp files");
- deleteDirectory(f);
+ FileHelper.removeRec(f);
}
@RequestMapping(value = "/backup.upload", method = RequestMethod.POST)
@@ -466,10 +447,9 @@ public class BackupImportController exte
UploadInfo info = validate(request, true);
try {
- String current_dir = context.getRealPath("/");
MultipartFile multipartFile = info.file;
InputStream is = multipartFile.getInputStream();
- performImport(is, current_dir);
+ performImport(is);
LinkedHashMap<String, Object> hs = new LinkedHashMap<String, Object>();
hs.put("user", usersDao.getUser(info.userId));
@@ -835,67 +815,6 @@ public class BackupImportController exte
}
- public void copyDirectory(File sourceLocation, File targetLocation)
- throws IOException {
-
- // log.debug("^^^^ "+sourceLocation.getName()+" || "+targetLocation.getName());
-
- if (sourceLocation.isDirectory()) {
- if (!targetLocation.exists()) {
- targetLocation.mkdir();
- }
-
- String[] children = sourceLocation.list();
- for (int i = 0; i < children.length; i++) {
- copyDirectory(new File(sourceLocation, children[i]), new File(
- targetLocation, children[i]));
- }
- } else {
-
- InputStream in = new FileInputStream(sourceLocation);
- OutputStream out = new FileOutputStream(targetLocation);
-
- // Copy the bits from instream to outstream
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- in.close();
- out.close();
- }
- }
-
- public void copyFile(File sourceLocation, File targetLocation)
- throws IOException {
-
- InputStream in = new FileInputStream(sourceLocation);
- OutputStream out = new FileOutputStream(targetLocation);
-
- // Copy the bits from instream to outstream
- byte[] buf = new byte[1024];
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- in.close();
- out.close();
- }
-
- public boolean deleteDirectory(File path) throws IOException {
- if (path.exists()) {
- File[] files = path.listFiles();
- for (int i = 0; i < files.length; i++) {
- if (files[i].isDirectory()) {
- deleteDirectory(files[i]);
- } else {
- files[i].delete();
- }
- }
- }
- return (path.delete());
- }
-
private void importUsers(File userFile) throws Exception {
this.getUsersByXML(userFile);
@@ -2432,15 +2351,15 @@ public class BackupImportController exte
return null;
}
- private void importFolders(String current_dir, File importBaseDir)
+ private void importFolders(File importBaseDir)
throws IOException {
// Now check the room files and import them
File roomFilesFolder = new File(importBaseDir, "roomFiles");
- File library_dir = new File(current_dir, OpenmeetingsVariables.UPLOAD_DIR);
+ File library_dir = OmFileHelper.getUploadDir();
- log.debug("roomFilesFolder PATH " + roomFilesFolder.getAbsolutePath());
+ log.debug("roomFilesFolder PATH " + roomFilesFolder.getCanonicalPath());
if (roomFilesFolder.exists()) {
@@ -2462,12 +2381,12 @@ public class BackupImportController exte
String fileOrFolderName = roomOrProfileFileOrFolder
.getName();
int beginIndex = fileOrFolderName
- .indexOf(ScopeApplicationAdapter.profilesPrefix);
+ .indexOf(OmFileHelper.profilesPrefix);
// Profile folder should be renamed if new user id
// is differ from current id.
if (beginIndex > -1) {
beginIndex = beginIndex
- + ScopeApplicationAdapter.profilesPrefix
+ + OmFileHelper.profilesPrefix
.length();
Long profileId = importLongType(fileOrFolderName
.substring(beginIndex));
@@ -2476,9 +2395,9 @@ public class BackupImportController exte
if (profileId != newProfileID) {
fileOrFolderName = fileOrFolderName
.replaceFirst(
- ScopeApplicationAdapter.profilesPrefix
+ OmFileHelper.profilesPrefix
+ profileId,
- ScopeApplicationAdapter.profilesPrefix
+ OmFileHelper.profilesPrefix
+ newProfileID);
}
}
@@ -2491,13 +2410,10 @@ public class BackupImportController exte
.listFiles();
for (File roomDocumentFile : roomDocumentFiles) {
-
if (roomDocumentFile.isDirectory()) {
- log.error("Folder detected in Documents space! Folder "
- + roomDocumentFolder);
+ log.error("Folder detected in Documents space! Folder " + roomDocumentFolder);
} else {
- copyFile(roomDocumentFile,
- new File(roomDocumentFolder, roomDocumentFile.getName()));
+ FileHelper.copy(roomDocumentFile, new File(roomDocumentFolder, roomDocumentFile.getName()));
}
}
} else {
@@ -2507,8 +2423,7 @@ public class BackupImportController exte
} else {
File roomFileOrProfileFile = new File(parentPathFile, roomOrProfileFileOrFolder.getName());
if (!roomFileOrProfileFile.exists()) {
- this.copyFile(roomOrProfileFileOrFolder,
- roomFileOrProfileFile);
+ FileHelper.copy(roomOrProfileFileOrFolder, roomFileOrProfileFile);
} else {
log.debug("File does already exist :: ", roomFileOrProfileFile);
}
@@ -2522,17 +2437,13 @@ public class BackupImportController exte
File sourceDirRec = new File(importBaseDir, "recordingFiles");
- log.debug("sourceDirRec PATH " + sourceDirRec.getAbsolutePath());
+ log.debug("sourceDirRec PATH " + sourceDirRec.getCanonicalPath());
if (sourceDirRec.exists()) {
+ File targetDirRec = OmFileHelper.getStreamsHibernateDir();
- File targetDirRec = new File(current_dir, OpenmeetingsVariables.STREAMS_DIR
- + File.separatorChar + "hibernate" + File.separatorChar);
-
- copyDirectory(sourceDirRec, targetDirRec);
-
+ FileHelper.copyRec(sourceDirRec, targetDirRec);
}
-
}
private Integer importIntegerType(String value) {
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/DownloadHandler.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/DownloadHandler.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/DownloadHandler.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/DownloadHandler.java Mon Jul 2 05:10:03 2012
@@ -21,7 +21,6 @@ package org.openmeetings.servlet.outputh
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
-import java.io.RandomAccessFile;
import java.util.Date;
import javax.servlet.ServletException;
@@ -36,6 +35,7 @@ import org.openmeetings.app.data.file.da
import org.openmeetings.app.data.user.Usermanagement;
import org.openmeetings.app.persistence.beans.files.FileExplorerItem;
import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
+import org.openmeetings.utils.OmFileHelper;
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
import org.springframework.context.ApplicationContext;
@@ -92,8 +92,7 @@ public class DownloadHandler extends Htt
return null;
}
- private void logNonExistentFolder(String dir) {
- File f = new File(dir);
+ private void logNonExistentFolder(File f) {
if (!f.exists()) {
boolean c = f.mkdir();
if (!c) {
@@ -183,84 +182,37 @@ public class DownloadHandler extends Htt
// Get the current User-Directory
- String current_dir = getServletContext().getRealPath("/");
-
- String working_dir = "";
-
- working_dir = current_dir + OpenmeetingsVariables.UPLOAD_DIR + File.separatorChar;
+ File working_dir;
// Add the Folder for the Room
if (moduleName.equals("lzRecorderApp")) {
- working_dir = current_dir + OpenmeetingsVariables.STREAMS_DIR + File.separatorChar
- + "hibernate" + File.separatorChar;
+ working_dir = OmFileHelper.getStreamsHibernateDir();
} else if (moduleName.equals("videoconf1")) {
- if (parentPath.length() != 0) {
- if (parentPath.equals("/")) {
- working_dir = working_dir + roomName
- + File.separatorChar;
- } else {
- working_dir = working_dir + roomName
- + File.separatorChar + parentPath
- + File.separatorChar;
- }
- } else {
- working_dir = current_dir + roomName
- + File.separatorChar;
+ working_dir = OmFileHelper.getUploadRoomDir(roomName);
+ if (parentPath.length() != 0 && !parentPath.equals("/")) {
+ working_dir = new File(working_dir, parentPath);
}
} else if (moduleName.equals("userprofile")) {
- working_dir += "profiles" + File.separatorChar;
- logNonExistentFolder(working_dir);
-
- working_dir += ScopeApplicationAdapter.profilesPrefix
- + users_id + File.separatorChar;
+ working_dir = OmFileHelper.getUploadProfilesUserDir(users_id);
logNonExistentFolder(working_dir);
} else if (moduleName.equals("remoteuserprofile")) {
- working_dir += "profiles" + File.separatorChar;
- logNonExistentFolder(working_dir);
-
- String remoteUser_id = httpServletRequest
- .getParameter("remoteUserid");
- if (remoteUser_id == null) {
- remoteUser_id = "0";
- }
-
- working_dir += ScopeApplicationAdapter.profilesPrefix
- + remoteUser_id + File.separatorChar;
+ String remoteUser_id = httpServletRequest.getParameter("remoteUserid");
+ working_dir = OmFileHelper.getUploadProfilesUserDir(remoteUser_id == null ? "0" : remoteUser_id);
logNonExistentFolder(working_dir);
} else if (moduleName.equals("remoteuserprofilebig")) {
- working_dir += "profiles" + File.separatorChar;
- logNonExistentFolder(working_dir);
-
- String remoteUser_id = httpServletRequest
- .getParameter("remoteUserid");
- if (remoteUser_id == null) {
- remoteUser_id = "0";
- }
-
- working_dir += ScopeApplicationAdapter.profilesPrefix
- + remoteUser_id + File.separatorChar;
+ String remoteUser_id = httpServletRequest.getParameter("remoteUserid");
+ working_dir = OmFileHelper.getUploadProfilesUserDir(remoteUser_id == null ? "0" : remoteUser_id);
logNonExistentFolder(working_dir);
-
- requestedFile = this.getBigProfileUserName(working_dir);
-
+
+ requestedFile = getBigProfileUserName(working_dir);
} else if (moduleName.equals("chat")) {
-
- working_dir += "profiles" + File.separatorChar;
- logNonExistentFolder(working_dir);
-
- String remoteUser_id = httpServletRequest
- .getParameter("remoteUserid");
- if (remoteUser_id == null) {
- remoteUser_id = "0";
- }
-
- working_dir += ScopeApplicationAdapter.profilesPrefix
- + remoteUser_id + File.separatorChar;
+ String remoteUser_id = httpServletRequest.getParameter("remoteUserid");
+ working_dir = OmFileHelper.getUploadProfilesUserDir(remoteUser_id == null ? "0" : remoteUser_id);
logNonExistentFolder(working_dir);
- requestedFile = this.getChatUserName(working_dir);
+ requestedFile = getChatUserName(working_dir);
} else {
- working_dir = working_dir + roomName + File.separatorChar;
+ working_dir = OmFileHelper.getUploadRoomDir(roomName);
}
if (!moduleName.equals("nomodule")) {
@@ -268,15 +220,13 @@ public class DownloadHandler extends Htt
log.debug("requestedFile: " + requestedFile
+ " current_dir: " + working_dir);
- String full_path = working_dir + requestedFile;
-
- File f = new File(full_path);
+ File full_path = new File(working_dir, requestedFile);
// If the File does not exist or is not readable show/load a
// place-holder picture
- if (!f.exists() || !f.canRead()) {
- if (!f.canRead()) {
+ if (!full_path.exists() || !full_path.canRead()) {
+ if (!full_path.canRead()) {
log.debug("LOG DownloadHandler: The request file is not readable");
} else {
log.debug("LOG DownloadHandler: The request file does not exist / has already been deleted");
@@ -292,38 +242,25 @@ public class DownloadHandler extends Htt
requestedFile = DownloadHandler.defaultImageName;
if (moduleName.equals("remoteuserprofile")) {
requestedFile = DownloadHandler.defaultProfileImageName;
- } else if (moduleName
- .equals("remoteuserprofilebig")) {
+ } else if (moduleName.equals("remoteuserprofilebig")) {
requestedFile = DownloadHandler.defaultProfileImageNameBig;
} else if (moduleName.equals("userprofile")) {
requestedFile = DownloadHandler.defaultProfileImageName;
} else if (moduleName.equals("chat")) {
requestedFile = DownloadHandler.defaultChatImageName;
}
- // request for an image
- full_path = current_dir + "default"
- + File.separatorChar + requestedFile;
} else if (requestedFile.endsWith(".swf")) {
requestedFile = DownloadHandler.defaultSWFName;
- // request for a SWFPresentation
- full_path = current_dir + "default"
- + File.separatorChar
- + DownloadHandler.defaultSWFName;
} else {
- // Any document, must be a download request
- // OR a Moodle Loggedin User
requestedFile = DownloadHandler.defaultImageName;
- full_path = current_dir + "default"
- + File.separatorChar
- + DownloadHandler.defaultImageName;
}
+ full_path = new File(OmFileHelper.getDefaultDir(), DownloadHandler.defaultSWFName);
}
log.debug("full_path: " + full_path);
- File f2 = new File(full_path);
- if (!f2.exists() || !f2.canRead()) {
- if (!f2.canRead()) {
+ if (!full_path.exists() || !full_path.canRead()) {
+ if (!full_path.canRead()) {
log.debug("DownloadHandler: The request DEFAULT-file does not exist / has already been deleted");
} else {
log.debug("DownloadHandler: The request DEFAULT-file does not exist / has already been deleted");
@@ -332,17 +269,14 @@ public class DownloadHandler extends Htt
return;
}
// Requested file is outside OM webapp folder
- File curDirFile = new File(current_dir);
- if (!f2.getCanonicalPath()
+ File curDirFile = OmFileHelper.getOmHome();
+ if (!full_path.getCanonicalPath()
.startsWith(curDirFile.getCanonicalPath())) {
throw new Exception("Invalid file requested: f2.cp == "
- + f2.getCanonicalPath() + "; curDir.cp == "
+ + full_path.getCanonicalPath() + "; curDir.cp == "
+ curDirFile.getCanonicalPath());
}
- // Get file and handle download
- RandomAccessFile rf = new RandomAccessFile(full_path, "r");
-
// Default type - Explorer, Chrome and others
int browserType = 0;
@@ -370,7 +304,7 @@ public class DownloadHandler extends Htt
httpServletResponse
.setContentType("application/x-shockwave-flash");
httpServletResponse.setHeader("Content-Length",
- "" + rf.length());
+ "" + full_path.length());
} else {
httpServletResponse
.setContentType("APPLICATION/OCTET-STREAM");
@@ -401,21 +335,12 @@ public class DownloadHandler extends Htt
}
httpServletResponse.setHeader("Content-Length",
- "" + rf.length());
+ "" + full_path.length());
}
- byte[] buffer = new byte[1024];
- int readed = -1;
-
- while ((readed = rf.read(buffer, 0, buffer.length)) > -1) {
- out.write(buffer, 0, readed);
- }
-
- rf.close();
-
+ OmFileHelper.copyFile(full_path, out);
out.flush();
out.close();
-
}
} else {
System.out
@@ -429,9 +354,7 @@ public class DownloadHandler extends Htt
}
}
- private String getChatUserName(String userprofile_folder) throws Exception {
-
- File f = new File(userprofile_folder);
+ private String getChatUserName(File f) throws Exception {
if (f.exists() && f.isDirectory()) {
String filesString[] = f.list();
for (int i = 0; i < filesString.length; i++) {
@@ -443,10 +366,7 @@ public class DownloadHandler extends Htt
return "_no.jpg";
}
- private String getBigProfileUserName(String userprofile_folder)
- throws Exception {
-
- File f = new File(userprofile_folder);
+ private String getBigProfileUserName(File f) throws Exception {
if (f.exists() && f.isDirectory()) {
String filesString[] = f.list();
for (int i = 0; i < filesString.length; i++) {
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/ExportToImage.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/ExportToImage.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/ExportToImage.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/ExportToImage.java Mon Jul 2 05:10:03 2012
@@ -22,7 +22,6 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
-import java.io.RandomAccessFile;
import java.io.Writer;
import java.util.Date;
import java.util.List;
@@ -43,6 +42,7 @@ import org.openmeetings.app.data.user.Us
import org.openmeetings.app.documents.GenerateImage;
import org.openmeetings.app.remote.PrintService;
import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
+import org.openmeetings.utils.OmFileHelper;
import org.openmeetings.utils.math.CalendarPatterns;
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
@@ -195,9 +195,7 @@ public class ExportToImage extends HttpS
|| exportType.equals("gif") || exportType.equals("tif")
|| exportType.equals("pdf")) {
- String current_dir = getServletContext().getRealPath("/");
- String working_dir = current_dir + OpenmeetingsVariables.UPLOAD_TEMP_DIR
- + File.separatorChar;
+ File uploadTempDir = OmFileHelper.getUploadTempDir();
String requestedFileSVG = fileName + "_"
+ CalendarPatterns.getTimeForStreamId(new Date())
@@ -206,26 +204,21 @@ public class ExportToImage extends HttpS
+ CalendarPatterns.getTimeForStreamId(new Date())
+ "." + exportType;
- log.debug("current_dir: " + current_dir);
- log.debug("working_dir: " + working_dir);
+ log.debug("working_dir: " + uploadTempDir);
log.debug("requestedFileSVG: " + requestedFileSVG);
log.debug("resultFileName: " + resultFileName);
- File svgFile = new File(working_dir + requestedFileSVG);
- File resultFile = new File(working_dir + resultFileName);
+ File svgFile = new File(uploadTempDir, requestedFileSVG);
+ File resultFile = new File(uploadTempDir, resultFileName);
- log.debug("svgFile: " + svgFile.getAbsolutePath());
- log.debug("resultFile: " + resultFile.getAbsolutePath());
+ log.debug("svgFile: " + svgFile.getCanonicalPath());
+ log.debug("resultFile: " + resultFile.getCanonicalPath());
log.debug("svgFile P: " + svgFile.getPath());
log.debug("resultFile P: " + resultFile.getPath());
FileWriter out = new FileWriter(svgFile);
svgGenerator.stream(out, useCSS);
- // Get file and handle download
- RandomAccessFile rf = new RandomAccessFile(
- resultFile.getAbsoluteFile(), "r");
-
httpServletResponse.reset();
httpServletResponse.resetBuffer();
OutputStream outStream = httpServletResponse
@@ -235,16 +228,10 @@ public class ExportToImage extends HttpS
httpServletResponse.setHeader("Content-Disposition",
"attachment; filename=\"" + resultFileName + "\"");
httpServletResponse.setHeader("Content-Length",
- "" + rf.length());
-
- byte[] buffer = new byte[1024];
- int readed = -1;
+ "" + resultFile.length());
- while ((readed = rf.read(buffer, 0, buffer.length)) > -1) {
- outStream.write(buffer, 0, readed);
- }
+ OmFileHelper.copyFile(resultFile, outStream);
outStream.close();
- rf.close();
out.flush();
out.close();
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/Install.java Mon Jul 2 05:10:03 2012
@@ -37,6 +37,7 @@ import org.openmeetings.app.installation
import org.openmeetings.app.installation.InstallationConfig;
import org.openmeetings.app.persistence.beans.basic.OmTimeZone;
import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
+import org.openmeetings.utils.OmFileHelper;
import org.openmeetings.utils.ImportHelper;
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
@@ -82,10 +83,8 @@ public class Install extends VelocityVie
String[] headerList = header != null ? header.split(",") : new String[0];
String headCode = headerList.length > 0 ? headerList[0] : "en";
- String filePath = getServletContext().getRealPath("/")
- + ImportInitvalues.languageFolderName;
LinkedHashMap<Integer, LinkedHashMap<String, Object>> allLanguagesAll = getImportInitvalues()
- .getLanguageFiles(filePath);
+ .getLanguageFiles();
LinkedHashMap<Integer, String> allLanguages = new LinkedHashMap<Integer, String>();
//first iteration for preferred language
Integer prefKey = -1;
@@ -118,7 +117,7 @@ public class Install extends VelocityVie
allFonts.put("Arial", "Arial");
List<OmTimeZone> omTimeZoneList = getImportInitvalues()
- .getTimeZones(filePath);
+ .getTimeZones();
Template tpl = super.getTemplate("install_step1_"
+ lang + ".vm");
@@ -157,37 +156,24 @@ public class Install extends VelocityVie
if (lang == null)
lang = "EN";
- String working_dir = getServletContext().getRealPath("/")
- + ScopeApplicationAdapter.configDirName
- + File.separatorChar;
-
- File installerFile = new File(working_dir, InstallationDocumentHandler.installFileName);
+ File installerFile = OmFileHelper.getInstallFile();
if (command == null || !installerFile.exists()) {
log.debug("command equals null");
if (!installerFile.exists()) {
-
- File installerdir = new File(working_dir);
-
- log.debug("bb " + installerFile);
-
- boolean b = installerdir.canWrite();
+ File confDir = OmFileHelper.getConfDir();
+ boolean b = confDir.canWrite();
if (!b) {
// File could not be created so throw an error
ctx.put("error",
"Could not Create File, Permission set? ");
- ctx.put("path", working_dir);
+ ctx.put("path", confDir.getCanonicalPath());
return getVelocityView().getVelocityEngine()
.getTemplate("install_error_" + lang + ".vm");
} else {
- InstallationDocumentHandler
- .getInstance()
- .createDocument(
- working_dir
- + InstallationDocumentHandler.installFileName,
- 0);
+ InstallationDocumentHandler.createDocument(0);
// File has been created so follow first step of
// Installation
return getVelocityView().getVelocityEngine()
@@ -195,8 +181,7 @@ public class Install extends VelocityVie
}
} else {
- int i = InstallationDocumentHandler.getInstance()
- .getCurrentStepNumber(working_dir);
+ int i = InstallationDocumentHandler.getCurrentStepNumber();
if (i == 0) {
return getStep2Template(httpServletRequest, ctx, lang);
} else {
@@ -207,8 +192,7 @@ public class Install extends VelocityVie
} else if (command.equals("step1")) {
- int i = InstallationDocumentHandler.getInstance()
- .getCurrentStepNumber(working_dir);
+ int i = InstallationDocumentHandler.getCurrentStepNumber();
if (i == 0) {
return getStep2Template(httpServletRequest, ctx, lang);
} else {
@@ -220,8 +204,7 @@ public class Install extends VelocityVie
} else if (command.equals("step2")) {
- int i = InstallationDocumentHandler.getInstance()
- .getCurrentStepNumber(working_dir);
+ int i = InstallationDocumentHandler.getCurrentStepNumber();
if (i == 0) {
log.debug("do init installation");
@@ -298,25 +281,17 @@ public class Install extends VelocityVie
+ " ***** " + useremail + " " + orgname + " "
+ cfg);
- String filePath = getServletContext().getRealPath("/")
- + ImportInitvalues.languageFolderName;
-
cfg.urlFeed = getServletContext().getInitParameter(
"url_feed");
cfg.urlFeed2 = getServletContext().getInitParameter(
"url_feed2");
- getImportInitvalues().loadAll(filePath, cfg, username,
+ getImportInitvalues().loadAll(cfg, username,
userpass, useremail, orgname, timeZone, false);
// update to next step
log.debug("add level to install file");
- InstallationDocumentHandler
- .getInstance()
- .createDocument(
- working_dir
- + InstallationDocumentHandler.installFileName,
- 1);
+ InstallationDocumentHandler.createDocument(1);
// return
// getVelocityEngine().getTemplate("install_complete_"+lang+".vm");
@@ -331,8 +306,7 @@ public class Install extends VelocityVie
} else if (command.equals("step")) {
- int i = InstallationDocumentHandler.getInstance()
- .getCurrentStepNumber(working_dir);
+ int i = InstallationDocumentHandler.getCurrentStepNumber();
if (i == 0) {
}
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/NetworkTestingController.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/NetworkTestingController.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/NetworkTestingController.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/NetworkTestingController.java Mon Jul 2 05:10:03 2012
@@ -18,8 +18,9 @@
*/
package org.openmeetings.servlet.outputhandler;
+import java.io.IOException;
+
import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@@ -28,8 +29,6 @@ import org.springframework.stereotype.Co
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import java.io.IOException;
-
@Controller
public class NetworkTestingController {
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/ScreenRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/ScreenRequestHandler.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/ScreenRequestHandler.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/ScreenRequestHandler.java Mon Jul 2 05:10:03 2012
@@ -38,6 +38,7 @@ import org.openmeetings.app.data.basic.F
import org.openmeetings.app.data.basic.Sessionmanagement;
import org.openmeetings.app.persistence.beans.basic.Configuration;
import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
+import org.openmeetings.utils.OmFileHelper;
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
import org.springframework.context.ApplicationContext;
@@ -232,10 +233,9 @@ public class ScreenRequestHandler extend
log.debug("Creating JNLP Template for TCP solution");
try {
- final String screenShareDirName = "screensharing";
//libs
StringBuilder libs = new StringBuilder();
- File screenShareDir = new File(ScopeApplicationAdapter.webAppPath, screenShareDirName);
+ File screenShareDir = OmFileHelper.getScreenSharingDir();
for (File jar : screenShareDir.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.getName().endsWith(".jar");
@@ -247,7 +247,7 @@ public class ScreenRequestHandler extend
ctx.put("LIBRARIES", libs);
log.debug("RTMP Sharer labels :: " + label_sharer);
- codebase = baseURL + screenShareDirName;
+ codebase = baseURL + OmFileHelper.SCREENSHARING_DIR;
ConnectionType conType = ConnectionType
.valueOf(httpServletRequest
@@ -333,9 +333,7 @@ public class ScreenRequestHandler extend
StringBuilder sb = new StringBuilder();
FileInputStream fis = null;
try {
- //FIXME hack !!!!
- File root = new File(ScopeApplicationAdapter.webAppPath).getParentFile().getParentFile();
- File conf = new File(root, "conf");
+ File conf = new File(OmFileHelper.getRootDir(), "conf");
File keyStore = new File(conf, "keystore.screen");
if (keyStore.exists()) {
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/UploadController.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/UploadController.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/UploadController.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/servlet/outputhandler/UploadController.java Mon Jul 2 05:10:03 2012
@@ -19,7 +19,6 @@
package org.openmeetings.servlet.outputhandler;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -31,6 +30,7 @@ import javax.servlet.http.HttpServletRes
import javax.servlet.http.HttpSession;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.transaction.util.FileHelper;
import org.openmeetings.app.OpenmeetingsVariables;
import org.openmeetings.app.data.file.FileProcessor;
import org.openmeetings.app.data.file.dao.FileExplorerItemDaoImpl;
@@ -40,6 +40,7 @@ import org.openmeetings.app.documents.Ge
import org.openmeetings.app.documents.GenerateThumbs;
import org.openmeetings.app.persistence.beans.user.Users;
import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
+import org.openmeetings.utils.OmFileHelper;
import org.openmeetings.utils.StoredFile;
import org.openmeetings.utils.stringhandlers.StringComparer;
import org.red5.logging.Red5LoggerFactory;
@@ -100,15 +101,13 @@ public class UploadController extends Ab
}
Long parentFolderId = Long.parseLong(parentFolderIdAsString);
- String current_dir = context.getRealPath("/");
-
MultipartFile multipartFile = info.file;
InputStream is = multipartFile.getInputStream();
log.debug("fileSystemName: " + info.filename);
HashMap<String, HashMap<String, String>> returnError = fileProcessor
.processFile(info.userId, room_id_to_Store, isOwner, is,
- parentFolderId, info.filename, current_dir, hs, 0L, ""); // externalFilesId,
+ parentFolderId, info.filename, hs, 0L, ""); // externalFilesId,
// externalType
HashMap<String, String> returnAttributes = returnError
@@ -187,17 +186,6 @@ public class UploadController extends Ab
throws Exception {
HashMap<String, HashMap<String, String>> returnError = new HashMap<String, HashMap<String, String>>();
- // Get the current user directory
- String currentDir = context.getRealPath("/");
- String workingDir = currentDir + OpenmeetingsVariables.UPLOAD_DIR + File.separatorChar
- + roomName + File.separatorChar;
- log.debug("workingDir: " + workingDir);
-
- File localFolder = new File(workingDir);
- if (!localFolder.exists()) {
- localFolder.mkdirs();
- }
-
// Check variable to see if this file is a presentation
int dotidx = fileSystemName.lastIndexOf('.');
String newFileName = StringComparer.getInstance().compareForRealPaths(
@@ -220,95 +208,38 @@ public class UploadController extends Ab
boolean isImage = storedFile.isImage();
boolean isAsIs = storedFile.isAsIs();
- String completeName = "";
-
+ File workingDir = null;
// add outputfolders for profiles
if (userProfile) {
// User Profile Update
- this.deleteUserProfileFilesStoreTemp(currentDir, userId);
+ this.deleteUserProfileFilesStoreTemp(userId);
- completeName = currentDir + OpenmeetingsVariables.UPLOAD_DIR + File.separatorChar
- + "profiles" + File.separatorChar;
- File f = new File(completeName);
- if (!f.exists()) {
- boolean c = f.mkdir();
- if (!c) {
- log.error("cannot write to directory");
- // System.out.println("cannot write to directory");
- }
- }
- completeName += ScopeApplicationAdapter.profilesPrefix + userId
- + File.separatorChar;
- File f2 = new File(completeName);
- if (!f2.exists()) {
- boolean c = f2.mkdir();
- if (!c) {
- log.error("cannot write to directory");
- // System.out.println("cannot write to directory");
- }
- }
+ workingDir = OmFileHelper.getUploadProfilesUserDir(userId);
}
// if it is a presenation it will be copied to another
// place
if (isAsIs) {
// check if this is a room file or UserProfile
- if (userProfile) {
- completeName += newFileName;
- } else {
- completeName = workingDir + newFileName;
+ if (!userProfile) {
+ workingDir = OmFileHelper.getUploadRoomDir(roomName);
}
} else if (canBeConverted || isPdf || isImage) {
- // check if this is a room file or UserProfile
- // add Temp folder structure
- String workingDirPpt = currentDir
- + OpenmeetingsVariables.UPLOAD_TEMP_DIR
- + File.separatorChar
- + ((userProfile) ? "profiles" + File.separatorChar
- + ScopeApplicationAdapter.profilesPrefix + userId
- : roomName) + File.separatorChar;
- localFolder = new File(workingDirPpt);
- if (!localFolder.exists()) {
- localFolder.mkdirs();
- }
- completeName = workingDirPpt + newFileName;
+ workingDir = OmFileHelper.getUploadTempProfilesUserDir(userId);
} else {
return;
}
- File f = new File(completeName + newFileExtDot);
- if (f.exists()) {
- int recursiveNumber = 0;
- String tempd = completeName + "_" + recursiveNumber;
- while (f.exists()) {
- recursiveNumber++;
- tempd = completeName + "_" + recursiveNumber;
- f = new File(tempd + newFileExtDot);
-
- }
- completeName = tempd;
- }
-
- log.debug("write file to : " + completeName + newFileExtDot);
+ File completeName = OmFileHelper.getNewFile(workingDir, newFileName, newFileExtDot);
- FileOutputStream fos = new FileOutputStream(completeName
- + newFileExtDot);
- byte[] buffer = new byte[1024];
- int len = 0;
-
- while (len != (-1)) {
- len = is.read(buffer, 0, 1024);
- if (len != (-1))
- fos.write(buffer, 0, len);
- }
+ log.debug("write file to : " + completeName);
- fos.close();
+ FileHelper.copy(is, completeName);
is.close();
log.debug("canBeConverted: " + canBeConverted);
if (canBeConverted) {
// convert to pdf, thumbs, swf and xml-description
- returnError = generatePDF.convertPDF(currentDir, newFileName,
- newFileExtDot, roomName, true, completeName);
+ returnError = generatePDF.convertPDF(newFileName, roomName, true, completeName);
} else if (isPdf) {
boolean isEncrypted = true;
@@ -317,16 +248,13 @@ public class UploadController extends Ab
if (isEncrypted) {
// Do convert pdf to other pdf first
- String inputfile = completeName + newFileExtDot;
-
- completeName = completeName + "_N_E";
- newFileName = newFileName + "_N_E";
+ File f_old = completeName;
- String outputfile = completeName + newFileExtDot;
+ completeName = OmFileHelper.appendSuffix(completeName, "_N_E");
+ newFileName += "_N_E";
- generateThumbs.decodePDF(inputfile, outputfile);
+ generateThumbs.decodePDF(f_old.getCanonicalPath(), completeName.getCanonicalPath());
- File f_old = new File(inputfile);
if (f_old.exists()) {
f_old.delete();
}
@@ -334,8 +262,7 @@ public class UploadController extends Ab
}
// convert to thumbs, swf and xml-description
- returnError = generatePDF.convertPDF(currentDir, newFileName,
- newFileExtDot, roomName, false, completeName);
+ returnError = generatePDF.convertPDF(newFileName, roomName, false, completeName);
// returnError.put("decodePDF", returnError2);
@@ -345,36 +272,29 @@ public class UploadController extends Ab
if (userProfile) {
// User Profile Update
- this.deleteUserProfileFiles(currentDir, userId);
+ this.deleteUserProfileFiles(userId);
// convert it to JPG
returnError = generateImage.convertImageUserProfile(
- currentDir, newFileName, newFileExtDot, userId,
- newFileName, false);
+ newFileName, newFileExtDot, userId, newFileName, false);
} else {
// convert it to JPG
log.debug("##### convert it to JPG: " + userProfile);
- returnError = generateImage.convertImage(currentDir,
- newFileName, newFileExtDot, roomName, newFileName,
- false);
+ returnError = generateImage.convertImage(
+ newFileName, newFileExtDot, roomName, newFileName, false);
}
} else if (isAsIs) {
if (userProfile) {
// User Profile Update
- this.deleteUserProfileFiles(currentDir, userId);
+ this.deleteUserProfileFiles(userId);
// is UserProfile Picture
- HashMap<String, String> processThumb1 = generateThumbs
- .generateThumb("_chat_", currentDir, completeName, 40);
- HashMap<String, String> processThumb2 = generateThumbs
- .generateThumb("_profile_", currentDir, completeName,
- 126);
- HashMap<String, String> processThumb3 = generateThumbs
- .generateThumb("_big_", currentDir, completeName, 240);
- returnError.put("processThumb1", processThumb1);
- returnError.put("processThumb2", processThumb2);
- returnError.put("processThumb3", processThumb3);
+ returnError.put("processThumb1", generateThumbs
+ .generateThumb("_chat_", completeName, 40));
+ returnError.put("processThumb2", generateThumbs
+ .generateThumb("_profile_", completeName, 126));
+ returnError.put("processThumb3", generateThumbs
+ .generateThumb("_big_", completeName, 240));
- File fileNameToStore = new File(completeName + ".jpg");
- String pictureuri = fileNameToStore.getName();
+ String pictureuri = completeName.getName();
Users us = usersDao.getUser(userId);
us.setUpdatetime(new java.util.Date());
us.setPictureuri(pictureuri);
@@ -383,7 +303,7 @@ public class UploadController extends Ab
//FIXME: After updating the picture url all other users should refresh
} else {
HashMap<String, String> processThumb = generateThumbs
- .generateThumb("_thumb_", currentDir, completeName, 50);
+ .generateThumb("_thumb_", completeName, 50);
returnError.put("processThumb", processThumb);
}
}
@@ -391,33 +311,22 @@ public class UploadController extends Ab
hs.put("message", "library");
hs.put("action", "newFile");
hs.put("error", returnError);
- hs.put("fileName", completeName);
+ hs.put("fileName", completeName.getName());
}
- private void deleteUserProfileFilesStoreTemp(String current_dir,
- Long users_id) throws Exception {
-
- String working_imgdir = current_dir + OpenmeetingsVariables.UPLOAD_DIR + File.separatorChar
- + "profiles" + File.separatorChar
- + ScopeApplicationAdapter.profilesPrefix + users_id
- + File.separatorChar;
- File f = new File(working_imgdir);
+ private void deleteUserProfileFilesStoreTemp(Long users_id) throws Exception {
+ File f = OmFileHelper.getUploadProfilesUserDir(users_id);
if (f.exists() && f.isDirectory()) {
this.filesString = f.list();
}
}
- private void deleteUserProfileFiles(String current_dir, Long users_id)
- throws Exception {
-
- String working_imgdir = current_dir + OpenmeetingsVariables.UPLOAD_DIR + File.separatorChar
- + "profiles" + File.separatorChar
- + ScopeApplicationAdapter.profilesPrefix + users_id
- + File.separatorChar;
+ private void deleteUserProfileFiles(Long users_id) throws Exception {
+ File working_imgdir = OmFileHelper.getUploadProfilesUserDir(users_id);
for (int i = 0; i < this.filesString.length; i++) {
String fileName = filesString[i];
- File subf = new File(working_imgdir + fileName);
+ File subf = new File(working_imgdir, fileName);
subf.delete();
}
}
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/AbstractOpenmeetingsSpringTest.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/AbstractOpenmeetingsSpringTest.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/AbstractOpenmeetingsSpringTest.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/AbstractOpenmeetingsSpringTest.java Mon Jul 2 05:10:03 2012
@@ -21,7 +21,6 @@ package org.openmeetings.test;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
-import java.io.File;
import java.util.Date;
import org.junit.Before;
@@ -33,7 +32,6 @@ import org.openmeetings.app.installation
import org.openmeetings.app.installation.InstallationConfig;
import org.openmeetings.app.persistence.beans.calendar.Appointment;
import org.openmeetings.app.persistence.beans.user.Users;
-import org.openmeetings.app.remote.red5.ScopeApplicationAdapter;
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -126,11 +124,7 @@ public abstract class AbstractOpenmeetin
}
private void makeDefaultScheme() throws Exception {
- String filePath = System.getProperty("webapps.root")
- + File.separatorChar + ScopeApplicationAdapter.webAppPath
- + ImportInitvalues.languageFolderName;
-
- importInitvalues.loadAll(filePath, new InstallationConfig(), username, userpass,
+ importInitvalues.loadAll(new InstallationConfig(), username, userpass,
useremail, orgname, timeZone, false);
}
}
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/asf/AsfCopyRightReplace.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/asf/AsfCopyRightReplace.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/asf/AsfCopyRightReplace.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/asf/AsfCopyRightReplace.java Mon Jul 2 05:10:03 2012
@@ -115,9 +115,7 @@ public class AsfCopyRightReplace {
for (File folderFile : folder.listFiles(new FilenameFilter() {
public boolean accept(File b, String name) {
- String absPath = b.getAbsolutePath() + File.separatorChar
- + name;
- File f = new File(absPath);
+ File f = new File(b, name);
return f.isDirectory();
}
})) {
@@ -127,7 +125,7 @@ public class AsfCopyRightReplace {
private void scanAndWriteXMLFile(File javaFile) {
try {
- System.out.println("Processing " + javaFile.getAbsolutePath());
+ System.out.println("Processing " + javaFile.getCanonicalPath());
BufferedReader is = new BufferedReader(new InputStreamReader(
new FileInputStream(javaFile), "UTF-8"));
@@ -166,7 +164,7 @@ public class AsfCopyRightReplace {
is.close();
OutputStreamWriter out = new OutputStreamWriter(
- new FileOutputStream(javaFile.getAbsolutePath()), "UTF-8");
+ new FileOutputStream(javaFile.getCanonicalPath()), "UTF-8");
out.write(strWriter.toString());
out.flush();
@@ -179,7 +177,7 @@ public class AsfCopyRightReplace {
private void scanAndWriteJavaFile(File javaFile) {
try {
- System.out.println("Processing " + javaFile.getAbsolutePath());
+ System.out.println("Processing " + javaFile.getCanonicalPath());
BufferedReader is = new BufferedReader(new InputStreamReader(
new FileInputStream(javaFile), "UTF-8"));
@@ -203,7 +201,7 @@ public class AsfCopyRightReplace {
is.close();
OutputStreamWriter out = new OutputStreamWriter(
- new FileOutputStream(javaFile.getAbsolutePath()), "UTF-8");
+ new FileOutputStream(javaFile.getCanonicalPath()), "UTF-8");
out.write(strWriter.toString());
out.flush();
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/library/TestFileParser.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/library/TestFileParser.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/library/TestFileParser.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/test/library/TestFileParser.java Mon Jul 2 05:10:03 2012
@@ -18,6 +18,8 @@
*/
package org.openmeetings.test.library;
+import java.io.File;
+
import org.apache.log4j.Logger;
import org.junit.Test;
import org.openmeetings.app.documents.LibraryWmlLoader;
@@ -36,7 +38,7 @@ public class TestFileParser extends Abst
try {
- libraryWmlLoader.loadWmlFile(System.getProperty("basedir") + "/", "filename1");
+ libraryWmlLoader.loadWmlFile(new File(System.getProperty("basedir")), "filename1");
} catch (Exception err) {
Added: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/OmFileHelper.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/OmFileHelper.java?rev=1356068&view=auto
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/OmFileHelper.java (added)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/OmFileHelper.java Mon Jul 2 05:10:03 2012
@@ -0,0 +1,260 @@
+package org.openmeetings.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.DecimalFormat;
+
+import org.apache.commons.transaction.util.FileHelper;
+import org.openmeetings.app.OpenmeetingsVariables;
+import org.red5.logging.Red5LoggerFactory;
+import org.slf4j.Logger;
+
+public class OmFileHelper {
+ private static final Logger log = Red5LoggerFactory.getLogger(OmFileHelper.class, OpenmeetingsVariables.webAppRootKey);
+
+ private static File OM_HOME = null;
+ private static final String UPLOAD_DIR = "upload";
+ private static final String UPLOAD_TEMP_DIR = "uploadtemp";
+ private static final String FILES_DIR = "files";
+ private static final String PUBLIC_DIR = "public";
+ private static final String CLIPARTS_DIR = "cliparts";
+ private static final String WEB_INF_DIR = "WEB-INF";
+ private static final String PROFILES_DIR = "profiles";
+ private static final String STREAMS_DIR = "streams";
+ private static final String EMOTIONS_DIR = "emoticons";
+ private static final String LANGUAGES_DIR = "languages";
+ private static final String IMPORT_DIR = "import";
+ private static final String HIBERNATE_DIR = "hibernate";
+ private static final String CONF_DIR = "conf";
+ private static final String BACKUP_DIR = "backup";
+ private static final String DEFAULT_DIR = "default";
+
+ private static final String INSTALL_FILE = "install.xml";
+
+ public static final String SCREENSHARING_DIR = "screensharing";
+
+ public static final String profilesPrefix = "profile_";
+ public static final String nameOfLanguageFile = "languages.xml";
+ public static final String nameOfCountriesFile = "countries.xml";
+ public static final String nameOfTimeZoneFile = "timezones.xml";
+ public static final String nameOfErrorFile = "errorvalues.xml";
+ public static final String libraryFileName = "library.xml";
+
+ public static void setOmHome(File omHome) {
+ OmFileHelper.OM_HOME = omHome;
+ }
+
+ public static void setOmHome(String omHome) {
+ OmFileHelper.OM_HOME = new File(omHome);
+ }
+
+ public static File getRootDir() {
+ //FIXME hack !!!!
+ return getOmHome().getParentFile().getParentFile();
+ }
+
+ public static File getOmHome() {
+ return OmFileHelper.OM_HOME;
+ }
+
+ private static File getDir(File parent, String name) {
+ File f = new File(parent, name);
+ if (!f.exists()) {
+ f.mkdir();
+ }
+ return f;
+ }
+
+ public static File getUploadDir() {
+ return new File(OmFileHelper.OM_HOME, UPLOAD_DIR);
+ }
+
+ public static File getUploadFilesDir() {
+ return getDir(getUploadDir(), FILES_DIR);
+ }
+
+ public static File getUploadProfilesDir() {
+ return getDir(getUploadDir(), PROFILES_DIR);
+ }
+
+ public static File getUploadProfilesUserDir(Long users_id) {
+ return getDir(getUploadProfilesDir(), OmFileHelper.profilesPrefix + users_id);
+ }
+
+ public static File getUploadProfilesUserDir(String users_id) {
+ return getDir(getUploadProfilesDir(), OmFileHelper.profilesPrefix + users_id);
+ }
+
+ public static File getUploadImportDir() {
+ return getDir(getUploadDir(), IMPORT_DIR);
+ }
+
+ public static File getUploadBackupDir() {
+ return getDir(getUploadDir(), BACKUP_DIR);
+ }
+
+ public static File getUploadRoomDir(String roomName) {
+ return getDir(getUploadDir(), roomName);
+ }
+
+ public static File getUploadTempDir() {
+ return new File(OmFileHelper.OM_HOME, UPLOAD_TEMP_DIR);
+ }
+
+ public static File getUploadTempFilesDir() {
+ return getDir(getUploadTempDir(), FILES_DIR);
+ }
+
+ public static File getUploadTempProfilesDir() {
+ return getDir(getUploadTempDir(), PROFILES_DIR);
+ }
+
+ public static File getUploadTempProfilesUserDir(Long users_id) {
+ return getDir(getUploadTempProfilesDir(), OmFileHelper.profilesPrefix + users_id);
+ }
+
+ public static File getUploadTempRoomDir(String roomName) {
+ return getDir(getUploadTempDir(), roomName);
+ }
+
+ public static File getStreamsDir() {
+ return new File(OmFileHelper.OM_HOME, STREAMS_DIR);
+ }
+
+ public static File getStreamsFilesDir() {
+ return getDir(getStreamsDir(), FILES_DIR);
+ }
+
+ public static File getStreamsHibernateDir() {
+ return getDir(getStreamsDir(), HIBERNATE_DIR);
+ }
+
+ public static File getStreamsSubDir(Long id) {
+ return getDir(getStreamsDir(), id.toString());
+ }
+
+ public static File getStreamsSubDir(String name) {
+ return getDir(getStreamsDir(), name);
+ }
+
+ public static File getLanguagesDir() {
+ return new File(OmFileHelper.OM_HOME, LANGUAGES_DIR);
+ }
+
+ public static File getPublicDir() {
+ return new File(OmFileHelper.OM_HOME, PUBLIC_DIR);
+ }
+
+ public static File getPublicClipartsDir() {
+ return new File(getPublicDir(), CLIPARTS_DIR);
+ }
+
+ public static File getPublicEmotionsDir() {
+ return new File(getPublicDir(), EMOTIONS_DIR);
+ }
+
+ public static File getWebinfDir() {
+ return new File(OmFileHelper.OM_HOME, WEB_INF_DIR);
+ }
+
+ public static File getConfDir() {
+ return new File(OmFileHelper.OM_HOME, CONF_DIR);
+ }
+
+ public static File getInstallFile() {
+ return new File(getConfDir(), INSTALL_FILE);
+ }
+
+ public static File getScreenSharingDir() {
+ return new File(OmFileHelper.OM_HOME, SCREENSHARING_DIR);
+ }
+
+ public static File getDefaultDir() {
+ return new File(OmFileHelper.OM_HOME, DEFAULT_DIR);
+ }
+
+ public static File appendSuffix(File original, String suffix) {
+ File parent = original.getParentFile();
+ String name = original.getName();
+ String ext = "";
+ int idx = name.lastIndexOf('.');
+ if (idx > -1) {
+ name = name.substring(0, idx);
+ ext = name.substring(idx);
+ }
+ return new File(parent, name + suffix + ext);
+ }
+
+ //FIXME need to be generalized
+ public static File getNewFile(File dir, String name, String ext) throws IOException {
+ File f = new File(dir, name + ext);
+ int recursiveNumber = 0;
+ while (f.exists()) {
+ f = new File(dir, name + "_" + (recursiveNumber++) + ext);
+ }
+ f.createNewFile();
+ return f;
+ }
+
+ public static File getNewDir(File dir, String name) throws IOException {
+ File f = new File(dir, name);
+ String baseName = f.getCanonicalPath();
+
+ int recursiveNumber = 0;
+ while (f.exists()) {
+ f = new File(baseName + "_" + (recursiveNumber++));
+ }
+ f.mkdir();
+ return f;
+ }
+
+ public static String getHumanSize(File dir) {
+ long size = getSize(dir);
+
+ if(size <= 0) return "0";
+ final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
+ int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
+ return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
+ }
+
+ public static long getSize(File dir) {
+ long size = 0;
+ if (dir.isFile()) {
+ size = dir.length();
+ } else {
+ File[] subFiles = dir.listFiles();
+
+ for (File file : subFiles) {
+ if (file.isFile()) {
+ size += file.length();
+ } else {
+ size += getSize(file);
+ }
+
+ }
+ }
+ return size;
+ }
+
+ public static void copyFile(String sourceFile, String targetFile) throws IOException {
+ FileHelper.copy(new File(sourceFile), new File(targetFile));
+ }
+
+ public static void copyFile(File f1, OutputStream out) throws IOException {
+ InputStream in = null;
+ try {
+ in = new FileInputStream(f1);
+ FileHelper.copy(in, out);
+ log.debug("File copied.");
+ } catch (Exception e) {
+ log.error("[copyfile(File, File)]", e);
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ }
+}
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ProcessHelper.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ProcessHelper.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ProcessHelper.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/ProcessHelper.java Mon Jul 2 05:10:03 2012
@@ -28,9 +28,12 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;
-import org.openmeetings.app.documents.GenerateSWF;
+import org.openmeetings.app.OpenmeetingsVariables;
+import org.red5.logging.Red5LoggerFactory;
+import org.slf4j.Logger;
public class ProcessHelper {
+ public static final Logger log = Red5LoggerFactory.getLogger(ProcessHelper.class, OpenmeetingsVariables.webAppRootKey);
private static class Worker extends Thread {
private final Process process;
@@ -75,6 +78,24 @@ public class ProcessHelper {
}
}
+ public static HashMap<String, String> executeScriptWindows(String process, String[] argv) {
+ HashMap<String, String> returnMap = new HashMap<String, String>();
+ returnMap.put("process", process);
+ try {
+ String[] cmd = new String[argv.length + 2];
+ cmd[0] = "cmd.exe";
+ cmd[1] = "/C";
+ System.arraycopy(argv, 0, cmd, 2, argv.length);
+ Map<String, String> env = new HashMap<String, String>();
+ returnMap = executeScript(process, cmd, env);
+ } catch (Throwable t) {
+ log.error("executeScriptWindows", t);
+ returnMap.put("error", t.getMessage());
+ returnMap.put("exitValue", "-1");
+ }
+ return returnMap;
+ }
+
public static HashMap<String, String> executeScript(String process, String[] argv) {
Map<String, String> env = new HashMap<String, String>();
return executeScript(process, argv, env);
@@ -84,8 +105,8 @@ public class ProcessHelper {
String[] argv, Map<? extends String, ? extends String> env) {
HashMap<String, String> returnMap = new HashMap<String, String>();
returnMap.put("process", process);
- GenerateSWF.log.debug("process: " + process);
- GenerateSWF.log.debug("args: " + Arrays.toString(argv));
+ log.debug("process: " + process);
+ log.debug("args: " + Arrays.toString(argv));
try {
returnMap.put("command", Arrays.toString(argv));
@@ -111,12 +132,11 @@ public class ProcessHelper {
inputWatcher.start();
worker.start();
-
try {
worker.join(timeout);
if (worker.exitCode != null) {
returnMap.put("exitValue", "" + worker.exitCode);
- GenerateSWF.log.debug("exitVal: " + worker.exitCode);
+ log.debug("exitVal: " + worker.exitCode);
returnMap.put("error", errorWatcher.output.toString());
} else {
returnMap.put("exception", "timeOut");
@@ -141,15 +161,13 @@ public class ProcessHelper {
} catch (TimeoutException e) {
// Timeout exception is processed above
- GenerateSWF.log.error("executeScript",e);
- e.printStackTrace();
+ log.error("executeScript",e);
returnMap.put("error", e.getMessage());
returnMap.put("exception", e.toString());
returnMap.put("exitValue", "-1");
} catch (Throwable t) {
// Any other exception is shown in debug window
- GenerateSWF.log.error("executeScript",t);
- t.printStackTrace();
+ log.error("executeScript",t);
returnMap.put("error", t.getMessage());
returnMap.put("exception", t.toString());
returnMap.put("exitValue", "-1");
Modified: incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/stringhandlers/ChatString.java
URL: http://svn.apache.org/viewvc/incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/stringhandlers/ChatString.java?rev=1356068&r1=1356067&r2=1356068&view=diff
==============================================================================
--- incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/stringhandlers/ChatString.java (original)
+++ incubator/openmeetings/trunk/singlewebapp/src/org/openmeetings/utils/stringhandlers/ChatString.java Mon Jul 2 05:10:03 2012
@@ -26,82 +26,72 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.openmeetings.app.OpenmeetingsVariables;
-import org.openmeetings.app.remote.red5.EmoticonsManager;
import org.red5.logging.Red5LoggerFactory;
import org.slf4j.Logger;
public class ChatString {
-
- private static final Logger log = Red5LoggerFactory.getLogger(ChatString.class, OpenmeetingsVariables.webAppRootKey);
-
- private static ChatString instance = null;
-
- private ChatString() {}
-
- public static synchronized ChatString getInstance(){
- if (instance == null){
- instance = new ChatString();
- }
- return instance;
- }
-
- public LinkedList<String[]> parseChatString(String message) {
+ private static final Logger log = Red5LoggerFactory.getLogger(
+ ChatString.class, OpenmeetingsVariables.webAppRootKey);
+
+ public static LinkedList<String[]> parseChatString(String message, LinkedList<LinkedList<String>> emotFiles) {
try {
LinkedList<String[]> list = new LinkedList<String[]>();
-
- //log.debug("this.link(message) "+this.link(message));
-
- String[] messageStr = {"text",message};
+
+ // log.debug("this.link(message) "+this.link(message));
+
+ String[] messageStr = { "text", message };
list.add(messageStr);
-
- for (Iterator<LinkedList<String>> iter = EmoticonsManager.getEmotfilesList().iterator();iter.hasNext();){
- LinkedList<String> emot = iter.next();
-
- //log.error("CHECK EMOT: "+ emot.get(0) + emot.get(1) + emot.size());
- list = this.splitStr(list,emot.get(0), emot.get(1), emot.get(emot.size()-2));
-
- if (emot.size()>4) {
- //log.error("CHECK EMOT ASIAN: "+ emot.get(0) + emot.get(2) + emot.size());
- list = this.splitStr(list,emot.get(0), emot.get(2), emot.get(emot.size()-2));
+
+ for (LinkedList<String> emot : emotFiles) {
+ // log.error("CHECK EMOT: "+ emot.get(0) + emot.get(1) +
+ // emot.size());
+ list = splitStr(list, emot.get(0), emot.get(1),
+ emot.get(emot.size() - 2));
+
+ if (emot.size() > 4) {
+ // log.error("CHECK EMOT ASIAN: "+ emot.get(0) + emot.get(2)
+ // + emot.size());
+ list = splitStr(list, emot.get(0), emot.get(2),
+ emot.get(emot.size() - 2));
}
- }
-
-// log.debug("######### ");
-// for (Iterator<String[]> iter = list.iterator();iter.hasNext();){
-// String[] stringArray = iter.next();
-// //stringArray[1] = this.link(stringArray[1]);
-// log.debug(stringArray[0]+"||"+stringArray[1]);
-// }
-
+ }
+
+ // log.debug("######### ");
+ // for (Iterator<String[]> iter = list.iterator();iter.hasNext();){
+ // String[] stringArray = iter.next();
+ // //stringArray[1] = this.link(stringArray[1]);
+ // log.debug(stringArray[0]+"||"+stringArray[1]);
+ // }
+
return list;
-
+
} catch (Exception err) {
- log.error("[parseChatString]",err);
+ log.error("[parseChatString]", err);
}
return null;
}
-
-
- private LinkedList<String[]> splitStr (LinkedList<String[]> list, String image, String regexp, String spaces){
-
+ private static LinkedList<String[]> splitStr(LinkedList<String[]> list,
+ String image, String regexp, String spaces) {
+
LinkedList<String[]> newList = new LinkedList<String[]>();
-
- for (Iterator<String[]> iter = list.iterator();iter.hasNext();){
-
+
+ for (Iterator<String[]> iter = list.iterator(); iter.hasNext();) {
+
String[] messageObj = iter.next();
String messageTye = messageObj[0];
-
- if (messageTye.equals("text")){
+
+ if (messageTye.equals("text")) {
String messageStr = messageObj[1];
-
+
String[] newStr = messageStr.split(regexp);
-
- for (int k=0;k<newStr.length;k++) {
- String[] textA = {"text",newStr[k]};
+
+ for (int k = 0; k < newStr.length; k++) {
+ String[] textA = { "text", newStr[k] };
newList.add(textA);
- if (k+1!=newStr.length){
- String[] imageA = {"image",image, spaces, regexp.replace("\\", "") };
+ if (k + 1 != newStr.length) {
+ String[] imageA = { "image", image, spaces,
+ regexp.replace("\\", "") };
newList.add(imageA);
}
}
@@ -111,141 +101,127 @@ public class ChatString {
}
}
-
+
return newList;
}
-
- public void replaceAllRegExp(){
+
+ public static LinkedList<LinkedList<String>> replaceAllRegExp(LinkedList<LinkedList<String>> emotFiles) {
+ LinkedList<LinkedList<String>> emotfilesListNew = new LinkedList<LinkedList<String>>();
try {
- LinkedList<LinkedList<String>> emotfilesList = EmoticonsManager.getEmotfilesList();
- LinkedList<LinkedList<String>> emotfilesListNew = new LinkedList<LinkedList<String>>();
- for (Iterator<LinkedList<String>> iter = emotfilesList.iterator();iter.hasNext();){
- LinkedList<String> emot = iter.next();
-
- //log.error("FILE: "+emot.get(0));
- String westernMeaning = this.checkforRegex(emot.get(1));
+ for (LinkedList<String> emot : emotFiles) {
+ // log.error("FILE: "+emot.get(0));
+ String westernMeaning = checkforRegex(emot.get(1));
emot.set(1, westernMeaning);
- //log.error("westernMeaning "+westernMeaning);
- if (emot.size()>2){
- String asianMeaning = this.checkforRegex(emot.get(2));
+ // log.error("westernMeaning "+westernMeaning);
+ if (emot.size() > 2) {
+ String asianMeaning = checkforRegex(emot.get(2));
emot.set(2, asianMeaning);
- //log.error("westernMeaning "+asianMeaning);
+ // log.error("westernMeaning "+asianMeaning);
}
emotfilesListNew.add(emot);
}
- EmoticonsManager.setEmotfilesList(emotfilesListNew);
} catch (Exception err) {
- log.error("[replaceAllRegExp]",err);
+ log.error("[replaceAllRegExp]", err);
}
+ return emotfilesListNew;
}
-
- /**
- * Replace characters having special meaning in regular expressions
- *
- */
- private String checkforRegex(String aRegexFragment){
- final StringBuilder result = new StringBuilder();
-
- final StringCharacterIterator iterator = new StringCharacterIterator(aRegexFragment);
- char character = iterator.current();
- while (character != CharacterIterator.DONE ){
- /*
- * All literals need to have backslashes doubled.
- */
- if (character == '.') {
- result.append("\\.");
- }
- else if (character == '\\') {
- result.append("\\\\");
- }
- else if (character == '?') {
- result.append("\\?");
- }
- else if (character == '*') {
- result.append("\\*");
- }
- else if (character == '+') {
- result.append("\\+");
- }
- else if (character == '&') {
- result.append("\\&");
- }
- else if (character == ':') {
- result.append("\\:");
- }
- else if (character == '{') {
- result.append("\\{");
- }
- else if (character == '}') {
- result.append("\\}");
- }
- else if (character == '[') {
- result.append("\\[");
- }
- else if (character == ']') {
- result.append("\\]");
- }
- else if (character == '(') {
- result.append("\\(");
- }
- else if (character == ')') {
- result.append("\\)");
- }
- else if (character == '^') {
- result.append("\\^");
- }
- else if (character == '$') {
- result.append("\\$");
- }
- else if (character == '|') {
- result.append("\\|");
- }
- else {
- //the char is not a special one
- //add it to the result as is
- result.append(character);
- }
- character = iterator.next();
- }
- return result.toString();
- }
-
- public String link(String input) {
- try {
-
- String tReturn = "";
-
- String parts[] = input.split(" ");
-
- for (int t=0;t<parts.length;t++) {
-
- String text = parts[t];
-
- //System.out.println("Part 1 "+text);
-
- Matcher matcher = Pattern.compile("(^|[ \t\r\n])((ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file|prospero|aim|webcal):(([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?([A-Za-z0-9$_+!*();/?:~-]))").matcher(text);
-
- if (matcher.find()) {
- text = matcher.replaceFirst("<u><FONT color=\"#0000CC\"><a href='" + text + "'>" + text
- + "</a></FONT></u>");
- }
-
- //System.out.println("Part 2 "+text);
-
- if (t != 0) {
- tReturn += " ";
- }
-
- tReturn += text;
-
+ /**
+ * Replace characters having special meaning in regular expressions
+ *
+ */
+ private static String checkforRegex(String aRegexFragment) {
+ final StringBuilder result = new StringBuilder();
+
+ final StringCharacterIterator iterator = new StringCharacterIterator(
+ aRegexFragment);
+ char character = iterator.current();
+ while (character != CharacterIterator.DONE) {
+ /*
+ * All literals need to have backslashes doubled.
+ */
+ if (character == '.') {
+ result.append("\\.");
+ } else if (character == '\\') {
+ result.append("\\\\");
+ } else if (character == '?') {
+ result.append("\\?");
+ } else if (character == '*') {
+ result.append("\\*");
+ } else if (character == '+') {
+ result.append("\\+");
+ } else if (character == '&') {
+ result.append("\\&");
+ } else if (character == ':') {
+ result.append("\\:");
+ } else if (character == '{') {
+ result.append("\\{");
+ } else if (character == '}') {
+ result.append("\\}");
+ } else if (character == '[') {
+ result.append("\\[");
+ } else if (character == ']') {
+ result.append("\\]");
+ } else if (character == '(') {
+ result.append("\\(");
+ } else if (character == ')') {
+ result.append("\\)");
+ } else if (character == '^') {
+ result.append("\\^");
+ } else if (character == '$') {
+ result.append("\\$");
+ } else if (character == '|') {
+ result.append("\\|");
+ } else {
+ // the char is not a special one
+ // add it to the result as is
+ result.append(character);
+ }
+ character = iterator.next();
+ }
+ return result.toString();
+ }
+
+ public static String link(String input) {
+ try {
+
+ String tReturn = "";
+
+ String parts[] = input.split(" ");
+
+ for (int t = 0; t < parts.length; t++) {
+
+ String text = parts[t];
+
+ // System.out.println("Part 1 "+text);
+
+ Matcher matcher = Pattern
+ .compile(
+ "(^|[ \t\r\n])((ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file|prospero|aim|webcal):(([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?([A-Za-z0-9$_+!*();/?:~-]))")
+ .matcher(text);
+
+ if (matcher.find()) {
+ text = matcher
+ .replaceFirst("<u><FONT color=\"#0000CC\"><a href='"
+ + text + "'>" + text + "</a></FONT></u>");
+
+ }
+
+ // System.out.println("Part 2 "+text);
+
+ if (t != 0) {
+ tReturn += " ";
}
-
- return tReturn;
-
- } catch (Exception e) {
- log.error("[link]",e);
+
+ tReturn += text;
+
}
- return "";
+
+ return tReturn;
+
+ } catch (Exception e) {
+ log.error("[link]", e);
}
+ return "";
+ }
}