mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
125781 rmunteanu: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1) 125603 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127808 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
134 lines
4.2 KiB
Java
134 lines
4.2 KiB
Java
package org.alfresco.util;
|
|
|
|
import java.io.File;
|
|
|
|
import org.alfresco.error.AlfrescoRuntimeException;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
/**
|
|
* Provides OpenOffice and LibreOffice variant information.
|
|
*
|
|
* @author Alan Davis
|
|
*/
|
|
public class OpenOfficeVariant
|
|
{
|
|
private static final String[] EXTENSIONS = new String[] {"", ".exe", ".com", ".bat", ".cmd"};
|
|
private static final Log logger = LogFactory.getLog(OpenOfficeCommandLine.class);
|
|
private static final String OS_NAME = System.getProperty("os.name").toLowerCase();
|
|
|
|
private final boolean windows = isWindows();
|
|
|
|
public File getOfficeHome(File executable)
|
|
{
|
|
// Get the grandparent
|
|
File officeHome = executable;
|
|
for (int i=1; officeHome != null && i <= 2; i++)
|
|
{
|
|
officeHome = officeHome.getParentFile();
|
|
}
|
|
|
|
if (officeHome == null && executable != null)
|
|
{
|
|
throw new AlfrescoRuntimeException("Did not find OppenOffice home from executable "+executable.getAbsolutePath());
|
|
}
|
|
|
|
return officeHome;
|
|
}
|
|
|
|
public File findExecutable(String executableName)
|
|
{
|
|
File file = new File(executableName);
|
|
if (file.isAbsolute())
|
|
{
|
|
file = canExecute(file);
|
|
}
|
|
else
|
|
{
|
|
file = findExecutableOnPath(executableName);
|
|
}
|
|
return file;
|
|
}
|
|
|
|
private File findExecutableOnPath(String executableName)
|
|
{
|
|
String systemPath = System.getenv("PATH");
|
|
systemPath = systemPath == null ? System.getenv("path") : systemPath;
|
|
String[] pathDirs = systemPath.split(File.pathSeparator);
|
|
|
|
File fullyQualifiedExecutable = null;
|
|
for (String pathDir : pathDirs)
|
|
{
|
|
File file = canExecute(new File(pathDir, executableName));
|
|
if (file != null)
|
|
{
|
|
fullyQualifiedExecutable = file;
|
|
break;
|
|
}
|
|
}
|
|
return fullyQualifiedExecutable;
|
|
}
|
|
|
|
private File canExecute(File file)
|
|
{
|
|
File fullyQualifiedExecutable = null;
|
|
File dir = file.getParentFile();
|
|
String name = file.getName();
|
|
for (String ext: EXTENSIONS)
|
|
{
|
|
file = new File(dir, name+ext);
|
|
if (file.canExecute())
|
|
{
|
|
fullyQualifiedExecutable = file;
|
|
break;
|
|
}
|
|
if (!windows)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
return fullyQualifiedExecutable;
|
|
}
|
|
|
|
public boolean isLibreOffice3Dot5(File officeHome)
|
|
{
|
|
if (logger.isDebugEnabled())
|
|
{
|
|
logger.debug("System.getProperty(\"os.name\")="+System.getProperty("os.name"));
|
|
logger.debug("officeHome="+(officeHome == null ? null : "'"+officeHome.getAbsolutePath()+"'"));
|
|
logger.debug("basis-link:"+new File(officeHome, "basis-link").isFile());
|
|
logger.debug("basis-link:"+new File(officeHome, "basis-link").isDirectory());
|
|
logger.debug(" ure-link:"+new File(officeHome, "ure-link").isFile());
|
|
logger.debug(" ure-link:"+new File(officeHome, "ure-link").isDirectory());
|
|
logger.debug(" NOTICE:"+new File(officeHome, "NOTICE").isFile());
|
|
}
|
|
return
|
|
officeHome != null &&
|
|
!new File(officeHome, "basis-link").isFile() &&
|
|
(new File(officeHome, "ure-link").isFile() || new File(officeHome, "ure-link").isDirectory());
|
|
}
|
|
|
|
public boolean isLibreOffice3Dot6(File officeHome)
|
|
{
|
|
if (logger.isDebugEnabled())
|
|
{
|
|
logger.debug(" NOTICE:"+new File(officeHome, "NOTICE").isFile());
|
|
}
|
|
return isLibreOffice3Dot5(officeHome) && new File(officeHome, "NOTICE").isFile();
|
|
}
|
|
|
|
public boolean isLinux()
|
|
{
|
|
return OS_NAME.startsWith("linux");
|
|
}
|
|
|
|
public boolean isMac()
|
|
{
|
|
return OS_NAME.startsWith("mac");
|
|
}
|
|
|
|
public boolean isWindows()
|
|
{
|
|
return OS_NAME.startsWith("windows");
|
|
}
|
|
} |