Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sally4-core
sally4-docmanager
Commits
7ca71ef5
Commit
7ca71ef5
authored
Jan 19, 2015
by
Constantin Jucovschi
Browse files
Merge branch 'master' into amqp_protocol
parents
b73e7884
f1391055
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/info/kwarc/sally4/docmanager/impl/CallbackManagerImpl.java
View file @
7ca71ef5
...
...
@@ -2,8 +2,8 @@ package info.kwarc.sally4.docmanager.impl;
import
info.kwarc.sally4.docmanager.CallbackManager
;
import
java.util.HashMap
;
import
java.util.UUID
;
import
java.util.concurrent.TimeUnit
;
import
org.apache.felix.ipojo.annotations.Component
;
import
org.apache.felix.ipojo.annotations.Instantiate
;
...
...
@@ -13,15 +13,20 @@ import org.apache.felix.ipojo.annotations.Validate;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.google.common.cache.Cache
;
import
com.google.common.cache.CacheBuilder
;
@Component
@Instantiate
@Provides
(
specifications
=
CallbackManager
.
class
)
public
class
CallbackManagerImpl
implements
CallbackManager
{
HashMap
<
String
,
Object
>
runners
=
new
HashMap
<
String
,
Object
>();
Cache
<
String
,
Object
>
runners
;
Logger
log
;
public
CallbackManagerImpl
()
{
runners
=
CacheBuilder
.
newBuilder
().
maximumSize
(
1000
).
expireAfterAccess
(
1
,
TimeUnit
.
HOURS
).
build
();
log
=
LoggerFactory
.
getLogger
(
getClass
());
}
...
...
@@ -45,13 +50,13 @@ public class CallbackManagerImpl implements CallbackManager {
@Override
public
Object
get
(
String
UUID
)
{
return
runners
.
get
(
UUID
);
return
runners
.
get
IfPresent
(
UUID
);
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
<
T
>
T
get
(
String
UUID
,
Class
<?
extends
T
>
cls
)
{
Object
o
=
runners
.
get
(
UUID
);
Object
o
=
runners
.
get
IfPresent
(
UUID
);
if
(
o
==
null
)
return
null
;
if
(
cls
.
isInstance
(
o
))
...
...
src/main/java/info/kwarc/sally4/servlet/impl/ServletController.java
View file @
7ca71ef5
...
...
@@ -4,6 +4,7 @@ import info.kwarc.sally4.components.TemplatingComponent;
import
info.kwarc.sally4.processors.FileServeProcessor
;
import
org.apache.camel.CamelContext
;
import
org.apache.camel.Component
;
import
org.apache.camel.builder.RouteBuilder
;
import
org.apache.camel.component.freemarker.FreemarkerComponent
;
...
...
@@ -20,10 +21,15 @@ public class ServletController {
debugTemplatingPath
=
""
;
}
public
ServletController
setDebugTemplating
(
boolean
debugTemplating
)
{
this
.
debugTemplating
=
debugTemplating
;
return
this
;
}
public
String
tpl
(
String
fileName
)
{
return
"templatingComponent:"
+
debugTemplatingPath
+
fileName
;
}
static
String
makeSureEndsInSlash
(
String
s
)
{
if
(
s
.
charAt
(
s
.
length
()-
1
)
==
'/'
)
{
return
s
;
...
...
@@ -40,24 +46,30 @@ public class ServletController {
}
}
void
replaceTemplatingComponent
(
Component
comp
)
{
if
(
context
.
getComponent
(
"templatingComponent"
)
!=
null
)
{
context
.
removeComponent
(
"templatingComponent"
);
}
context
.
addComponent
(
"templatingComponent"
,
comp
);
}
public
ServletController
initDebugTemplating
(
String
fullPath
)
{
fullPath
=
makeSureEndsInSlash
(
fullPath
);
debugTemplatingPath
=
"file://"
+
fullPath
;
debugTemplating
=
true
;
if
(
context
.
getComponent
(
"templatingComponent"
)
==
null
)
{
context
.
addComponent
(
"templatingComponent"
,
new
FreemarkerComponent
());
if
(
debugTemplating
)
{
fullPath
=
makeSureEndsInSlash
(
fullPath
);
debugTemplatingPath
=
"file://"
+
fullPath
;
replaceTemplatingComponent
(
new
FreemarkerComponent
());
}
return
this
;
}
public
ServletController
initTemplating
(
String
jarPath
)
{
jarPath
=
makeSureEndsInSlash
(
jarPath
);
if
(
context
.
getComponent
(
"templatingComponent"
)
==
null
)
{
context
.
addComponent
(
"t
emplatingComponent
"
,
new
TemplatingComponent
(
jarPath
,
loader
));
if
(
!
debugTemplating
||
context
.
getComponent
(
"templatingComponent"
)==
null
)
{
replaceT
emplatingComponent
(
new
TemplatingComponent
(
jarPath
,
loader
));
}
return
this
;
}
public
ServletController
serveStaticFiles
(
String
servletPath
,
final
String
jarPath
)
{
final
String
_servletPath
=
makeSureStartsInSlash
(
servletPath
);
try
{
...
...
@@ -65,7 +77,7 @@ public class ServletController {
@Override
public
void
configure
()
throws
Exception
{
from
(
"sallyservlet://"
+
_servletPath
+
"?matchOnUriPrefix=true"
)
.
process
(
new
FileServeProcessor
(
jarPath
,
loader
));
.
process
(
new
FileServeProcessor
(
jarPath
,
loader
));
}
});
}
catch
(
Exception
e
)
{
...
...
@@ -74,5 +86,5 @@ public class ServletController {
return
this
;
}
}
src/main/java/info/kwarc/sally4/servlet/impl/ServletImpl.java
View file @
7ca71ef5
...
...
@@ -33,6 +33,9 @@ public class ServletImpl implements SallyServlet {
@Property
(
name
=
"SallyHost"
,
value
=
"http://localhost"
)
String
SallyHost
;
@Property
(
name
=
"SallyDebugTemplate"
,
value
=
"false"
)
boolean
debugTemplate
=
false
;
String
SallyURL
;
@Bind
(
aggregate
=
true
)
...
...
@@ -69,7 +72,8 @@ public class ServletImpl implements SallyServlet {
if
(
context
.
hasComponent
(
"sallyservlet"
)
==
null
)
{
context
.
addComponent
(
"sallyservlet"
,
servletComponent
);
}
return
new
ServletController
(
context
,
loader
);
return
new
ServletController
(
context
,
loader
).
setDebugTemplating
(
debugTemplate
);
}
@Invalidate
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment