PageRenderTime 57ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/com.idega.app.eplatform/src/edu/stanford/ejalbert/launching/BrowserLaunchingFactory.java

https://github.com/tryggvil/com.idega.app.platform
Java | 134 lines | 87 code | 3 blank | 44 comment | 29 complexity | bcafadece5db7fa86bff13ad227b987d MD5 | raw file
  1. /************************************************
  2. Copyright 2004,2005,2006,2007 Markus Gebhard, Jeff Chapman
  3. This file is part of BrowserLauncher2.
  4. BrowserLauncher2 is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. BrowserLauncher2 is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with BrowserLauncher2; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. ************************************************/
  16. // $Id: BrowserLaunchingFactory.java,v 1.1 2007-12-11 02:35:41 eiki Exp $
  17. package edu.stanford.ejalbert.launching;
  18. import net.sf.wraplog.AbstractLogger;
  19. import edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException;
  20. import edu.stanford.ejalbert.launching.macos.MacOs2_0BrowserLaunching;
  21. import edu.stanford.ejalbert.launching.macos.MacOs2_1BrowserLaunching;
  22. import edu.stanford.ejalbert.launching.macos.MacOs3_0BrowserLaunching;
  23. import edu.stanford.ejalbert.launching.macos.MacOs3_1BrowserLaunching;
  24. import edu.stanford.ejalbert.launching.macos.MacOsXBrowserLaunching;
  25. import edu.stanford.ejalbert.launching.misc.SunOSBrowserLaunching;
  26. import edu.stanford.ejalbert.launching.misc.UnixNetscapeBrowserLaunching;
  27. import edu.stanford.ejalbert.launching.windows.WindowsBrowserLaunching;
  28. /**
  29. * Factory for determining the OS and returning the appropriate version
  30. * of IBrowserLaunching. The factory uses
  31. * {@link System#getProperty(String) System.getProperty("os.name")} to
  32. * determine the OS.
  33. *
  34. * @author Markus Gebhard
  35. */
  36. public class BrowserLaunchingFactory {
  37. /**
  38. * Analyzes the name of the underlying operating system
  39. * based on the "os.name" system property and returns
  40. * the IBrowserLaunching version appropriate for the
  41. * O/S.
  42. *
  43. * @param logger AbstractLogger
  44. * @return IBrowserLaunching
  45. * @throws UnsupportedOperatingSystemException
  46. */
  47. public static IBrowserLaunching createSystemBrowserLaunching(
  48. AbstractLogger logger)
  49. throws UnsupportedOperatingSystemException {
  50. String osName = System.getProperty("os.name");
  51. if (osName.startsWith("Mac OS")) {
  52. logger.info("Mac OS");
  53. if(osName.equals("Mac OS X")){
  54. return new MacOsXBrowserLaunching(logger);
  55. }
  56. else{
  57. //older macos
  58. String mrjVersion = System.getProperty("mrj.version");
  59. String majorMRJVersion = mrjVersion.substring(0, 3);
  60. try {
  61. double version = Double.valueOf(majorMRJVersion).doubleValue();
  62. logger.info("version=" + Double.toString(version));
  63. if (version == 2) {
  64. return new MacOs2_0BrowserLaunching();
  65. }
  66. else if (version >= 2.1 && version < 3) {
  67. // Assume that all 2.x versions of MRJ work the same. MRJ 2.1 actually
  68. // works via Runtime.exec() and 2.2 supports that but has an openURL() method
  69. // as well that we currently ignore.
  70. return new MacOs2_1BrowserLaunching();
  71. }
  72. else if (version == 3.0) {
  73. return new MacOs3_0BrowserLaunching();
  74. }
  75. else if (version >= 3.1) {
  76. // Assume that all 3.1 and later versions of MRJ work the same.
  77. return new MacOs3_1BrowserLaunching();
  78. }
  79. else {
  80. throw new UnsupportedOperatingSystemException(
  81. "Unsupported MRJ version: " + version);
  82. }
  83. }
  84. catch (NumberFormatException nfe) {
  85. throw new UnsupportedOperatingSystemException(
  86. "Invalid MRJ version: " + mrjVersion);
  87. }
  88. }
  89. }
  90. else if (osName.startsWith("Windows")) {
  91. logger.info("Windows OS");
  92. if (osName.indexOf("9") != -1 ||
  93. osName.indexOf("Windows Me") != -1) {
  94. return new WindowsBrowserLaunching(
  95. logger,
  96. WindowsBrowserLaunching.WINKEY_WIN9X);
  97. }
  98. else if(osName.indexOf("Vista") != -1) {
  99. return new WindowsBrowserLaunching(
  100. logger,
  101. WindowsBrowserLaunching.WINKEY_WINVISTA);
  102. }
  103. else if (osName.indexOf("2000") != -1 ||
  104. osName.indexOf("XP") != -1) {
  105. return new WindowsBrowserLaunching(
  106. logger,
  107. WindowsBrowserLaunching.WINKEY_WIN2000);
  108. }
  109. else {
  110. return new WindowsBrowserLaunching(
  111. logger,
  112. WindowsBrowserLaunching.WINKEY_WINNT);
  113. }
  114. }
  115. else if (osName.startsWith("SunOS")) {
  116. logger.info("SunOS");
  117. return new SunOSBrowserLaunching(logger);
  118. }
  119. else {
  120. logger.info("Unix-type OS");
  121. return new UnixNetscapeBrowserLaunching(
  122. logger,
  123. UnixNetscapeBrowserLaunching.CONFIGFILE_LINUX_UNIX);
  124. }
  125. }
  126. }