Logo Search packages:      
Sourcecode: passepartout version File versions  Download package

void Document::xml_open ( const ElementWrap root  )  [private]

Todo:
this function is too long and unreadable

Todo:
Use a proper type that can be converted for the paper type.

Definition at line 391 of file document.cc.

References ElementWrap::element(), ElementWrap::get_element_name(), and ElementWrap::get_filename().

Referenced by open().

                                              {
  /// \todo this function is too long and unreadable
  std::string temp_template = xml.get_filename("template");

  if(xml.get_element_name() != "document")
    throw Error::Read("Root node is not <document>");

  //default values if attribute is not encountered:
  doublesided = true; 
  orientation = Papers::PORTRAIT;
  first_page_num = 1;
  paper_name = "A4";

  //read document attributes:
  xmlpp::Element::AttributeList attributes = xml.element().get_attributes();
  for(xmlpp::Element::AttributeList::iterator i = attributes.begin();
      i != attributes.end();
      i++)
    {
      const std::string name = (*i)->get_name();
      if(name == "template"); // handled elsewhere
      else if(name == "doublesided")
      doublesided = to<bool>((*i)->get_value());
      else if(name == "landscape") {
      if(to<bool>((*i)->get_value()))
        orientation = Papers::LANDSCAPE;
      } else if(name == "paper_name") {
      /// \todo Use a proper type that can be converted for the paper type.
      try {
        paper_name = (*i)->get_value();
      } catch (Error::PaperName e) {
        throw Error::Read("There is no paper called \"" + e.name + "\".");
      }
      } else if(name == "first_page_num") {
      first_page_num = to<int>((*i)->get_value());
      } else
      warning << "Unknown attribute \"" << (*i)->get_name()
            << "\" ignored in <document>." << std::endl;
    }

  if(!is_template) // templates can't have templates
    set_template(temp_template);
  // the template overrides anything  explicitly stated in the document

  // read text streams and pages:
  xmlpp::Element::NodeList children = xml.element().get_children();
  for(xmlpp::Node::NodeList::iterator i = children.begin();
      i != children.end();
      i++) {
    if(xmlpp::Element *elem = dynamic_cast<xmlpp::Element*>(*i)) {
      std::string name = elem->get_name();
      if(name == "text_stream") {
      std::auto_ptr<TextStream> stream
        (new TextStream(ElementWrap(xml, *elem)));
      const std::string &name = stream->get_name();
      if(name.empty())
        throw Error::Read("Text stream has no name.");
        
      // template streams override document streams
      // if two streams have the same name, the second will be ignored
      if(!get_text_stream(name))
        _add_text_stream(stream.release()); // no signal

      
      } else if(name == "page") {
      pages.push_back(new Page(ElementWrap(xml, *elem), *this));
      } else
      warning << "Unknown node <" << name
            << "> ignored in <document>" << std::endl;
    }
  }
}


Generated by  Doxygen 1.6.0   Back to index