Lodahl's blog: Lorem Ipsum
Showing posts with label Lorem Ipsum. Show all posts
Showing posts with label Lorem Ipsum. Show all posts

03 December 2013

LibreOffice now has a built in XML-parser

LibreOffice is using a XML based document format so of cause there is a built in XML parser. But until now it has been quite cumbersome to deal with XML in macros. You need to manually traverse through the entire XML structure like this example (thanks to Andrew Pitonyak):

Function CreateDocumentHandler()
oDocHandler = CreateUnoListener( "DocHandler_", "com.sun.star.xml.sax.XDocumentHandler" )
glLocatorSet = False
CreateDocumentHandler() = oDocHandler
End Function

'==================================================
' Methods of our document handler call these
' global functions.
' These methods look strangely similar to
' a SAX event handler. ;-)
' These global routines are called by the Sax parser
' as it reads in an XML document.
' These subroutines must be named with a prefix that is
' followed by the event name of the com.sun.star.xml.sax.XDocumentHandler interface.
'==================================================

Sub DocHandler_characters( cChars As String )

if xNode = "lipsum" then
oWrite=1
cChars= Left(cChars,len(cChars)-1)
if len(cChars)>1 then
cChars= cChars+ Chr$(13)
else
cChars=cChars
endif
WriteLoremipsum (cChars, oWrite)
Else oWrite=0
Endif
End Sub

Sub DocHandler_ignorableWhitespace( cWhitespace As String )
End Sub

Sub DocHandler_processingInstruction( cTarget As String, cData As String )
End Sub

Sub DocHandler_startDocument()
End Sub

Sub DocHandler_endDocument()
End Sub

Sub DocHandler_startElement( cName As String, oAttributes As com.sun.star.xml.sax.XAttributeList )
xNode = cName
End Sub

Sub DocHandler_endElement( cName As String )
End Sub

Sub DocHandler_setDocumentLocator( oLocator As com.sun.star.xml.sax.XLocator )
' Save the locator object in a global variable.
' The locator object has valuable methods that we can
' call to determine
goLocator = oLocator
glLocatorSet = True
End Sub

This example above is from the extension Lorem Ipsum generator that you can download from here: http://extensions.libreoffice.org/extension-center/magenta-lorem-ipsum-generator

But now its much easier as LibreOffice 4.2 comes with two new spreadsheet functions called WEBSERVICE and FILTERXML. In a macro it is possible to call and use such built in spreadsheet functions even when you are working with text documents.

The example below does pretty much the same as the one above

Sub Main
svc = createUnoService( "com.sun.star.sheet.FunctionAccess" ) 'Create a service to use Calc functions
XML_String = svc.callFunction("WEBSERVICE",array("http://www.lipsum.com/feed/xml?amount=2&what=paras&start=Yes"))
Lipsum = svc.callFunction("FILTERXML", array(XML_String, "/feed/lipsum" ))
Print Lipsum
End Sub

I'm really looking forward play around with these nifty little features in Calc.

09 April 2012

The task panel in LibreOffice

LibreOffice has a very little known feature called the task pane. You might already be familiar with the navigator and the Styles and formatting dialogues. These dialogues are dockable whitch means that you can glue the dialogues to the border of the LibreOffice window.

It is however possible to create your own dockable dialogues. The dialogue becomes dockable through the so called task panel.

The task panel is only visible when you actively choose to show it and besides that you can only show it if it has content. In the view menu you might find the menu item “Task panel”. But as mentioned its only present in the menu if the task panel has an active content. When its visible it can be docked to one of the sides of the window or it can be floating. You can move it around and put it where you find it best for you.

In my case I have transformed an existing extension – the “Lorem Ipsum Generator” to show up in the task panel. As the task panel has a very little prominent occurrence in LibreOffice I decided to keep the Lorem Ipsum icon in the tool bar but now it only toggles the task panel on and off.

The result is that the tool becomes available at all times. Not open and close the dialogue any more. Just put the cursor wherever you want some dummy text and click the button in the task panel.

Usability

In the discussion about usability and “the new GUI” I think this could be the beginning. Of course the whole concept must have an overhaul as there are still some problems. First of all I don't think it's possible to use a localizable dialogue in the task panel. Therefore I had to keep the dialoque in English only but I hope that this will be only for a short time until I find out how to localize it. Another problem is that its not a trivial task to transform a dialogue into a a task panel item. I don't even think its possible to do with basic alone. i think it should be possible to generate an extension with dockable dialogues as its possible to generate extensions with the extension packager.

Anyway. I believe that the task panel could easily become a very important step into a new GUI. Not alone but followed by other efforts. Also we need to discuss if some of the existing built in dialogues in LibreOffice could easily be transformed into dockable tools. One thing I personally would like to see is the word count dialogue made dockable. Since 3.5 this dialogue has been modal witch means that it can be open while you type. It would be an obvious decision to put that dialogue in the dock.

What do you think? Would it be a good idea to continue to work on the task panel idea?

If you want to try my extension you can find it here: http://dl.dropbox.com/u/9348527/LoremIpsum.oxt but please have in mind that its not yet completely finished.

08 July 2009

Lorem Ipsum 1.6.0

I have handed over the Lorem Ipsum extension to Magenta ApS. I am still the one working with it, so no change there.

I have just uploaded a new version now with 22 languages: Turkish, Indonesian, Arab, Dutch (Netherlands), Dutch (Belgium), Portuguese, Russian, Hungarian, Japanese, Spanish, Czech, German, Serbian (Cyrillic), Serbian (Latin), Romanian, Norwegian bokmål, Italian, Polish, Swedish, French, English and Danish.

Also th problem that the extension writes to (and overwrites) the status bar is fixed. You can download it here: http://extensions.services.openoffice.org/project/Magenta_Lorem_ipsum_generator

03 March 2009

Translating OpenOffice.org extensions

One very important feature in OpenOffice.org is the ability to extend the functionality of the program with extensions. Most public extensions can be found in the official extension repository here: http://extensions.services.openoffice.org/.

It is very important for the community, that as many extensions as possible are localized or translated into as many languages as possible. There is a tool for translation in the form of an extension. You can find it here: http://extensions.services.openoffice.org/project/extension-translator. When you have installed this extension, you can translate all other extensions that you have installed. You just have to remember to return the translated file to the original developer.

I though find this a little too technical.

I tried to find another way that makes it more easy for the end user to submit a translation. I own an extension called Lorem Ipsum Generator. You can find it here: http://extensions.services.openoffice.org/project/Lorem_ipsum_generator. And I would very much like it to be translated into more languages. I have created a Form on Google Docs, where you can fill in the translated strings and then submit it directly to me. You can find the form here: http://spreadsheets.google.com/viewform?formkey=cEhWWTVMUmRFdmpSR0NtQjVEM1FTUGc6MA..

The extension Lorem Ipsum Generator is so far in English, Danish and Italian. Please provide me with more translations.

01 March 2009

Lorem Ipsum Generator now in italian

Thanks to Maurizio Salzano the extension is now also localized into italian.

http://extensions.services.openoffice.org/project/Lorem_ipsum_generator

06 December 2008

Extension: Lorem ipsum

This free extension generates Lorem ipsum dummy text from www.lipsum.com. I made this one my self by the way.

When you install this extension you will se another icon in the icon bar. Click the icon and you will see a dialog, where you can select how much Lorem Ipsum text you want. Select a number and select paragraph, words, bytes or list.

You can also choose if your tex should begin with 'Lorem ipsum dolor ...'


This screen shot is in Danish, but if you are using another language, you will see the English version.

Using this extension requires access to the Internet because the text is provided by a service from http://www.lipsum.com. The extension itself doesn't contain any Lorem Ipsum text.

The result will be some text that has no meaning, but can be used e.g. to test a template or to show a brochure without any content.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut adipiscing mauris. Etiam aliquam eros sed nisl. Praesent sapien. Quisque fermentum varius nulla. Praesent erat pede, facilisis sed, euismod eget, euismod at, dui. Duis elementum rhoncus risus. Pellentesque blandit, mi et volutpat aliquam, est justo vehicula lectus, vitae porttitor arcu mi et erat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In adipiscing sem eu ipsum. In pretium risus eu magna. Donec porttitor eleifend magna. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque sagittis cursus lorem. Aenean vel risus. Etiam pretium. Morbi nibh. Cras magna dui, volutpat et, elementum sit amet, vulputate sed, sapien. Vestibulum volutpat gravida eros. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec tristique ligula at nisl

I created this extension when I was investigating the phenomenon a couple of years ago. I used this as a showcase. Later on, I found that this extra little action button in OpenOffice.org Writer is rather valuable to me.

16 September 2008

I made a small update to my first (and so far only) openoffice.org Extension Lorem Ipsum Generator extensions.services.openoffice.org/project/Lorem_ipsum_generator.

This small nifty extension shows as an extra icon in Writer. With a click, you can fetch a piece of true Lorem Ipsum text from www.lipsum.com.

This time I added some error handling to prevent the macro to stop (and show the Basic IDE) if the user don't have access to the internet or if he website www.lipsum.com is down.

24 August 2008

Generate Lorem Ipsum dummy text in OpenOffice.org

Some time ago I made a new version of my Lorem Ipsum Generator extension for OpenOffice.org. You can find it here: http://extensions.services.openoffice.org/project/Lorem_ipsum_generator.

It's actually not rocket science. The extension calls a website that returns a piece of dummy text and puts it in you document. Lorem Ipsum text is a nice thing, if you are making a template or a document but doesn't yet have the actual text content. You will then use the dummy text to fill out your template or document to see how it looks.
News in this version:

  • Paragraphs are actual paragraphs and nit just a linebreak
  • The dialog is ajusted and looks nicer
  • Localized English and Danish. Please contact me if you would like to translate it int
Here is a few screenshots:







The extension was even refered to by SoftPedia Here: http://www.softpedia.com/get/Office-tools/Other-Office-Tools/Lorem-ipsum-generator.shtml

03 October 2007

Extending OpenOffice.org

Sorry, I have been away from my blog for a few days.

This summer I wrote a Danish manual about extensions and how to create and maintain extensions( http://doc.oooforum.dk/Extensions.pdf ). When I wrote the manual, I used both the wiki on http://www.OpenOffice.org : http://wiki.services.openoffice.org/wiki/Extensions . I also used two articles by Dimitri Popov (http://www.linuxjournal.com/article/7802 and http://www.linuxjournal.com/article/9412).

Dimitri is using an example in his article, where he is creating dummy text with Lorem Ipsum. I remember, that it was annoying that the example was masde as a mock up as example and didn't actually create Lorem Ipsum text. I know that this was not the purpose of the article, but I was still thinking: "Why not do it ?".

I have never made a macro in OpenOffice.org before, so I took this as a challenge. I had to find out everything from the beginning and I has some difficulties extracting data from the XML stream. The solution is a little clumsy, I will admit that. If any of you know a better and more elegant way, please feel free to make a new macro.

There is still a few other issues , but I expect to get them solved over the next few weeks.

I have uploaded the solution as extension to the repository, but it's actually not published yet. You can find the odt-file here: http://extensions.services.openoffice.org/download/288

When you have installed the extension, you will see a new tool bar with a button. This button will call http://www.lipsum.com/ give you some dummy text. Not rocket science, but anyway a helpfull feature.

Thanks to DannyB for this description of how to parse an XML stream http://www.oooforum.org/forum/viewtopic.phtml?t=4907 and to Andrew Pitonyak for his dokumentation "Useful Macro Information".