Skip to content

Commit

Permalink
Added HTTP sitemap generator for scala test app
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianKirmaier committed May 22, 2024
1 parent b0ec038 commit d4939da
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,22 @@ object Request {
Request.fromString(s).copy(oldContent = oldViewW, origOldContent = oldViewW)
}
def fromString(s: String): Request = {
if(!isValidLink(s)) {
logger.warn("Warning - Invalid Link: " + s)
try {
if(!isValidLink(s)) {
logger.warn("Warning - Invalid Link: " + s)
}
val uri = new URI(s)
val rawQuery = uri.getRawQuery
val query: Map[String,String] = if(rawQuery == null || rawQuery == "") Map() else rawQuery.split("&").map(x => {
val Array(a,b) = x.split("=")
a -> b
}).toMap
val path = uri.getPath
val res = Request(s, uri.getScheme, uri.getHost, uri.getPort, path,path,"/", query,wref_null,wref_null)
res
} catch {
case e: Exception =>
throw new RuntimeException("Could not parse Request from string: " + s, e)
}
val uri = new URI(s)
val rawQuery = uri.getRawQuery
val query: Map[String,String] = if(rawQuery == null || rawQuery == "") Map() else rawQuery.split("&").map(x => {
val Array(a,b) = x.split("=")
a -> b
}).toMap
val path = uri.getPath
val res = Request(s, uri.getScheme, uri.getHost, uri.getPort, path,path,"/", query,wref_null,wref_null)
res
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ object AppCrawler {
crawler.crawlAll()
}

def routeToRouteNode(route: Route): RouteNode = {
val stage = new Stage
val routeNode = new RouteNode(stage)
stage.setScene(new Scene(routeNode))
val sm = new SessionManagerDesktop(routeNode)
routeNode.setRoute(route)
routeNode.start(sm)
routeNode
}

def getImageURL(x: Image): String = {
if(x.getUrl == null) return null;
val url = simplifyAndEncode(x.getUrl)
Expand Down Expand Up @@ -185,6 +195,7 @@ class AppCrawler(prefix: String, createApp: Supplier[RouteNode]) {
val app: RouteNode = inFX(createApp.get())
val result = inFX {
LinkUtil.getSessionManager(app)
val request = Request.fromString(crawlNext)
app.getRoute()(Request.fromString(crawlNext))
}.future.await
result match {
Expand Down Expand Up @@ -235,7 +246,12 @@ class AppCrawler(prefix: String, createApp: Supplier[RouteNode]) {
def crawlAll(): CrawlReportApp = {

while (toIndex.nonEmpty) {
doStep()
try {
doStep()
} catch {
case ex: Throwable =>
logger.error("Error in crawlAll", ex)
}
}

CrawlReportApp((indexed -- redirects -- deadLinks).toList, reports.reverse, deadLinks.toList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import simplefx.core._

import scala.collection.JavaConverters.asScalaBufferConverter

class MyApp(stage: Stage) extends RouteNode(stage) {
class TestWebApplication extends RouteApp {

stylesheets ::= "test.css"
override def createRoute(): Route = {
if(getRouteNode() != null) {
getRouteNode().stylesheets ::= "test.css"
}

setRoute(
Route.empty()
.and(get("", (r) => Response.view(new MainView)))
.and(get("/", (r) => Response.view(new MainView)))
Expand All @@ -44,11 +46,9 @@ class MyApp(stage: Stage) extends RouteNode(stage) {
.and(get("/it's\" tricky", (r) => Response.view(new MainView)))
.filter(DevFilter.create)
.filter(StatisticsFilter.create)
)
}


// addTransition{ case (null,view2,true ) => PageTransition.InstantTransition }
// addTransition{ case (view,view2,true ) => PageTransition.MoveDown }
// addTransition{ case (view,view2,false) => PageTransition.MoveUp }
}

class Header(view: View, sessionManager: SessionManager) extends HBox {
Expand Down Expand Up @@ -368,15 +368,3 @@ class ParalaxPage extends Page {

}



object TestWebApplication extends App
@SimpleFXApp class TestWebApplication {
val app = new MyApp(stage)
if(WebAPI.isBrowser) {
root = app
} else {
scene = new Scene(app, 1400,800)
}
app.start(SessionManager.getDefault(app,stage))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package example.scala

import example.colors.{ColorsApp, ColorsHTTP}
import one.jpro.platform.routing.Route
import one.jpro.platform.routing.server.RouteHTTP


object TestWebApplicationHTTP {
def main(args: Array[String]): Unit = {
new TestWebApplicationHTTP().start()
}
}
class TestWebApplicationHTTP extends RouteHTTP {

override def getRoute: Route = {
new TestWebApplication().createRoute()
}

}

0 comments on commit d4939da

Please sign in to comment.