override protected void DoPullProperties() { Stopwatch watch = new Stopwatch(); watch.Start(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name.StartsWith("sect") || reader.Name.StartsWith("chapter")) { string id = reader.GetAttribute("id"); if (id != null && id != String.Empty) { DocbookEntry entry = new DocbookEntry(); entry.Id = id; entry.Depth = reader.Depth; string language = reader.GetAttribute("lang"); if (language != null && language != String.Empty) { entry.Language = language; } entries_stack.Push(entry); } } else if (reader.Name == "article" || reader.Name == "book") { string language = reader.GetAttribute("lang"); if (language != null && language != String.Empty) { base_language = language; } } else if (reader.Name == "title") { reader.Read(); // Go to the text node if (entries_stack.Count == 0 && base_title == null) { // This is probably the book title base_title = reader.Value; } else if (entries_stack.Count > 0) { DocbookEntry entry = (DocbookEntry)entries_stack.Peek(); if (entry.Title == null) { entry.Title = reader.Value; } } } else if (reader.Name == "keyword") { reader.Read(); // read the text node AddProperty(Property.NewKeyword("dc:subject", reader.Value)); } break; case XmlNodeType.Text: // Append text to the child indexable if (entries_stack.Count > 0) { ((DocbookEntry)entries_stack.Peek()).Content.Append(reader.Value); } // Append text to the main indexable else { AppendWord(reader.Value); } break; case XmlNodeType.EndElement: if (entries_stack.Count > 0 && ((DocbookEntry)entries_stack.Peek()).Depth == reader.Depth) { DocbookEntry entry, parent_entry = null; entry = (DocbookEntry)entries_stack.Pop(); if (entries_stack.Count > 0) { parent_entry = (DocbookEntry)entries_stack.Peek(); } Indexable indexable; indexable = new Indexable(UriFu.AddFragment(Indexable.Uri, entry.Id, false)); indexable.HitType = "DocbookEntry"; indexable.MimeType = "text/x-docbook-entry"; indexable.AddProperty(Property.NewKeyword("beagle:FileType", "documentation")); indexable.Filtering = IndexableFiltering.AlreadyFiltered; indexable.AddProperty(Property.NewUnsearched("fixme:id", entry.Id)); indexable.AddProperty(Property.New("dc:title", entry.Title)); // Add the docbook book title indexable.AddProperty(Property.NewUnsearched("fixme:base_title", base_title)); // Add the child language (or docbook language if none is specified) if (entry.Language != null) { indexable.AddProperty(Property.NewUnsearched("fixme:language", entry.Language)); } else if (base_language != null) { indexable.AddProperty(Property.NewUnsearched("fixme:language", base_language)); } // Add any parent (as in docbook parent entry, not beagle) data if we have it if (parent_entry != null) { indexable.AddProperty(Property.NewUnsearched("fixme:parent_id", parent_entry.Id)); indexable.AddProperty(Property.NewUnsearched("fixme:parent_title", parent_entry.Title)); } StringReader content_reader = new StringReader(entry.Content.ToString()); indexable.SetTextReader(content_reader); indexable.SetChildOf(this.Indexable); AddIndexable(indexable); } break; } } // Add the common properties to the top-level // file item such as Title, Language etc. AddProperty(Property.New("dc:title", base_title)); AddProperty(Property.NewUnsearched("fixme:language", base_language)); watch.Stop(); // If we've successfully crawled the file but haven't // found any indexables, we shouldn't consider it // successfull at all (unless we have a title, which // means that it's actually a docbook file, just without // sections. if (!HasGeneratedIndexable && base_title == null) { Log.Error("Probably not a docbook. Ignoring {0}!", base_path); Error(); return; } Logger.Log.Debug("Parsed docbook file in {0}", watch); Finished(); }
override protected void DoPullProperties () { Stopwatch watch = new Stopwatch (); watch.Start (); while (reader.Read ()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name.StartsWith ("sect") || reader.Name.StartsWith ("chapter")) { string id = reader.GetAttribute ("id"); if (id != null && id != String.Empty) { DocbookEntry entry = new DocbookEntry (); entry.Id = id; entry.Depth = reader.Depth; string language = reader.GetAttribute ("lang"); if (language != null && language != String.Empty) entry.Language = language; entries_stack.Push (entry); } } else if (reader.Name == "article" || reader.Name == "book") { string language = reader.GetAttribute ("lang"); if (language != null && language != String.Empty) base_language = language; } else if (reader.Name == "title") { reader.Read (); // Go to the text node if (entries_stack.Count == 0 && base_title == null) { // This is probably the book title base_title = reader.Value; } else if (entries_stack.Count > 0) { DocbookEntry entry = (DocbookEntry) entries_stack.Peek (); if (entry.Title == null) entry.Title = reader.Value; } } else if (reader.Name == "keyword") { reader.Read (); // read the text node AddProperty (Property.NewKeyword ("dc:subject", reader.Value)); } break; case XmlNodeType.Text: // Append text to the child indexable if (entries_stack.Count > 0) ((DocbookEntry) entries_stack.Peek ()).Content.Append (reader.Value); // Append text to the main indexable else AppendWord (reader.Value); break; case XmlNodeType.EndElement: if (entries_stack.Count > 0 && ((DocbookEntry) entries_stack.Peek ()).Depth == reader.Depth) { DocbookEntry entry, parent_entry = null; entry = (DocbookEntry) entries_stack.Pop (); if (entries_stack.Count > 0) parent_entry = (DocbookEntry) entries_stack.Peek (); Indexable indexable; indexable = new Indexable (UriFu.AddFragment (Indexable.Uri, entry.Id, false)); indexable.HitType = "DocbookEntry"; indexable.MimeType = "text/x-docbook-entry"; indexable.AddProperty (Property.NewKeyword ("beagle:FileType", "documentation")); indexable.Filtering = IndexableFiltering.AlreadyFiltered; indexable.AddProperty (Property.NewUnsearched ("fixme:id", entry.Id)); indexable.AddProperty (Property.New ("dc:title", entry.Title)); // Add the docbook book title indexable.AddProperty (Property.NewUnsearched ("fixme:base_title", base_title)); // Add the child language (or docbook language if none is specified) if (entry.Language != null) indexable.AddProperty (Property.NewUnsearched ("fixme:language", entry.Language)); else if (base_language != null) indexable.AddProperty (Property.NewUnsearched ("fixme:language", base_language)); // Add any parent (as in docbook parent entry, not beagle) data if we have it if (parent_entry != null) { indexable.AddProperty (Property.NewUnsearched ("fixme:parent_id", parent_entry.Id)); indexable.AddProperty (Property.NewUnsearched ("fixme:parent_title", parent_entry.Title)); } StringReader content_reader = new StringReader (entry.Content.ToString ()); indexable.SetTextReader (content_reader); indexable.SetChildOf (this.Indexable); AddIndexable (indexable); } break; } } // Add the common properties to the top-level // file item such as Title, Language etc. AddProperty (Property.New ("dc:title", base_title)); AddProperty (Property.NewUnsearched ("fixme:language", base_language)); watch.Stop (); // If we've successfully crawled the file but haven't // found any indexables, we shouldn't consider it // successfull at all (unless we have a title, which // means that it's actually a docbook file, just without // sections. if (! HasGeneratedIndexable && base_title == null) { Log.Error ("Probably not a docbook. Ignoring {0}!", base_path); Error (); return; } Logger.Log.Debug ("Parsed docbook file in {0}", watch); Finished (); }