Skip to content
Snippets Groups Projects
Commit 7bdf531d authored by Nikos Marinos's avatar Nikos Marinos
Browse files

some progress

parent ff4ea3fe
No related branches found
No related tags found
1 merge request!21Replace master with dev
......@@ -28,6 +28,8 @@ import PDFViewer from './pdf-viewer/PDFViewer'
import nxmlXSL from '../assets/xsl/pnihms2pmc3.xsl'
import htmlXSL from '../assets/xsl/nxml2html.xsl'
const dtdUri = 'app/assets/xsl/dtd/archivearticle3.dtd'
const PreviewPageDiv = styled(PreviewPage)`
.show-mobile {
display: none;
......@@ -144,24 +146,33 @@ const allFileTypes = XMLFileTypes.concat(
}, []),
)
const transformXML = async (xmlUri, xslUri, param) => {
const xml = await loadXML(xmlUri)
const xsl = await loadXML(xslUri)
if (typeof XSLTProcessor !== 'undefined') {
const xsltProcessor = new XSLTProcessor()
xsltProcessor.importStylesheet(xsl)
if (param) {
xsltProcessor.setParameter(null, param.name, param.value)
}
const resultDocument = await xsltProcessor.transformToDocument(
xml,
document,
)
return resultDocument
} else if (typeof xml.transformNode !== 'undefined') {
const resultDocument = await xml.transformNode(xsl)
return resultDocument
}
const transformXML = (xmlUri, dtdUri, xslUri, xslHtmlUri, param) => {
return new Promise((resolve, reject) => {
fetch('/xml/validate/api/post', {
method: 'POST',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${window.localStorage.getItem('token')}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
xmlUri,
dtdUri,
xslUri,
xslHtmlUri,
param,
}),
}).then(response => {
if (!response.ok) {
reject(response.json())
}
else {
resolve(response.json())
}
}).then(data => resolve(data))
.catch(reason => reject(reason))
})
}
const loadXML = url =>
......@@ -215,61 +226,42 @@ class EPMCTagged extends React.Component {
}
return null
}
setError(error) {
this.props.setXMLError(error, this.props.project, this.props.currentVersion)
}
async processXML() {
this.setState({ status: 'Saving...' })
const { addXMLFiles, project, currentVersion } = this.props
const { files } = currentVersion
const xml = files.find(file => file.type === 'PMC')
if (xml) {
const nxml = await transformXML(xml.url, nxmlXSL).catch(err => {
if (err) {
this.setError('XML is invalid/malformed.')
}
})
if (nxml) {
const blob = new Blob([new XMLSerializer().serializeToString(nxml)], {
type: 'text/xml',
})
const filelist = {
name: 'filelist',
value: files
.filter(
file =>
file.type === 'IMGview' ||
file.type === 'supplement_tag' ||
file.type === 'supplementary file',
)
.map(
file =>
`${file.filename.substring(
0,
file.filename.lastIndexOf('.'),
)}:/api/files/${file.url.split('/').pop()};`,
)
.join(''),
}
const html = await transformXML(
URL.createObjectURL(blob),
htmlXSL,
filelist,
).catch(err => {
if (err) {
this.setError('XML is invalid/malformed.')
}
})
const htmlBlob = new Blob([html.documentElement.outerHTML], {
type: 'text/html',
console.log('1')
transformXML(xml.url, dtdUri, nxmlXSL, htmlXSL, files)
.then (result => {
console.log('CORRECT')
const nxmlBlob = new Blob([result.nxml], {
type: 'text/xml',
})
const htmlBlob = new Blob([result.html.documentElement.outerHTML], {
type: 'text/html',
})
addXMLFiles(nxmlBlob, htmlBlob, project, currentVersion).then(() => {
this.setError('')
this.setState({ status: 'All changes saved.' })
})
})
addXMLFiles(blob, htmlBlob, project, currentVersion).then(() => {
this.setError('')
this.setState({ status: 'All changes saved.' })
.catch(async err => {
console.log('ERROR')
const error = await err
console.log(error)
this.setError(error)
this.setState({ status: 'Something went wrong.' })
})
}
}
}
render() {
const { currentVersion, currentUser, uploadFile } = this.props
const { files: allfiles, metadata, source } = currentVersion
......@@ -285,9 +277,9 @@ class EPMCTagged extends React.Component {
)
const html = files.find(file => file.type === 'tempHTML')
? `/api/files/${files
.find(file => file.type === 'tempHTML')
.url.split('/')
.pop()}`
.find(file => file.type === 'tempHTML')
.url.split('/')
.pop()}`
: null
const xmlError = metadata.notes
? metadata.notes.find(n => n.notesType === 'xml error')
......@@ -395,11 +387,11 @@ class EPMCTagged extends React.Component {
)}
{pane === 'pdf' && pdf && <PDFViewer url={pdf.url} />}
{pane === 'web' &&
html && <Iframe src={html} title="web preview" />}
html && <Iframe src={html} title="web preview" />}
{pane === 'original' &&
manuscript && (
<ManuscriptPreview file={manuscript} source={source} />
)}
manuscript && (
<ManuscriptPreview file={manuscript} source={source} />
)}
</PanelContent>
</PreviewPanel>
<EditPanel style={{ minWidth: showManuscript ? 0 : 'auto' }}>
......
......@@ -10,6 +10,7 @@ services:
# volumes:
# - ./:/home/xpub
depends_on:
- java
- postgres
- ftpd_server
- minio
......@@ -75,6 +76,20 @@ services:
- minio_config:/root/.minio
command: "server /data"
java:
image: openjdk:8-jdk-alpine
# https://hub.docker.com/_/java/
# Dockerfile : https://github.com/docker-library/openjdk/blob/master/8-jdk/alpine/Dockerfile
# volumes:
# - ${BASE_DIR}/myjava01/home/batchuser/bin:/home/batchuser/bin
# - ${BASE_DIR}/myjava01/var_log/batchuser:/var/log/batchuser
# - ${BASE_DIR}/mysftp/sshkeys/id_rsa:/home/batchuser/.ssh/id_rsa:ro
# working_dir: /home/batchuser/bin
# ports:
# HOST_OR_VM:DOCKER_CONTAINER
# command: tail -f /dev/null
command: java -version
volumes:
postgres-volume:
minio_data: {}
......
......@@ -35,6 +35,7 @@
"minio": "^6.0.0",
"moment": "^2.18.1",
"node-fetch": "^2.2.0",
"node-libxml": "^3.2.3",
"pdfjs-dist": "^2.0.489",
"prop-types": "^15.5.10",
"properties-reader": "0.0.16",
......@@ -74,7 +75,8 @@
"xpath": "0.0.27",
"xpub-journal": "^0.0.6",
"xpub-selectors": "^0.1.0",
"xpub-theme": "^0.0.7"
"xpub-theme": "^0.0.7",
"xslt4node": "^0.3.2"
},
"devDependencies": {
"babel-core": "^6.26.0",
......@@ -138,7 +140,7 @@
"reset": "pubsweet setupdb --clobber",
"start": "docker-compose up --build",
"start:production": "docker-compose -f ./docker-compose.yml -f ./docker-compose.prod.yml up --build",
"start:services": "docker-compose up postgres ftpd_server minio",
"start:services": "docker-compose up java postgres ftpd_server minio",
"start:all": "docker-compose up postgres ftpd_server minio pgadmin",
"server": "yarn seed && pubsweet server",
"build": "NODE_ENV=production pubsweet build"
......
// import {xsltProcess, xmlParse} from "xslt-processor"
const passport = require('passport')
// const Libxml = require('node-libxml')
// const config = require('config')
// const fetch = require('node-fetch')
const Libxml = require('node-libxml')
const config = require('config')
const fetch = require('node-fetch')
const xslt4node = require('xslt4node')
// const transform = xslt4node.transform;
xslt4node.addLibrary('./javaLibs/saxon9he.jar')
xslt4node.addOptions('-Xmx1g')
// const pubsweetServer = config.get('pubsweet-server.baseUrl')
const pubsweetServer = config.get('pubsweet-server.baseUrl')
const authBearer = passport.authenticate('bearer', { session: false })
/*
const fetchFile = (fileUri, token) => {
const url = `${pubsweetServer}${fileUri}`
return new Promise((resolve, reject) => {
......@@ -25,39 +30,107 @@ const fetchFile = (fileUri, token) => {
})
})
}
*/
const transformXML = (xmlString, xsltString, params) => {
let config = {
xslt: xsltString,
source: xmlString,
result: String,
params,
props: {
indent: 'yes',
},
}
return new Promise((resolve, reject) => {
xslt4node.transform(config, (err, result) => {
if (err) {
reject(result)
} else {
resolve(result)
}
})
})
try {
} catch (e) {
console.log(e)
}
}
module.exports = app => {
app.post('/xml/validate/api/post', authBearer, (req, res) => {
res.set({ 'Content-Type': 'application/json' })
/*
const libxml = new Libxml()
fetchFile(req.body.xml, req.headers.authorization)
.then(xml => {
const xmlIsWellformed = libxml.loadXmlFromString(xml)
libxml.loadDtds([req.body.dtd])
const testDefaultV = libxml.validateAgainstDtds()
if (xmlIsWellformed && testDefaultV) {
res.json('success')
} else {
res.send(
JSON.stringify(libxml.validationDtdErrors[req.body.dtd], [
'column',
'level',
'line',
'message',
]),
)
}
})
.catch(err => {
res.send(JSON.stringify(err))
fetchFile(req.body.xmlUri, req.headers.authorization).then(xml => {
fetchFile(req.body.xslUri, req.headers.authorization).then(xsl => {
fetchFile(req.body.xslHtmlUri, req.headers.authorization)
.then(xslHtml => {
const libxml = new Libxml()
const xmlIsWellformed = libxml.loadXmlFromString(xml)
libxml.loadDtds([req.body.dtdUri])
const xmlIsValid = libxml.validateAgainstDtds()
if (xmlIsWellformed && xmlIsValid) {
transformXML(xml, xsl).then(nxml => {
const nxmlIsWellformed = libxml.loadXmlFromString(nxml)
const nxmlIsValid = libxml.validateAgainstDtds()
const files = req.body.files
let filelist
if (files) {
filelist = {
name: 'filelist',
value: files
.filter(
file =>
file.type === 'IMGview' ||
file.type === 'supplement_tag' ||
file.type === 'supplementary file',
)
.map(
file =>
`${file.filename.substring(
0,
file.filename.lastIndexOf('.'),
)}:/api/files/${file.url.split('/').pop()};`,
)
.join(''),
}
}
transformXML(nxml, xslHtml, filelist).then(html =>
res.json({ nxml, html }),
)
})
} else {
if (!xmlIsWellformed) {
res
.status(400)
.json(
JSON.stringify(libxml.wellformedErrors, [
'column',
'level',
'line',
'message',
]),
)
} else if (!xmlIsValid) {
res
.status(400)
.json(
JSON.stringify(
libxml.validationDtdErrors[req.body.dtdUri],
['column', 'level', 'line', 'message'],
),
)
}
}
})
.catch(err => {
res.status(400).json(JSON.stringify(err.message))
})
})
*/
})
})
}
File added
This diff is collapsed.
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment