Added get_parent_webnode, get_full_uri, and get_full_uri_parent helpers to WebNode.

This commit is contained in:
Relintai 2022-02-04 15:54:21 +01:00
parent 53238c1265
commit 65892ddd5a
2 changed files with 37 additions and 0 deletions

View File

@ -22,6 +22,35 @@ void WebNode::set_uri_segment(const String &val) {
_uri_segment = val;
}
String WebNode::get_full_uri(const bool slash_at_the_end) {
if (slash_at_the_end) {
return get_full_uri_parent(true) + _uri_segment + '/';
} else {
return get_full_uri_parent(true) + _uri_segment;
}
}
String WebNode::get_full_uri_parent(const bool slash_at_the_end) {
String uri = "/";
WebNode *n = get_parent_webnode();
while (n) {
if (n->_uri_segment == "" || n->_uri_segment == '/') {
break;
}
uri = "/" + n->_uri_segment + uri;
n = n->get_parent_webnode();
}
if (!slash_at_the_end) {
uri.pop_back();
}
return uri;
}
Settings *WebNode::get_settings() {
if (_settings) {
return _settings;
@ -147,6 +176,10 @@ WebNode *WebNode::get_root() {
return s->get_web_root();
}
WebNode *WebNode::get_parent_webnode() {
return Object::cast_to<WebNode>(get_parent());
}
WebNode::WebNode() :
Node() {
// should look this up in parents when parented (and node parenting is implemented)

View File

@ -22,6 +22,9 @@ public:
String get_uri_segment();
void set_uri_segment(const String &val);
virtual String get_full_uri(const bool slash_at_the_end = true);
virtual String get_full_uri_parent(const bool slash_at_the_end = true);
Settings *get_settings();
void set_settings(Settings *settings);
@ -50,6 +53,7 @@ public:
WebServer *get_server();
WebNode *get_root();
WebNode *get_parent_webnode();
WebNode();
~WebNode();