From 0c9b45d210a5d94b3ba219e32b73233a5a795f61 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 27 Oct 2014 23:16:15 +0100 Subject: [PATCH 1/1] Download note as XML and JSON --- appinfo/application.php | 10 ++++ appinfo/routes.php | 5 ++ controller/guicontroller.php | 10 ++++ controller/notescontroller.php | 104 +++++++++++++++++++++++++++++++++ grauphel.css | 13 +++++ lib/response/xmlresponse.php | 43 ++++++++++++++ templates/gui-note.php | 4 ++ 7 files changed, 189 insertions(+) create mode 100644 controller/notescontroller.php create mode 100644 lib/response/xmlresponse.php diff --git a/appinfo/application.php b/appinfo/application.php index 66ed557..7761eb5 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -56,6 +56,16 @@ class Application extends App ); } ); + $container->registerService( + 'NotesController', + function($c) { + return new \OCA\Grauphel\Controller\NotesController( + $c->query('AppName'), + $c->query('Request'), + $c->query('Session')->getUser() + ); + } + ); $container->registerService( 'TokenController', function($c) { diff --git a/appinfo/routes.php b/appinfo/routes.php index ddfc90b..1c7e50b 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -68,6 +68,11 @@ $application->registerRoutes( 'name' => 'gui#tag', 'verb' => 'GET', ), + array( + 'url' => '/note/{guid}.xml', + 'name' => 'notes#xml', + 'verb' => 'GET', + ), array( 'url' => '/note/{guid}', 'name' => 'gui#note', diff --git a/controller/guicontroller.php b/controller/guicontroller.php index 4f74ab5..fc97b04 100644 --- a/controller/guicontroller.php +++ b/controller/guicontroller.php @@ -96,6 +96,16 @@ class GuiController extends Controller 'note-content' => $converter->convert( $note->{'note-content'} ), + 'links' => array( + 'json' => $this->urlGen->linkToRoute( + 'grauphel.api.note', array( + 'guid' => $guid, 'username' => $this->user->getUid() + ) + ), + 'xml' => $this->urlGen->linkToRoute( + 'grauphel.notes.xml', array('guid' => $guid) + ), + ) ) ); diff --git a/controller/notescontroller.php b/controller/notescontroller.php new file mode 100644 index 0000000..02bfc93 --- /dev/null +++ b/controller/notescontroller.php @@ -0,0 +1,104 @@ + + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/grauphel.htm + */ +namespace OCA\Grauphel\Controller; + +use \OCP\AppFramework\Controller; +use \OCP\AppFramework\Http\TemplateResponse; +use \OCA\Grauphel\Lib\Client; +use \OCA\Grauphel\Lib\TokenStorage; +use \OCA\Grauphel\Lib\Response\ErrorResponse; + +/** + * Owncloud frontend: Notes + * + * @category Tools + * @package Grauphel + * @author Christian Weiske + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @version Release: @package_version@ + * @link http://cweiske.de/grauphel.htm + */ +class NotesController extends Controller +{ + /** + * constructor of the controller + * + * @param string $appName Name of the app + * @param IRequest $request Instance of the request + */ + public function __construct($appName, \OCP\IRequest $request, $user) + { + parent::__construct($appName, $request); + $this->user = $user; + + //default http header: we assume something is broken + header('HTTP/1.0 500 Internal Server Error'); + } + + /** + * Output a note in tomboy XML format + * + * @link https://wiki.gnome.org/Apps/Tomboy/NoteXmlFormat + * + * @NoAdminRequired + * @NoCSRFRequired + */ + public function xml($guid) + { + $note = $this->getNotes()->load($guid, false); + + $xw = new \XMLWriter(); + $xw->openMemory(); + $xw->startDocument('1.0', 'utf-8'); + + $xw->startElementNS(null, 'note', 'http://beatniksoftware.com/tomboy'); + $xw->writeAttribute('version', '0.3'); + $xw->writeAttribute('xmlns:link', 'http://beatniksoftware.com/tomboy/link'); + $xw->writeAttribute('xmlns:size', 'http://beatniksoftware.com/tomboy/size'); + + $xw->writeElement('title', $note->title); + $xw->startElement('text'); + $xw->writeAttribute('xml:space', 'preserve'); + + $xw->startElement('note-content'); + $xw->writeAttribute('version', $note->{'note-content-version'}); + $xw->writeRaw($note->{'note-content'}); + $xw->endElement();//note-content + $xw->endElement();//text + + $xw->writeElement('last-change-date', $note->{'last-change-date'}); + $xw->writeElement('last-metadata-change-date', $note->{'last-metadata-change-date'}); + $xw->writeElement('create-date', $note->{'create-date'}); + $xw->writeElement('cursor-position', 0); + $xw->writeElement('width', 450); + $xw->writeElement('height', 360); + $xw->writeElement('x', 0); + $xw->writeElement('y', 0); + $xw->writeElement('open-on-startup', $note->{'open-on-startup'}); + + $xw->endElement();//note + + return new \OCA\Grauphel\Response\XmlResponse($xw->outputMemory()); + } + + protected function getNotes() + { + $username = $this->user->getUid(); + $notes = new \OCA\Grauphel\Lib\NoteStorage($this->urlGen); + $notes->setUsername($username); + return $notes; + } +} +?> diff --git a/grauphel.css b/grauphel.css index 1ad5a2d..571e580 100644 --- a/grauphel.css +++ b/grauphel.css @@ -54,6 +54,19 @@ color: green; } +.app-grauphel #app-content .actions { + float: right; +} +.app-grauphel #app-content .actions a { + color: #555; + padding: 14px 10px; + position: relative; + top: 7px; + min-width: 25px; + padding: 5px; + background-color: rgba(240,240,240,.9); +} + .app-grauphel .oauth-authorize { margin: 2ex; text-align: center; diff --git a/lib/response/xmlresponse.php b/lib/response/xmlresponse.php new file mode 100644 index 0000000..050bbff --- /dev/null +++ b/lib/response/xmlresponse.php @@ -0,0 +1,43 @@ + + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/grauphel.htm + */ +namespace OCA\Grauphel\Response; + +/** + * Returns XML data + * + * @category Tools + * @package Grauphel + * @author Christian Weiske + * @copyright 2014 Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @version Release: @package_version@ + * @link http://cweiske.de/grauphel.htm + */ +class XmlResponse extends \OCP\AppFramework\Http\Response +{ + protected $xml; + + public function __construct($xml) + { + $this->setStatus(\OCP\AppFramework\Http::STATUS_OK); + $this->addHeader('Content-Type', 'text/xml; charset=utf-8'); + $this->xml = $xml; + } + + public function render() + { + return $this->xml; + } +} +?> diff --git a/templates/gui-note.php b/templates/gui-note.php index 296a0d2..fb2d741 100644 --- a/templates/gui-note.php +++ b/templates/gui-note.php @@ -6,6 +6,10 @@
+
+ JSON + XML +

title); ?>

Last modified: -- 2.30.2