forked from tabulapdf/tabula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ru
97 lines (81 loc) · 3.4 KB
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# encoding: UTF-8
require 'rubygems'
require 'bundler'
Bundler.require
# Disable LittleCMS when running in JVM >= 1.8
# https://pdfbox.apache.org/2.0/getting-started.html
jvmajor, jvminor = java.lang.System.getProperty('java.specification.version').split('.')
if !jvminor.nil? && jvminor.to_i >= 8
java.lang.System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider")
end
require_relative './webapp/tabula_settings.rb'
require_relative './webapp/tabula_web.rb'
potential_root_uri_without_slashes = (defined?($servlet_context) ? $servlet_context.getContextPath : ENV["ROOT_URI"])
if potential_root_uri_without_slashes.nil? || potential_root_uri_without_slashes == ''
ROOT_URI = '/'
else
ROOT_URI = (potential_root_uri_without_slashes[0] == "/" ? '' : '/') + potential_root_uri_without_slashes + (potential_root_uri_without_slashes[-1] == "/" ? '' : '/')
end
puts "running under #{ROOT_URI} as root URI"
map ROOT_URI do
run Cuba
end
if "#{$PROGRAM_NAME}".include?("tabula.jar")
# only do this if running as jar or app. (if "rackup", we don't
# actually use 8080 by default.)
require 'java'
# don't do "java_import java.net.URI" -- it conflicts with Ruby URI and
# makes Cuba/Rack really really upset. just call "java.*" classes
# directly.
port = java.lang.Integer.getInteger('warbler.port', 8080)
url = "http://127.0.0.1:#{port}"
puts "============================================================"
puts url
puts "============================================================"
# Open browser after slight delay. (The server may take a while to actually
# serve HTTP, so we are trying to avoid a "Could Not Connect To Server".)
uri = java.net.URI.new(url)
sleep 0.5
puts "should we open browser?"
puts "java.lang.Boolean.getBoolean('tabula.openBrowser'): #{java.lang.Boolean.getBoolean('tabula.openBrowser')}"
have_desktop = false
if java.lang.Boolean.getBoolean('tabula.openBrowser')
puts "java.awt.Desktop.isDesktopSupported: #{java.awt.Desktop.isDesktopSupported}"
if java.awt.Desktop.isDesktopSupported
begin
desktop = java.awt.Desktop.getDesktop()
rescue
puts "java.awt.Desktop.getDesktop(): no"
desktop = nil
else
puts "java.awt.Desktop.getDesktop(): yes"
have_desktop = true
end
end
end
# if running as a jar or app, automatically open the user's web browser if
# the system supports it.
if have_desktop
puts "\n======================================================"
puts "Launching web browser to #{url}\n\n"
begin
desktop.browse(uri)
rescue
puts "Unable to launch your web browser, you will have to"
puts "manually open it to the above URL."
else
puts "If it does not open in 10 seconds, you may manually open"
puts "a web browser to the above URL."
end
puts "When you're done using the Tabula interface, you may"
puts "return to this window and press \"Control-C\" to close it."
puts "======================================================\n\n"
else
puts "\n======================================================"
puts "Server now listening at: #{url}\n\n"
puts "You may now open a web browser to the above URL."
puts "When you're done using the Tabula interface, you may"
puts "return to this window and press \"Control-C\" to close it."
puts "======================================================\n\n"
end
end