Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
45
Issues
45
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
ae524bf0
Commit
ae524bf0
authored
Jan 29, 2016
by
Alexander Basov
Committed by
Matija Obreza
Feb 02, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feature #28109 Genesys documentation pages (WAR)
parent
6b0dec29
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
20 deletions
+23
-20
pom.xml
pom.xml
+1
-0
src/main/java/org/genesys2/server/servlet/controller/AsciiDocController.java
...enesys2/server/servlet/controller/AsciiDocController.java
+22
-20
No files found.
pom.xml
View file @
ae524bf0
...
...
@@ -685,6 +685,7 @@
</executions>
<configuration>
<sourceDirectory>
src/main/asciidoc
</sourceDirectory>
<outputDirectory>
${project.build.outputDirectory}/docs
</outputDirectory>
<preserveDirectories>
true
</preserveDirectories>
<headerFooter>
true
</headerFooter>
<numbered>
true
</numbered>
...
...
src/main/java/org/genesys2/server/servlet/controller/AsciiDocController.java
View file @
ae524bf0
package
org.genesys2.server.servlet.controller
;
import
org.apache.commons.io.IOUtils
;
import
org.genesys2.spring.ResourceNotFoundException
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
org.jsoup.nodes.Element
;
...
...
@@ -10,26 +11,30 @@ import org.springframework.web.bind.annotation.PathVariable;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URL
;
@Controller
@RequestMapping
(
"/doc"
)
public
class
AsciiDocController
extends
BaseController
{
private
static
final
String
GENERATED_DOCS_DIR
=
"/generated-docs/"
;
private
static
final
String
GENERATED_DOCS_SECTIONS_DIR
=
"sections/"
;
private
static
final
String
DOCS_DIR
=
"/docs/"
;
private
static
final
String
DOCS_SECTIONS_DIR
=
"sections/"
;
private
static
final
String
DOCS_IMAGES_DIR
=
"images/"
;
private
static
final
String
HTML_EXTENSION
=
".html"
;
private
static
final
String
PNG_EXTENSION
=
".png"
;
@RequestMapping
(
"/0/{documentName}"
)
public
String
viewDoc
(
ModelMap
model
,
@PathVariable
(
value
=
"documentName"
)
String
documentName
)
throws
IOException
{
String
docPath
=
getDocPathByName
(
documentName
,
HTML_EXTENSION
);
ClassLoader
classLoader
=
this
.
getClass
().
getClassLoader
();
String
docPath
=
new
StringBuilder
(
DOCS_DIR
).
append
(
documentName
)
.
append
(
HTML_EXTENSION
).
toString
();
InputStream
resourceStream
=
classLoader
.
getResourceAsStream
(
docPath
);
if
(
resourceStream
==
null
)
{
throw
new
ResourceNotFoundException
();
}
InputStream
resourceStream
=
new
FileInputStream
(
docPath
);
String
html
=
IOUtils
.
toString
(
resourceStream
);
Document
document
=
Jsoup
.
parse
(
html
);
...
...
@@ -61,25 +66,22 @@ public class AsciiDocController extends BaseController {
@RequestMapping
(
"/0/sections/{documentName}"
)
public
String
viewSection
(
ModelMap
model
,
@PathVariable
(
value
=
"documentName"
)
String
documentName
)
throws
IOException
{
return
viewDoc
(
model
,
GENERATED_DOCS_SECTIONS_DIR
+
documentName
);
String
docPath
=
new
StringBuilder
(
DOCS_SECTIONS_DIR
).
append
(
documentName
).
toString
();
return
viewDoc
(
model
,
docPath
);
}
@RequestMapping
(
"/0/images/{imageName}"
)
@ResponseBody
public
byte
[]
getImage
(
@PathVariable
(
value
=
"imageName"
)
String
imageName
)
throws
IOException
{
String
imagePath
=
getDocPathByName
(
"images/"
+
imageName
,
PNG_EXTENSION
);
InputStream
inputStream
=
new
FileInputStream
(
imagePath
);
return
IOUtils
.
toByteArray
(
inputStream
);
}
ClassLoader
classLoader
=
this
.
getClass
().
getClassLoader
();
String
imgPath
=
new
StringBuilder
(
DOCS_DIR
).
append
(
DOCS_IMAGES_DIR
)
.
append
(
imageName
).
append
(
PNG_EXTENSION
).
toString
();
private
String
getDocPathByName
(
String
documentName
,
String
extension
)
{
URL
classesFolderURL
=
this
.
getClass
().
getProtectionDomain
()
.
getCodeSource
().
getLocation
();
File
classesFolderFile
=
new
File
(
classesFolderURL
.
getPath
());
String
targetFolderName
=
classesFolderFile
.
getParent
();
InputStream
inputStream
=
classLoader
.
getResourceAsStream
(
imgPath
);
if
(
inputStream
==
null
)
{
throw
new
ResourceNotFoundException
();
}
return
targetFolderName
+
GENERATED_DOCS_DIR
+
documentName
+
extension
;
return
IOUtils
.
toByteArray
(
inputStream
)
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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