From 59ecbf0274f56be2ddedf3356018afef3adf57d3 Mon Sep 17 00:00:00 2001 From: joeshaw Date: Wed, 6 Dec 2006 20:32:48 +0000 Subject: [PATCH] Added Scribus filter from Alexander Macdonald --- Filters/AssemblyInfo.cs | 1 + Filters/FilterScribus.cs | 125 +++++++++++++++++++++++++++++++++++++++++++++++ Filters/Makefile.am | 3 +- 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 Filters/FilterScribus.cs diff --git a/Filters/AssemblyInfo.cs b/Filters/AssemblyInfo.cs index 9ccac156..10279980 100644 --- a/Filters/AssemblyInfo.cs +++ b/Filters/AssemblyInfo.cs @@ -81,6 +81,7 @@ using Beagle.Filters; typeof(FilterRuby), typeof(FilterScheme), typeof(FilterScilab), + typeof(FilterScribus), typeof(FilterShellscript), typeof(FilterSpreadsheet), typeof(FilterSvg), diff --git a/Filters/FilterScribus.cs b/Filters/FilterScribus.cs new file mode 100644 index 00000000..98fa2e28 --- /dev/null +++ b/Filters/FilterScribus.cs @@ -0,0 +1,125 @@ +// +// FilterScribus.cs +// +// Copyright (C) 2006 Alexander Macdonald +// + +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// + +using System; +using System.IO; +using System.Xml; +using System.Text; + +using Beagle.Util; +using Beagle.Daemon; + +namespace Beagle.Filters { + public class FilterScribus : Beagle.Daemon.Filter { + // These two arrays contain the mapping from attributes in a scribus + // file to actual beagle property names + private static string[] scribus_attributes = { "TITLE", "KEYWORDS", "COMMENTS", "DOCSOURCE", "DOCCONTRIB", "DOCRELATION", "DOCIDENT", "PUBLISHER", "AUTHOR", "DOCCOVER", "DOCRIGHTS" }; + private static string[] scribus_properties = { "dc:title", "dc:keywords", "dc:description", "fixme:source", "dc:contributers", "fixme:relation", "dc:identifier", "dc:publisher", "dc:author", "fixme:coverage", "dc:rights" }; + + private StringBuilder sb = new StringBuilder(); + + public FilterScribus () + { + AddSupportedFlavor (FilterFlavor.NewFromMimeType ("application/x-scribus")); + AddSupportedFlavor (FilterFlavor.NewFromExtension (".sla")); + } + + override protected void DoPullProperties () + { + XmlTextReader reader = new XmlTextReader (Stream); + + string text = ""; + int pagecount = 0; + + bool join_text_mode = false; + + try { + while (reader.Read ()) { + switch (reader.NodeType) { + case XmlNodeType.Element: + switch (reader.LocalName) { + case "SCRIBUSUTF8": + join_text_mode = true; + AddProperty (Property.New ("fixme:scribus-version" , reader.GetAttribute("Version"))); + break; + case "SCRIBUSUTF8NEW": + AddProperty (Property.New ("fixme:scribus-version" , reader.GetAttribute("Version"))); + break; + case "DOCUMENT": + for (int i=0; i