apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1748318 - in /apr/apr-util/branches/1.6.x: ./ CHANGES include/apr_xml.h xml/apr_xml.c
Date Mon, 13 Jun 2016 21:57:45 GMT
Author: minfrin
Date: Mon Jun 13 21:57:45 2016
New Revision: 1748318

URL: http://svn.apache.org/viewvc?rev=1748318&view=rev
Log:
Backport r1747941.
apr_xml_to_text: Add style APR_XML_X2T_PARSED to maintain a consistent namespace prefix.

Modified:
    apr/apr-util/branches/1.6.x/   (props changed)
    apr/apr-util/branches/1.6.x/CHANGES
    apr/apr-util/branches/1.6.x/include/apr_xml.h
    apr/apr-util/branches/1.6.x/xml/apr_xml.c

Propchange: apr/apr-util/branches/1.6.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jun 13 21:57:45 2016
@@ -1,4 +1,4 @@
-/apr/apr/trunk:781403,781409,784519,784592,789965,794508,917837-917838,982408-982409,998533,1086937,1127053,1127648,1128838,1129433,1133587,1207704,1210524,1211987,1214516,1308087,1308131,1308318,1327636,1340286,1346865,1357761,1357772,1357780,1357966,1357968,1357979,1358295,1358480,1361811,1362241,1362248,1362252,1362255,1363076,1369681,1370626,1371811,1371817,1371919,1371923,1382174,1389154,1389169,1390461,1390477,1402870,1402897,1402903,1402907,1406088,1422413,1425356,1426442,1426448,1438960,1449308,1449314,1460185,1460243-1460244,1462219,1462224,1484271,1493715,1495887,1495889,1496407,1516261,1523479,1529554,1531009,1541054,1543399,1544846,1618843,1619438,1625247,1626561,1648830,1711657,1722547,1728958,1728963
+/apr/apr/trunk:781403,781409,784519,784592,789965,794508,917837-917838,982408-982409,998533,1086937,1127053,1127648,1128838,1129433,1133587,1207704,1210524,1211987,1214516,1308087,1308131,1308318,1327636,1340286,1346865,1357761,1357772,1357780,1357966,1357968,1357979,1358295,1358480,1361811,1362241,1362248,1362252,1362255,1363076,1369681,1370626,1371811,1371817,1371919,1371923,1382174,1389154,1389169,1390461,1390477,1402870,1402897,1402903,1402907,1406088,1422413,1425356,1426442,1426448,1438960,1449308,1449314,1460185,1460243-1460244,1462219,1462224,1484271,1493715,1495887,1495889,1496407,1516261,1523479,1529554,1531009,1541054,1543399,1544846,1618843,1619438,1625247,1626561,1648830,1711657,1722547,1728958,1728963,1747941
 /apr/apr-util/branches/1.3.x:896410,1154885
 /apr/apr-util/branches/1.4.x:1126217,1211211,1211219,1211223,1211330
 /apr/apr-util/trunk:731033-731034,731225,731236,731291,731293,731379,743986,744009,745771,747612,747623,747630,1626561

Modified: apr/apr-util/branches/1.6.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.6.x/CHANGES?rev=1748318&r1=1748317&r2=1748318&view=diff
==============================================================================
--- apr/apr-util/branches/1.6.x/CHANGES [utf-8] (original)
+++ apr/apr-util/branches/1.6.x/CHANGES [utf-8] Mon Jun 13 21:57:45 2016
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes with APR-util 1.6.0
 
+  *) apr_xml_to_text: Add style APR_XML_X2T_PARSED to maintain a
+     consistent namespace prefix. [Jari Urpalainen
+     <jari.urpalainen nokia.com>]
 
 Changes with APR-util 1.5.x and later:
 

Modified: apr/apr-util/branches/1.6.x/include/apr_xml.h
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.6.x/include/apr_xml.h?rev=1748318&r1=1748317&r2=1748318&view=diff
==============================================================================
--- apr/apr-util/branches/1.6.x/include/apr_xml.h (original)
+++ apr/apr-util/branches/1.6.x/include/apr_xml.h Mon Jun 13 21:57:45 2016
@@ -276,6 +276,7 @@ APU_DECLARE(char *) apr_xml_parser_geter
  *     APR_XML_X2T_INNER               contents only 
  *     APR_XML_X2T_LANG_INNER          xml:lang + inner contents 
  *     APR_XML_X2T_FULL_NS_LANG        FULL + ns defns + xml:lang 
+ *     APR_XML_X2T_PARSED              original prefixes
  * </PRE>
  * @param namespaces The namespace of the current XML element
  * @param ns_map Namespace mapping
@@ -292,6 +293,7 @@ APU_DECLARE(void) apr_xml_to_text(apr_po
 #define APR_XML_X2T_INNER        1	/**< contents only */
 #define APR_XML_X2T_LANG_INNER   2	/**< xml:lang + inner contents */
 #define APR_XML_X2T_FULL_NS_LANG 3	/**< FULL + ns defns + xml:lang */
+#define APR_XML_X2T_PARSED       4	/**< original prefixes */
 
 /**
  * empty XML element

Modified: apr/apr-util/branches/1.6.x/xml/apr_xml.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.6.x/xml/apr_xml.c?rev=1748318&r1=1748317&r2=1748318&view=diff
==============================================================================
--- apr/apr-util/branches/1.6.x/xml/apr_xml.c (original)
+++ apr/apr-util/branches/1.6.x/xml/apr_xml.c Mon Jun 13 21:57:45 2016
@@ -86,7 +86,7 @@ static int find_prefix(apr_xml_parser *p
     ** prefix.
     */
     for (; elem; elem = elem->parent) {
-	apr_xml_ns_scope *ns_scope = elem->ns_scope;
+	apr_xml_ns_scope *ns_scope;
 
 	for (ns_scope = elem->ns_scope; ns_scope; ns_scope = ns_scope->next) {
 	    if (strcmp(prefix, ns_scope->prefix) == 0) {
@@ -120,6 +120,26 @@ static int find_prefix(apr_xml_parser *p
     return APR_XML_NS_ERROR_UNKNOWN_PREFIX;
 }
 
+/* return original prefix given ns index */
+static const char * find_prefix_name(const apr_xml_elem *elem, int ns, int parent)
+{
+    /*
+    ** Walk up the tree, looking for a namespace scope that defines this
+    ** prefix.
+    */
+    for (; elem; elem = parent ? elem->parent : NULL) {
+	apr_xml_ns_scope *ns_scope = elem->ns_scope;
+
+	for (; ns_scope; ns_scope = ns_scope->next) {
+	    if (ns_scope->ns == ns)
+		return ns_scope->prefix;
+	}
+    }
+    /* not found */
+    return "";
+}
+
+
 static void start_handler(void *userdata, const char *name, const char **attrs)
 {
     apr_xml_parser *parser = userdata;
@@ -646,7 +666,8 @@ static apr_size_t elem_size(const apr_xm
 {
     apr_size_t size;
 
-    if (style == APR_XML_X2T_FULL || style == APR_XML_X2T_FULL_NS_LANG) {
+    if (style == APR_XML_X2T_FULL || style == APR_XML_X2T_FULL_NS_LANG ||
+	style == APR_XML_X2T_PARSED) {
 	const apr_xml_attr *attr;
 
 	size = 0;
@@ -670,11 +691,29 @@ static apr_size_t elem_size(const apr_xm
 		size += 11 + strlen(elem->lang) + 1;
 	    }
 	}
+	else if (style == APR_XML_X2T_PARSED) {
+	    apr_xml_ns_scope *ns_scope = elem->ns_scope;
+
+	    /* compute size of: ' xmlns:%s="%s"' */
+	    for (; ns_scope; ns_scope = ns_scope->next) {
+		size += 10 + strlen(find_prefix_name(elem, ns_scope->ns, 0)) +
+			     strlen(APR_XML_GET_URI_ITEM(namespaces, ns_scope->ns));
+	    }
+
+	    if (elem->lang != NULL) {
+		/* compute size of: ' xml:lang="%s"' */
+		size += 11 + strlen(elem->lang) + 1;
+	    }
+	}
 
 	if (elem->ns == APR_XML_NS_NONE) {
 	    /* compute size of: <%s> */
 	    size += 1 + strlen(elem->name) + 1;
 	}
+	else if (style == APR_XML_X2T_PARSED) {
+	    /* compute size of: <%s:%s> */
+	    size += 3 + strlen(find_prefix_name(elem, elem->ns, 1)) + strlen(elem->name);
+	}
 	else {
 	    int ns = ns_map ? ns_map[elem->ns] : elem->ns;
 
@@ -700,6 +739,10 @@ static apr_size_t elem_size(const apr_xm
 		/* compute size of: ' %s="%s"' */
 		size += 1 + strlen(attr->name) + 2 + strlen(attr->value) + 1;
 	    }
+	    else if (style == APR_XML_X2T_PARSED) {
+		/* compute size of: ' %s:%s="%s"' */
+		size += 5 + strlen(find_prefix_name(elem, attr->ns, 1)) + strlen(attr->name) + strlen(attr->value);
+	    }
 	    else {
 		/* compute size of: ' ns%d:%s="%s"' */
                 int ns = ns_map ? ns_map[attr->ns] : attr->ns;
@@ -733,7 +776,7 @@ static apr_size_t elem_size(const apr_xm
 
     for (elem = elem->first_child; elem; elem = elem->next) {
 	/* the size of the child element plus the CDATA that follows it */
-	size += (elem_size(elem, APR_XML_X2T_FULL, NULL, ns_map) +
+	size += (elem_size(elem, style == APR_XML_X2T_PARSED ? APR_XML_X2T_PARSED : APR_XML_X2T_FULL,
NULL, ns_map) +
 		 text_size(elem->following_cdata.first));
     }
 
@@ -757,13 +800,15 @@ static char *write_elem(char *s, const a
     apr_size_t len;
     int ns;
 
-    if (style == APR_XML_X2T_FULL || style == APR_XML_X2T_FULL_NS_LANG) {
+    if (style == APR_XML_X2T_FULL || style == APR_XML_X2T_FULL_NS_LANG ||
+	style == APR_XML_X2T_PARSED) {
 	int empty = APR_XML_ELEM_IS_EMPTY(elem);
 	const apr_xml_attr *attr;
 
-	if (elem->ns == APR_XML_NS_NONE) {
+	if (elem->ns == APR_XML_NS_NONE)
 	    len = sprintf(s, "<%s", elem->name);
-	}
+	else if (style == APR_XML_X2T_PARSED)
+	    len = sprintf(s, "<%s:%s", find_prefix_name(elem, elem->ns, 1), elem->name);
 	else {
 	    ns = ns_map ? ns_map[elem->ns] : elem->ns;
 	    len = sprintf(s, "<ns%d:%s", ns, elem->name);
@@ -773,10 +818,13 @@ static char *write_elem(char *s, const a
 	for (attr = elem->attr; attr; attr = attr->next) {
 	    if (attr->ns == APR_XML_NS_NONE)
 		len = sprintf(s, " %s=\"%s\"", attr->name, attr->value);
-            else {
-                ns = ns_map ? ns_map[attr->ns] : attr->ns;
-                len = sprintf(s, " ns%d:%s=\"%s\"", ns, attr->name, attr->value);
-            }
+	    else if (style == APR_XML_X2T_PARSED)
+		len = sprintf(s, " %s:%s=\"%s\"",
+			      find_prefix_name(elem, attr->ns, 1), attr->name, attr->value);
+	    else {
+		ns = ns_map ? ns_map[attr->ns] : attr->ns;
+		len = sprintf(s, " ns%d:%s=\"%s\"", ns, attr->name, attr->value);
+	    }
 	    s += len;
 	}
 
@@ -799,6 +847,18 @@ static char *write_elem(char *s, const a
 		s += len;
 	    }
 	}
+	else if (style == APR_XML_X2T_PARSED) {
+	    apr_xml_ns_scope *ns_scope = elem->ns_scope;
+
+	    for (; ns_scope; ns_scope = ns_scope->next) {
+		const char *prefix = find_prefix_name(elem, ns_scope->ns, 0);
+
+		len = sprintf(s, " xmlns%s%s=\"%s\"",
+			      *prefix ? ":" : "", *prefix ? prefix : "",
+			      APR_XML_GET_URI_ITEM(namespaces, ns_scope->ns));
+		s += len;
+	    }
+	}
 
 	/* no more to do. close it up and go. */
 	if (empty) {
@@ -823,14 +883,17 @@ static char *write_elem(char *s, const a
     s = write_text(s, elem->first_cdata.first);
 
     for (child = elem->first_child; child; child = child->next) {
-	s = write_elem(s, child, APR_XML_X2T_FULL, NULL, ns_map);
+	s = write_elem(s, child,
+		       style == APR_XML_X2T_PARSED ? APR_XML_X2T_PARSED : APR_XML_X2T_FULL,
+		       NULL, ns_map);
 	s = write_text(s, child->following_cdata.first);
     }
 
-    if (style == APR_XML_X2T_FULL || style == APR_XML_X2T_FULL_NS_LANG) {
-	if (elem->ns == APR_XML_NS_NONE) {
+    if (style == APR_XML_X2T_FULL || style == APR_XML_X2T_FULL_NS_LANG || style == APR_XML_X2T_PARSED)
{
+	if (elem->ns == APR_XML_NS_NONE)
 	    len = sprintf(s, "</%s>", elem->name);
-	}
+	else if (style == APR_XML_X2T_PARSED)
+	    len = sprintf(s, "</%s:%s>", find_prefix_name(elem, elem->ns, 1), elem->name);
 	else {
 	    ns = ns_map ? ns_map[elem->ns] : elem->ns;
 	    len = sprintf(s, "</ns%d:%s>", ns, elem->name);



Mime
View raw message