Skip to content

Commit b65c02b

Browse files
committed
first commit
0 parents  commit b65c02b

File tree

15,819 files changed

+671658
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

15,819 files changed

+671658
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# MacOS DesktopConfig files
2+
.DS_Store
3+
/target/

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# SWBForms2

nb-configuration.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-shared-configuration>
3+
<!--
4+
This file contains additional configuration written by modules in the NetBeans IDE.
5+
The configuration is intended to be shared among all the users of project and
6+
therefore it is assumed to be part of version control checkout.
7+
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
8+
-->
9+
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
10+
<!--
11+
Properties that influence various parts of the IDE, especially code formatting and the like.
12+
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
13+
That way multiple projects can share the same settings (useful for formatting rules for example).
14+
Any value defined here will override the pom.xml file value but is only applicable to the current project.
15+
-->
16+
<netbeans.hint.jdkPlatform>JDK 1.7</netbeans.hint.jdkPlatform>
17+
</properties>
18+
</project-shared-configuration>

pom.xml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.semanticwb</groupId>
6+
<artifactId>SWBForms2</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>war</packaging>
9+
10+
<name>SWBForms2</name>
11+
12+
<properties>
13+
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.semanticwb.datamager</groupId>
20+
<artifactId>SWBDataManager</artifactId>
21+
<version>1.0-SNAPSHOT</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>javax</groupId>
25+
<artifactId>javaee-web-api</artifactId>
26+
<version>7.0</version>
27+
<scope>provided</scope>
28+
</dependency>
29+
</dependencies>
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>org.apache.maven.plugins</groupId>
35+
<artifactId>maven-compiler-plugin</artifactId>
36+
<version>3.1</version>
37+
<configuration>
38+
<source>1.8</source>
39+
<target>1.8</target>
40+
<compilerArguments>
41+
<endorseddirs>${endorsed.dir}</endorseddirs>
42+
</compilerArguments>
43+
</configuration>
44+
</plugin>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-war-plugin</artifactId>
48+
<version>2.3</version>
49+
<configuration>
50+
<failOnMissingWebXml>false</failOnMissingWebXml>
51+
</configuration>
52+
</plugin>
53+
<plugin>
54+
<groupId>org.apache.maven.plugins</groupId>
55+
<artifactId>maven-dependency-plugin</artifactId>
56+
<version>2.6</version>
57+
<executions>
58+
<execution>
59+
<phase>validate</phase>
60+
<goals>
61+
<goal>copy</goal>
62+
</goals>
63+
<configuration>
64+
<outputDirectory>${endorsed.dir}</outputDirectory>
65+
<silent>true</silent>
66+
<artifactItems>
67+
<artifactItem>
68+
<groupId>javax</groupId>
69+
<artifactId>javaee-endorsed-api</artifactId>
70+
<version>7.0</version>
71+
<type>jar</type>
72+
</artifactItem>
73+
</artifactItems>
74+
</configuration>
75+
</execution>
76+
</executions>
77+
</plugin>
78+
</plugins>
79+
</build>
80+
81+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.semanticwb.swbforms.servlet;
2+
3+
import java.io.IOException;
4+
import java.util.logging.Logger;
5+
import javax.servlet.Filter;
6+
import javax.servlet.FilterChain;
7+
import javax.servlet.FilterConfig;
8+
import javax.servlet.ServletException;
9+
import javax.servlet.ServletRequest;
10+
import javax.servlet.ServletResponse;
11+
import javax.servlet.annotation.WebFilter;
12+
import javax.servlet.http.HttpServletRequest;
13+
import javax.servlet.http.HttpServletResponse;
14+
import org.semanticwb.datamanager.DataObject;
15+
import org.semanticwb.swbforms.servlet.router.RouteHandler;
16+
import org.semanticwb.swbforms.servlet.router.Router;
17+
18+
/**
19+
*
20+
* @author serch
21+
*/
22+
@WebFilter(urlPatterns = {"/*"})
23+
public class FormsFilter implements Filter {
24+
private static final Logger logger = Logger.getLogger("i.c.s.CloudFilter");
25+
//private static final Router router = Router.getRouter();
26+
27+
@Override
28+
public void init(FilterConfig filterConfig) throws ServletException {
29+
logger.info("Starting Cloudino...");
30+
}
31+
32+
@Override
33+
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
34+
Object obj = ((HttpServletRequest)request).getSession().getAttribute("_USER_");
35+
// System.out.println("obj:"+obj);
36+
DataObject dobj = null;
37+
if ((null!=obj) && (obj instanceof DataObject)) {
38+
dobj = (DataObject)obj;
39+
}
40+
HttpServletRequest hreq = ((HttpServletRequest)request);
41+
// System.out.println("*************************************");
42+
// System.out.println("getContextPath:"+hreq.getContextPath());
43+
// System.out.println("getPathInfo:"+hreq.getPathInfo());
44+
// System.out.println("getPathTranslated:"+hreq.getPathTranslated());
45+
// System.out.println("getRequestURI:"+hreq.getRequestURI());
46+
// System.out.println("getServletPath:"+hreq.getServletPath());
47+
// System.out.println("getRequestURL:"+hreq.getRequestURL());
48+
String path = hreq.getRequestURI().substring(hreq.getContextPath().length());
49+
// System.out.println("path->:"+path);
50+
RouteHandler rh = Router.getHandler(path, dobj);
51+
// System.out.println("rh:"+rh);
52+
if (null==rh) {
53+
chain.doFilter(request, response);
54+
} else {
55+
rh.handle(hreq, (HttpServletResponse)response);
56+
}
57+
// System.out.println("");
58+
}
59+
60+
@Override
61+
public void destroy() {
62+
63+
}
64+
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package org.semanticwb.swbforms.servlet;
7+
8+
import java.io.IOException;
9+
import java.nio.file.FileSystems;
10+
import java.nio.file.Path;
11+
import java.nio.file.Paths;
12+
import java.nio.file.StandardWatchEventKinds;
13+
import java.nio.file.WatchKey;
14+
import java.nio.file.WatchService;
15+
import java.util.concurrent.Executors;
16+
import java.util.concurrent.ScheduledExecutorService;
17+
import java.util.concurrent.TimeUnit;
18+
import java.util.logging.Level;
19+
import java.util.logging.Logger;
20+
import javax.servlet.ServletContextEvent;
21+
import javax.servlet.ServletContextListener;
22+
import javax.servlet.annotation.WebListener;
23+
import org.semanticwb.datamanager.DataMgr;
24+
import org.semanticwb.datamanager.SWBScriptEngine;
25+
import org.semanticwb.datamanager.script.ScriptObject;
26+
import org.semanticwb.swbforms.servlet.router.Router;
27+
28+
@WebListener
29+
public class FormsServletContextListener implements ServletContextListener {
30+
31+
static Logger log = Logger.getLogger(FormsServletContextListener.class.getName());
32+
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
33+
34+
@Override
35+
public void contextInitialized(ServletContextEvent sce) {
36+
log.info("Starting SWBForms");
37+
DataMgr.createInstance(sce.getServletContext().getRealPath("/"));
38+
log.info("SWBForms DataMgr Started");
39+
40+
SWBScriptEngine engine = DataMgr.getUserScriptEngine("/WEB-INF/global.js", null, false);
41+
log.info("SWBForms SWBScriptEngine Started");
42+
43+
ScriptObject config = engine.getScriptObject().get("config");
44+
if (config != null) {
45+
String base = config.getString("baseDatasource");
46+
if (base != null) {
47+
DataMgr.getBaseInstance().setBaseDatasourse(base);
48+
}
49+
}
50+
51+
log.info("Configuring Router");
52+
ScriptObject ros = engine.getScriptObject().get("routes");
53+
Router.initRouter(ros);
54+
log.info("Router configured");
55+
try {
56+
WatchService wservice = FileSystems.getDefault().newWatchService();
57+
Path file = Paths.get(DataMgr.getApplicationPath(), "/WEB-INF/global.js").getParent().toAbsolutePath();
58+
WatchKey key = file.register(wservice, StandardWatchEventKinds.ENTRY_MODIFY);
59+
service.scheduleWithFixedDelay(() -> {
60+
key.pollEvents().stream().forEach((f) -> {
61+
if ("global.js".equals(f.context().toString())) {
62+
SWBScriptEngine engine1 = DataMgr.getUserScriptEngine("/WEB-INF/global.js", null, false);
63+
ScriptObject ros1 = engine1.getScriptObject().get("routes");
64+
Router.initRouter(ros1);
65+
}
66+
});
67+
}, 10, 10, TimeUnit.SECONDS);
68+
} catch (IOException | UnsupportedOperationException pex) {
69+
log.log(Level.SEVERE, "Error Reloading routes from global.js file ", pex);
70+
}
71+
}
72+
73+
@Override
74+
public void contextDestroyed(ServletContextEvent sce) {
75+
System.out.println("aplicacion web parada");
76+
try {
77+
service.shutdownNow();
78+
service.awaitTermination(10, TimeUnit.SECONDS);
79+
} catch (InterruptedException iex) {
80+
log.log(Level.SEVERE, "Shootingdown", iex);
81+
}
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.semanticwb.swbforms.servlet.router;
2+
3+
import java.io.IOException;
4+
import javax.servlet.ServletException;
5+
import javax.servlet.http.HttpServletRequest;
6+
import javax.servlet.http.HttpServletResponse;
7+
8+
/**
9+
*
10+
* @author serch
11+
*/
12+
public interface RouteHandler {
13+
void handle(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException;
14+
}

0 commit comments

Comments
 (0)