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.
|Using Django and MongoDB to Build a Blog||Mar 05, 2014|
|What virtualization solution do you use/manage at work?||Mar 04, 2014|
|Our Assignment||Mar 04, 2014|
|March 2014 Issue of Linux Journal: 20 Years of Linux Journal||Mar 03, 2014|
|Have Resume - Will Travel||Feb 28, 2014|
|March 2014 Video Preview||Feb 28, 2014|
- Using Django and MongoDB to Build a Blog
- Our Assignment
- Sign Up to Win a Silicon Mechanics Swag Pack!
- March 2014 Issue of Linux Journal: 20 Years of Linux Journal
- RSS Feeds
- Have Resume - Will Travel
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- Zedge, for All Your Annoying Ringtones!
- You have to be careful there
1 week 2 days ago
- Wonder when LJ is going to
1 week 3 days ago
- Puerto Rico Free Software
1 week 4 days ago
1 week 5 days ago
- I hate voice commands
1 week 6 days ago
- usabilty --- AGAIN with this nonsense
1 week 6 days ago
- Don't make excuses
1 week 6 days ago
- Sorry to let you know, but
1 week 6 days ago
- Ridiculous statement. Not a
2 weeks 9 hours ago
2 weeks 13 hours ago