Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
69 src/main/webapp/attach.groovy
@@ -1,69 +0,0 @@
-import java.security.MessageDigest;
-
-import javax.jcr.Value;
-
-import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.fileupload.disk.DiskFileItemFactory;
-import org.apache.commons.fileupload.servlet.ServletFileUpload
-
-if (request.method != 'POST') {
- request.getRequestDispatcher("view.html").forward(request, response)
-}
-
-if (ServletFileUpload.isMultipartContent(request)) {
- // Create a new file upload handler
- ServletFileUpload upload = [new DiskFileItemFactory()]
-
- def node
- def items = upload.getItemIterator(request)
- while (items.hasNext()) {
- def item = items.next()
- if (item.formField && item.fieldName == 'p') {
- node = context.getAttribute('jcr').getNode(item.openStream().text)
- }
- else {
- def digest = MessageDigest.getInstance('md5')
- def binary = node.session.valueFactory.createBinary(item.openStream())
-// item.openStream().with {
- binary.stream.with {
- byte[] data = new byte[8192]
- int bytesRead
- while ((bytesRead = read(data)) >= 0) {
- digest.update data, 0, bytesRead
- }
- }
- def checksum = new String(Hex.encodeHex(digest.digest()))
-
- def attachNode = node.session.rootNode << 'mn:attachments'
- checksum.split(/(?<=\G.{2})/).each {
- attachNode = attachNode << it
- }
- if (attachNode.isNew()) {
-// println "Creating node: $attachNode.path"
- attachNode.addMixin('mix:referenceable')
- attachNode.session.save {
-// attachNode['jcr:content'] = attachNode.session.valueFactory.createBinary(item.openStream())
- attachNode['jcr:content'] = binary
- }
- }
-
- if (node) {
- node.session.save {
- def attachments = node << 'mn:attachments'
- attachments[item.name] = attachNode
- }
-// attachments = node.attachments.values as List
-// }
-// else {
-// attachments = []
-// }
-// attachments << node.session.valueFactory.createValue(attachNode)
-//
-// node.session.save {
-// node['attachments'] = attachments as Value[]
-// }
- }
- }
- }
- response.sendRedirect("view.html?p=$node.path")
-}
View
7 src/main/webapp/download.groovy
@@ -1,7 +0,0 @@
-if (request.getParameter('p')) {
- def node = context.getAttribute('jcr').getNode(request.getParameter('p'))
-// response.contentType = ''
- response.setHeader('Content-Disposition', "attachment;filename=${request.getParameter('f')}")
- sout << node['jcr:content'].binary.stream
-// sout << node['jcr:content'].binary.stream.bytes
-}
View
53 src/main/webapp/edit.html
@@ -1,53 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<%
- def parent
- if (request.getParameter('p')) {
- parent = context.getAttribute('jcr').getNode(request.getParameter('p'))
- }
- else {
- parent = context.getAttribute('jcr').rootNode
- }
- def node
- if (request.getParameter('c')) {
- def title = request.getParameter('c')
- node = parent << title
- node['title'] = title
- }
- else {
- node = parent
- }
-%>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-<title>${node.title.string} - Miniki</title>
-</head>
-<body>
-<h2 style="color:lightgray">
-<%
- def breadcrumb
- breadcrumb = { n ->
- if (!n.parent.isSame(n.session.rootNode)) {
- breadcrumb(n.parent)
- }
- out << ' &raquo '
- html.a(href: "view.html?p=$n.path", style: 'color:gray', n.title.string)
- }
- breadcrumb(node)
-%>
-</h2>
-<form action="save.groovy" method="post">
- <input type="hidden" name="p" value="<% out << node.path%>"/>
- <input type="text" name="t" value="<% out << node.title?.string %>"/><br/>
- <textarea rows="4" cols="20" name="txt">${node.text?.string}</textarea><br/>
- <input type="submit" value="Save">
- <a href='view.html?p=<% out << node.path%>'>Cancel</a>
-</form>
-<% node.nodes.each {
- if (it.name != 'mn:attachments') { %>
- <a href='view.html?p=<% out << it.path%>'>${it.title.string}</a>
-<% }
- } %>
-
-</body>
-</html>
View
16 src/main/webapp/index.html
@@ -1,16 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-<title>Miniki</title>
-</head>
-<body>
-<h1>
-<%
- print 'test'
-%>
-</h1>
-<h2>${'another test'}</h2>
-<% html.h2('and another test') %>
-</body>
-</html>
View
11 src/main/webapp/save.groovy
@@ -1,11 +0,0 @@
-import org.apache.jackrabbit.util.Text;
-
-if (request.getParameter('p')) {
- def node = context.getAttribute('jcr').getNode(request.getParameter('p'))
- node.session.save {
- node['title'] = Text.escapeIllegalJcrChars(request.getParameter('t'))
- node['text'] = request.getParameter('txt')
- }
-}
-
-request.getRequestDispatcher("view.html").forward(request, response)
View
28 src/main/webapp/search.groovy
@@ -1,28 +0,0 @@
-import org.mnode.juicer.query.QueryBuilder
-
-if (request.getParameter('q')) {
- def jcr = context.getAttribute('jcr')
- def searchQuery = new QueryBuilder(jcr.workspace.queryManager, jcr.valueFactory).with {
- query(
- source: selector(nodeType: 'nt:unstructured', name: 'items'),
- constraint: and(
- constraint1: descendantNode(selectorName: 'items', path: '/mn:content'),
- constraint2: fullTextSearch(selectorName: 'items', propertyName: 'text', searchTerms: request.getParameter('q'))
- )
- )
- }
- request.setAttribute('query', searchQuery)
-
- def attachSearchQuery = new QueryBuilder(jcr.workspace.queryManager, jcr.valueFactory).with {
- query(
- source: selector(nodeType: 'nt:unstructured', name: 'items'),
- constraint: and(
- constraint1: descendantNode(selectorName: 'items', path: '/mn:attachments'),
- constraint2: fullTextSearch(selectorName: 'items', propertyName: 'jcr:content', searchTerms: request.getParameter('q'))
- )
- )
- }
- request.setAttribute('attachQuery', attachSearchQuery)
-}
-
-request.getRequestDispatcher("search.html").forward(request, response)
View
26 src/main/webapp/search.html
@@ -1,26 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-<title>Search - Miniki</title>
-</head>
-<body>
-<div style="width:100%;text-align:right">
- <form action="search.groovy">
- <input type="text" name="q"/>
- <input type="submit" value="Search"/>
- </form>
-</div>
-<%
- if (request.getAttribute('query')) {
- request.getAttribute('query').execute().nodes.each { %>
- <a href='view.html?p=<% out << it.path%>'>${it.title.string}</a>
-<% }} %>
-<%
- if (request.getAttribute('attachQuery')) {
- request.getAttribute('attachQuery').execute().nodes.each { %>
- <a href='download.groovy?p=<% out << it.path%>&f=<% out << it.title.string %>'>${it.title.string}</a>
-<% }} %>
-
-</body>
-</html>
View
68 src/main/webapp/view.html
@@ -1,68 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<% def node
- if (request.getParameter('p')) {
- node = context.getAttribute('jcr').getNode(request.getParameter('p'))
- }
- else {
- node = context.getAttribute('jcr').rootNode << 'mn:content'
- if (!node.title) {
- node.title = 'My Miniki'
- }
- } %>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
-<title>${node.title.string} - Miniki</title>
-</head>
-<body>
-<div style="width:100%;text-align:right">
- <form action="search.groovy">
- <input type="text" name="q"/>
- <input type="submit" value="Search"/>
- </form>
-</div>
-<h2 style="color:lightgray">
-<%
- def breadcrumb
- breadcrumb = { n ->
- if (!n.parent.isSame(n.session.rootNode)) {
- breadcrumb(n.parent)
- }
- out << ' &raquo '
- html.a(href: "view.html?p=$n.path", style: 'color:gray', n.title.string)
- }
- breadcrumb(node)
-%>
-<a href="edit.html?p=<% out << node.path%>" style="color:gray;vertical-align:super;font-size:0.5em">[Edit]</a>
-</h2>
-<p><pre>${node.text ? node.text.string : 'Nothing to see here'}</pre></p>
-<% node.nodes.each {
- if (it.name != 'mn:attachments') { %>
- <a href='view.html?p=<% out << it.path%>'>${it.title.string}</a>
-<% }
- else { %>
- <ul>
- <%
- it.properties.each { p ->
- if (p.type == 9) { %>
- <li><a href='download.groovy?p=<% out << p.getNode().path%>&f=<% out << p.name %>'>${p.name}</a></li>
-<%
- }
- }
- %>
- </ul>
- <%
- }
- } %>
-<form action="edit.html">
- <input type="hidden" name="p" value="<% out << node.path%>"/>
- <input type="text" name="c"/>
- <input type="submit" value="Add"/>
-</form>
-<form action="attach.groovy" enctype="multipart/form-data" method="post">
- <input type="hidden" name="p" value="<% out << node.path%>"/>
- <input type="file" name="datafile" size="40">
- <input type="submit" value="Attach"/>
-</form>
-</body>
-</html>

No commit comments for this range

Something went wrong with that request. Please try again.