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
);
54 string text
= String
.Empty
;
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
]);
74 AddProperty (Property
.New (scribus_properties
[i
] , text
));
77 // treat the DOCDATE attribute in a special way
78 text
= reader
.GetAttribute("DOCDATE");
81 AddProperty (Property
.NewDate ("dc:date", System
.Convert
.ToDateTime (text
)));
82 } catch (FormatException
) {
83 AddProperty (Property
.New ("dc:date", text
));
88 text
= reader
.GetAttribute("CH");
96 AppendStructuralBreak ();
104 case XmlNodeType
.Comment
:
105 AppendText (reader
.Value
.Trim ());
106 AppendStructuralBreak ();
111 AddProperty (Property
.New ("fixme:pagecount", pagecount
.ToString ()));
114 AppendText (sb
.ToString());
117 } catch (System
.Xml
.XmlException e
) {
118 Logger
.Log
.Error ("Error parsing xml file {0}", FileInfo
.FullName
);
119 Logger
.Log
.Debug (e
);