Skip to content

Commit

Permalink
XMLA driver: when constructing metadata request XML, encode restricti…
Browse files Browse the repository at this point in the history
…on values

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@67 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Jan 24, 2008
1 parent afa7d80 commit 14ca2de
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,7 @@ public String generateRequest(
final String restriction = restrictions[i];
final String value = restrictions[i + 1];
buf.append("<").append(restriction).append(">");
// TODO: escape value
buf.append(value);
buf.append(xmlEncode(value));
buf.append("</").append(restriction).append(">");
}
}
Expand All @@ -523,6 +522,27 @@ public String generateRequest(
return buf.toString();
}

/**
* Encodes a string for use in an XML CDATA section.
*
* <p>TODO use an XML serialiser or handle these too:
* quote (") "
* apostrophe (') &apos;
* ampersand (&) &amp;
* less than (<) &lt;
* greater than (>) &gt;
*
* @param value to be xml encoded
* @return an XML encode string or the value is not required.
*/
private static String xmlEncode(String value){
if (value.indexOf('&') == -1) {
return value;
} else {
return value.replace("&", "&amp;");
}
}

// ~ inner classes --------------------------------------------------------

static class Helper {
Expand Down

0 comments on commit 14ca2de

Please sign in to comment.