Virtual Filesystems Are Virtual Office Documents
Listing 7. Allowing a User to Use FUSE on Fedora Core
root-bash-# usermod -a -G fuse ben
An example of setting up a little PostgreSQL table and creating a new virtual office document to allow editing this table is shown in Listing 8.
Listing 8. Setting Up a Virtual Office Document to Edit a Database Table
bash-$ psql ben=# create database lj; ben=# \c lj; You are now connected to database "lj". lj=# create table msgs lj-# ( id serial primary key, lj-# num int, msg varchar(200), lj-# foo varchar(100) ); lj=# insert into msgs values lj-# ( default, 7, 'This is msg #1', 'Foo is Bar'); lj=# insert into msgs values lj-# ( default, 12, 'Second message', 'ii tenki'); lj=# select * from msgs; id | num | msg | foo ----+-----+----------------+------------ 1 | 7 | This is msg #1 | Foo is Bar 2 | 12 | Second message | ii tenki (2 rows) \q bash-$ ferrisls pg://localhost/lj msgs bash-$ ferrisls --xml pg://localhost/lj/msgs <ferrisls> <ferrisls url="pg:///localhost/lj/msgs" name="msgs"> <context id="1" num="7" msg="This is msg #1" foo="Foo is Bar" name="1" primary-key="id" /> <context id="2" num="12" msg="Second message" foo="ii tenki" name="2" primary-key="id" /> </ferrisls> </ferrisls> bash-$ ferris-filesystem-to-xsltfs-sheets \ --plugin excel2003 --fuse msgs \ pg://localhost/lj/msgs bash-$ ferrisls -lh ~/ferrisfuse ... ben ben 129 06 Oct 21 11:56 mount-msgs.sh ... ben ben 4.0k 06 Oct 21 11:56 msgs bash-$ cd ~/ferrisfuse/ bash-$ ./mount-msgs.sh bash-$ ls -lh msgs ... 0 ben ben 3.8K Jan 1 1970 msgs.xml* bash-$ cat msgs/msgs.xml | head <?xml version="1.0" encoding="UTF-8" ... ?> <Workbook xmlns=...> <OfficeDocumentSettings xmlns=...> <Colors> ... bash-$ ooffice msgs/msgs.xml
The final command in Listing 8 opens the virtual spreadsheet document, which should look similar to Figure 1. I then changed some data in the second row and saved the file giving the result shown in Figure 2.
Looking at the PostgreSQL table after saving the virtual office document shows the updated contents—see Listing 9.
Listing 9. The Contents of the Database after Editing with OpenOffice.org
bash-$ psql lj lj=# select * from msgs; id | num | msg | foo ----+-----+----------------+----------------------- 1 | 7 | This is msg #1 | Foo is Bar 2 | 23 | Second message | The weather outside... (2 rows)
The ferris-mount-etagere-as-kml.sh script uses xsltfs:// and FUSE to set up a read/write virtual KML file. The stylesheets translate between libferris geoemblems and the KML format for place names used by Google Earth.
The stylesheets used to expose libferris emblems provide an example of translating a whole tree in libferris into a hierarchical XML document for an external application to use. The is-dir EA from the input filesystem is used to determine the type of XML element to generate in the translated filesystem, as KML files require the use of Placemark or Folder elements depending on whether children are to be found.
For testing purposes, if the LIBFERRIS_XSLTFS_DONT_UPDATE environment variable is set, libferris performs the reverse stylesheet application and logs what updates would have been done but does not actually update the input filesystem.
There are a few hints that can make setting up and adjusting custom forward and reverse stylesheets much simpler.
I use the example.xml file shown in Listing 1 again here as the input filesystem. Although in this example, I am starting with example.xml, which is an XML file, we want to see how libferris sees this input filesystem, not only the raw XML itself. For example, the contents of an elements text nodes will be available as the content attribute when libferris mounts this XML file.
To get at the libferris view of the XML, I use ferrisls with its --xml-xsltfs-debug option. I also need to recurse the example.xml file to get the whole filesystem and explicitly select any attributes that the example.xsl file will want to use.
The manual application of a forward stylesheet is shown in Listing 10.
The reverse stylesheet can be applied to the translated filesystem XML file. Once this output looks sane, non-destructive testing can be done by applying it through xsltfs:// with LIBFERRIS_XSLTFS_DONT_UPDATE set. Make sure ferris-logging-xsltfs is set to debug in the ferris-capplet-logging configuration tool to get all the information about what would have been updated.
|Bitcoin on Amazon! Sort of...||Sep 28, 2016|
|Free Today: September Issue of Linux Journal (Retail value: $5.99)||Sep 27, 2016|
|nginx||Sep 27, 2016|
|Epiq Solutions' Sidekiq M.2||Sep 26, 2016|
|Nativ Disc||Sep 23, 2016|
|Android Browser Security--What You Haven't Been Told||Sep 22, 2016|
- Free Today: September Issue of Linux Journal (Retail value: $5.99)
- Bitcoin on Amazon! Sort of...
- Android Browser Security--What You Haven't Been Told
- Epiq Solutions' Sidekiq M.2
- The Many Paths to a Solution
- Readers' Choice Awards 2013
- Nativ Disc
- Identity: Our Last Stand
- Tech Tip: Really Simple HTTP Server with Python
Pick up any e-commerce web or mobile app today, and you’ll be holding a mashup of interconnected applications and services from a variety of different providers. For instance, when you connect to Amazon’s e-commerce app, cookies, tags and pixels that are monitored by solutions like Exact Target, BazaarVoice, Bing, Shopzilla, Liveramp and Google Tag Manager track every action you take. You’re presented with special offers and coupons based on your viewing and buying patterns. If you find something you want for your birthday, a third party manages your wish list, which you can share through multiple social- media outlets or email to a friend. When you select something to buy, you find yourself presented with similar items as kind suggestions. And when you finally check out, you’re offered the ability to pay with promo codes, gifts cards, PayPal or a variety of credit cards.Get the Guide