4 // Copyright (C) 2006 Alexander Macdonald <alex@alexmac.cc>
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
35 namespace Beagle
.Filters
{
36 public class FilterScribus
: Beagle
.Daemon
.Filter
{
37 // These two arrays contain the mapping from attributes in a scribus
38 // file to actual beagle property names
39 private static string[] scribus_attributes
= { "TITLE", "KEYWORDS", "COMMENTS", "DOCSOURCE", "DOCCONTRIB", "DOCRELATION", "DOCIDENT", "PUBLISHER", "AUTHOR", "DOCCOVER", "DOCRIGHTS" }
;
40 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" }
;
42 private StringBuilder sb
= new StringBuilder();
44 public FilterScribus ()
46 AddSupportedFlavor (FilterFlavor
.NewFromMimeType ("application/x-scribus"));
47 AddSupportedFlavor (FilterFlavor
.NewFromExtension (".sla"));
50 override protected void DoPullProperties ()
52 XmlTextReader reader
= new XmlTextReader (Stream
);
57 bool join_text_mode
= false;
60 while (reader
.Read ()) {
61 switch (reader
.NodeType
) {
62 case XmlNodeType
.Element
:
63 switch (reader
.LocalName
) {
65 join_text_mode
= true;
66 AddProperty (Property
.New ("fixme:scribus-version" , reader
.GetAttribute("Version")));
68 case "SCRIBUSUTF8NEW":
69 AddProperty (Property
.New ("fixme:scribus-version" , reader
.GetAttribute("Version")));
72 for (int i
=0; i
<scribus_attributes
.Length
; i
++) {
73 text
= reader
.GetAttribute(scribus_attributes
[i
]);
75 AddProperty (Property
.New (scribus_properties
[i
] , text
));
78 // treat the DOCDATE attribute in a special way
79 text
= reader
.GetAttribute("DOCDATE");
82 AddProperty (Property
.NewDate ("dc:date", System
.Convert
.ToDateTime (text
)));
83 } catch (FormatException
) {
84 AddProperty (Property
.New ("dc:date", text
));
89 text
= reader
.GetAttribute("CH");
97 AppendStructuralBreak ();
105 case XmlNodeType
.Comment
:
106 AppendText (reader
.Value
.Trim ());
107 AppendStructuralBreak ();
112 AddProperty (Property
.New ("fixme:pagecount", "" + pagecount
));
115 AppendText (sb
.ToString());
118 } catch (System
.Xml
.XmlException e
) {
119 Logger
.Log
.Error ("Error parsing xml file {0}", FileInfo
.FullName
);
120 Logger
.Log
.Debug (e
);