Пример #1
0
static QString extractAddress(DOM::Node node) {
	QString rc = ";;";
	QMap<QString,QString> entry;
	DOM::NodeList nodes = node.childNodes();
	unsigned int n = nodes.length();
	for (unsigned int i = 0; i < n; ++i) {
		DOM::Node node = nodes.item(i);
		DOM::NamedNodeMap map = node.attributes();
		for (unsigned int j = 0; j < map.length(); ++j) {
			if (map.item(j).nodeName().string() != "class") {
				continue;
			}
			QString a = map.item(j).nodeValue().string();
			if (a == "street-address") {
				entry["street-address"] = textForNode(node);
			} else if (a == "locality") {
				entry["locality"] = textForNode(node);
			} else if (a == "region") {
				entry["region"] = textForNode(node);
			} else if (a == "postal-code") {
				entry["postal-code"] = textForNode(node);
			}
		}
	}

	rc += entry["street-address"] + ";" + entry["locality"] + ";" + entry["region"] + ";" + entry["postal-code"] + ";" + entry["country"];
	return rc.stripWhiteSpace();
}
Пример #2
0
bool KonqMFIcon::hasMicroFormat(DOM::NodeList nodes) {
	bool ok = false;
	unsigned int n = nodes.length();
	for (unsigned int i = 0; i < n; ++i) {
		DOM::Node node = nodes.item(i);
		DOM::NamedNodeMap map = node.attributes();
		for (unsigned int j = 0; j < map.length(); ++j) {
			if (map.item(j).nodeName().string() != "class") {
				continue;
			}
			if (map.item(j).nodeValue().string() == "vevent") {
				ok = true;
				extractEvent(node);
				break;
			}
			if (map.item(j).nodeValue().string() == "vcard") {
				ok = true;
				extractCard(node);
				break;
			}
		}
		if (hasMicroFormat(node.childNodes())) {
			ok = true;
		}
	}
	return ok;
}
Пример #3
0
QString ResultsView::deLinkify( DOM::Node node )
{
  //TODO: make this function more flexible (ie, accept non-link-content as
  //well.)
  QString word;
  for ( int i = 0; i < node.childNodes().length(); ++i )
  {
    if ( node.childNodes().item(i).nodeName() != "a" )
    {
      return QString();
    }
    if ( ! node.childNodes().item(i).hasChildNodes() )
    {
      return QString();
    }

    word += node.childNodes().item(i).childNodes().item( 0 ).nodeValue().string();
  }
  return word;
}
Пример #4
0
static QString textForNode(DOM::Node node) {
	QString rc;
	DOM::NodeList nl = node.childNodes();
	for (unsigned int i = 0; i < nl.length(); ++i) {
		DOM::Node n = nl.item(i);
		if (n.nodeType() == DOM::Node::TEXT_NODE) {
			rc += n.nodeValue().string();
		}
	}
	// FIXME: entries need to be escaped for vcard/vevent
	return rc.stripWhiteSpace();
}
Пример #5
0
void KonqMFIcon::extractCard(DOM::Node node) {
	QString name, value;
	DOM::NodeList nodes = node.childNodes();
	unsigned int n = nodes.length();
	value += "BEGIN:VCARD\nVERSION:3.0\n";
	for (unsigned int i = 0; i < n; ++i) {
		DOM::Node node = nodes.item(i);
		DOM::NamedNodeMap map = node.attributes();
		for (unsigned int j = 0; j < map.length(); ++j) {
			if (map.item(j).nodeName().string() != "class") {
				continue;
			}
			QStringList l = QStringList::split(' ', map.item(j).nodeValue().string());
			for (QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
				if (*it == "photo") {
				} else if (*it == "adr") {
					value += "ADR:" + extractAddress(node) + "\n";
				} else if (*it == "tel") {
					value += "TEL;TYPE=VOICE:" + textForNode(node) + "\n";
				} else if (*it == "fn") {
					name = textForNode(node);
					value += "FN:" + name + "\n";
				} else if (*it == "url") {
					DOM::Node at = node.attributes().getNamedItem("href");
					if (!at.isNull()) {
						value += "URL:" + at.nodeValue().string().stripWhiteSpace() + "\n";
					}
				} else if (*it == "email") {
					DOM::Node at = node.attributes().getNamedItem("href");
					if (!at.isNull()) {
						QString v = at.nodeValue().string();
						if (v.startsWith("mailto:")) {
							v = v.mid(7);
						}
						value += "EMAIL:" + v.stripWhiteSpace() + "\n";
					}
				} else if (*it == "org") {
					value += "ORG:" + textForNode(node) + "\n";
				}
			}
		}
	}

	if (!name.isEmpty()) {
		value += "END:VCARD\n";
		_cards.append(qMakePair(name, value));
	}
}
Пример #6
0
void KonqMFIcon::extractEvent(DOM::Node node) {
	QString name, value = "BEGIN:VCALENDAR\nPRODID:-//Konqueror//EN\nVERSION:2.0\nBEGIN:VEVENT\n";
	DOM::NodeList nodes = node.childNodes();
	unsigned int n = nodes.length();
	for (unsigned int i = 0; i < n; ++i) {
		DOM::Node node = nodes.item(i);
		DOM::NamedNodeMap map = node.attributes();
		for (unsigned int j = 0; j < map.length(); ++j) {
			if (map.item(j).nodeName().string() != "class") {
				continue;
			}
			QStringList l = QStringList::split(' ', map.item(j).nodeValue().string());
			for (QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
				if (*it == "url") {
					DOM::Node at = node.attributes().getNamedItem("href");
					if (!at.isNull()) {
						value += "URL:" + at.nodeValue().string().stripWhiteSpace() + "\n";
					}
				} else if (*it == "dtstart") {
					DOM::Node at = node.attributes().getNamedItem("title");
					if (!at.isNull()) {
						value += "DTSTART:" + at.nodeValue().string().stripWhiteSpace() + "\n";
					}
				} else if (*it == "dtend") {
					DOM::Node at = node.attributes().getNamedItem("title");
					if (!at.isNull()) {
						value += "DTEND:" + at.nodeValue().string().stripWhiteSpace() + "\n";
					}
				} else if (*it == "summary") {
					name = textForNode(node);
					value += "SUMMARY:" + name + "\n";
				} else if (*it == "location") {
					value += "LOCATION:" + textForNode(node) + "\n";
				}
			}
		}
	}

	if (!name.isEmpty()) {
		value += "END:VEVENT\nEND:VCALENDAR\n";
		_events.append(qMakePair(name, value));
	}
}
Пример #7
0
void Range::checkNodeWOffset( DOM::Node n, int offset) const
{
    checkNode( n );
    
    if( offset < 0 )
        throw DOMException( DOMException::INDEX_SIZE_ERR );

    if( n.nodeType() != Node::TEXT_NODE )
    {
	if( (unsigned int)offset > n.childNodes().length() )
            throw DOMException( DOMException::INDEX_SIZE_ERR );
    }
    else
    {
	Text t;
	t = n;
        if( t.isNull() || (unsigned)offset > t.length() )
            throw DOMException( DOMException::INDEX_SIZE_ERR );
    }
}