Revision 3539
Added by barteau about 17 years ago
src/edu/ucsb/nceas/metacat/clientview/ClientViewHelper.java | ||
---|---|---|
40 | 40 |
import javax.xml.xpath.XPathConstants; |
41 | 41 |
import javax.xml.xpath.XPathExpressionException; |
42 | 42 |
import javax.xml.xpath.XPathFactory; |
43 |
import org.w3c.dom.DOMException; |
|
43 | 44 |
import org.w3c.dom.Document; |
44 | 45 |
import org.w3c.dom.Node; |
45 | 46 |
import org.w3c.dom.NodeList; |
47 |
import org.w3c.dom.Text; |
|
46 | 48 |
|
47 | 49 |
/** |
48 | 50 |
* |
... | ... | |
125 | 127 |
|
126 | 128 |
//*** BEGIN: manual bind params to bean (if we arrived here via the ClientViewHelper.jspx). |
127 | 129 |
if (action == null || action.equals("")) { |
128 |
if (contentType != null && contentType.contains("multipart/form-data")) {
|
|
130 |
if (contentType != null && contentType.indexOf("multipart/form-data") > -1) {
|
|
129 | 131 |
action = "Upload"; |
130 | 132 |
} else { |
131 | 133 |
action = request.getParameter("action"); |
... | ... | |
313 | 315 |
* @param serverResponse XML login response sent from Metacat. |
314 | 316 |
*/ |
315 | 317 |
public void setLoggedIn(String serverResponse) { |
316 |
loggedIn = (serverResponse != null && serverResponse.contains("login"));
|
|
318 |
loggedIn = (serverResponse != null && serverResponse.indexOf("login") > -1);
|
|
317 | 319 |
} |
318 | 320 |
|
319 | 321 |
public String parseXml(String elementName, String xml) { |
... | ... | |
766 | 768 |
Node node; |
767 | 769 |
|
768 | 770 |
//*** Parse the last Doc Id, and increment the version number. |
769 |
if(lastDocId != null && lastDocId.contains(".")) {
|
|
771 |
if(lastDocId != null && lastDocId.indexOf(".") > -1) {
|
|
770 | 772 |
ready2Split = lastDocId.replace('.','~'); //*** This is necessary for the split to work. |
771 | 773 |
tokens = ready2Split.split("~"); |
772 | 774 |
if(tokens.length > LAST_TOKEN && !tokens[LAST_TOKEN].equals("")) { |
... | ... | |
797 | 799 |
//*** Update the Doc Id in the metadata file. |
798 | 800 |
if (getMetadataDoc() != null) { |
799 | 801 |
node = (Node) xpath.evaluate(xPathQuery, getMetadataDoc().getDocumentElement(), XPathConstants.NODE); |
800 |
node.setTextContent(result); |
|
802 |
setTextContent(xpath, node, result); |
|
803 |
//node.setTextContent(result); |
|
801 | 804 |
} |
802 | 805 |
return(result); |
803 | 806 |
} |
... | ... | |
807 | 810 |
int vers; |
808 | 811 |
String template = scope.toLowerCase() + ".%1d.%2d"; |
809 | 812 |
|
810 |
if(lastDocId != null && lastDocId.contains(".")) {
|
|
813 |
if(lastDocId != null && lastDocId.indexOf(".") > -1) {
|
|
811 | 814 |
lastDocId = lastDocId.replace('.','~'); //*** This is necessary for the split to work. |
812 | 815 |
tokens = lastDocId.split("~"); |
813 | 816 |
if(tokens.length > 1 && !tokens[1].equals("")) { |
... | ... | |
866 | 869 |
if (text != null && !text.equals("")) { |
867 | 870 |
try { |
868 | 871 |
targetNode = (Node) xPath.evaluate(expression, root, XPathConstants.NODE); |
869 |
targetNode.setTextContent(text); |
|
872 |
setTextContent(xPath, targetNode, text); |
|
873 |
//targetNode.setTextContent(text); |
|
870 | 874 |
} catch (XPathExpressionException ex) { |
871 | 875 |
ex.printStackTrace(); |
872 | 876 |
} |
... | ... | |
892 | 896 |
|
893 | 897 |
node = getNode(xPath, expression, root); |
894 | 898 |
if (node != null && !node.equals("")) |
895 |
result = node.getTextContent(); |
|
899 |
result = getTextContent(xPath, node); |
|
900 |
//result = node.getTextContent(); Not in java 1.4 |
|
896 | 901 |
return(result); |
897 | 902 |
} |
898 | 903 |
|
... | ... | |
906 | 911 |
if (nodes != null && (size = nodes.getLength()) > 0) { |
907 | 912 |
result = new String[size]; |
908 | 913 |
for(int i = 0; i < size; i++) |
909 |
result[i] = nodes.item(i).getTextContent(); |
|
914 |
result[i] = getTextContent(xPath, nodes.item(i)); |
|
915 |
//result[i] = nodes.item(i).getTextContent(); Not in java 1.4 |
|
910 | 916 |
} |
911 | 917 |
} catch (XPathExpressionException ex) { |
912 | 918 |
ex.printStackTrace(); |
... | ... | |
1042 | 1048 |
bean.setMessage(ClientView.SELECT_MESSAGE, ex.getMessage()); |
1043 | 1049 |
} |
1044 | 1050 |
} |
1051 |
responseMap.put("message", bean.getMessage(ClientView.SELECT_MESSAGE)); |
|
1045 | 1052 |
return(responseMap); |
1046 | 1053 |
} |
1047 | 1054 |
|
... | ... | |
1075 | 1082 |
return(result); |
1076 | 1083 |
} |
1077 | 1084 |
|
1085 |
public static void setTextContent(XPath xPath, Node elementNode, String content) throws DOMException { |
|
1086 |
Text textNode, newTxtNode; |
|
1087 |
Document document; |
|
1088 |
|
|
1089 |
textNode = (Text) getNode(xPath, "text()", elementNode); |
|
1090 |
if (textNode != null) { |
|
1091 |
if (isElementContentWhitespace(textNode)) { |
|
1092 |
//*** If there is an existing text node, and it's whitespace, |
|
1093 |
//*** create a new text node and insert it before whitespace. |
|
1094 |
document = elementNode.getOwnerDocument(); |
|
1095 |
newTxtNode = document.createTextNode(content); |
|
1096 |
elementNode.insertBefore(newTxtNode, textNode); |
|
1097 |
} else { |
|
1098 |
//*** If there is an existing text node, and it has content, |
|
1099 |
//*** overwrite the existing text. |
|
1100 |
textNode.setNodeValue(content); |
|
1101 |
} |
|
1102 |
} else { |
|
1103 |
//*** If there isn't an existing text node, |
|
1104 |
//*** create a new text node and append it to the elementNode. |
|
1105 |
document = elementNode.getOwnerDocument(); |
|
1106 |
newTxtNode = document.createTextNode(content); |
|
1107 |
elementNode.appendChild(newTxtNode); |
|
1108 |
} |
|
1109 |
} |
|
1110 |
|
|
1111 |
public static String getTextContent(XPath xPath, Node elementNode) throws DOMException { |
|
1112 |
String result = ""; |
|
1113 |
Text textNode; |
|
1114 |
|
|
1115 |
textNode = (Text) getNode(xPath, "text()", elementNode); |
|
1116 |
if (textNode != null) |
|
1117 |
result = textNode.getNodeValue(); |
|
1118 |
return(result); |
|
1119 |
} |
|
1120 |
|
|
1121 |
public static boolean isElementContentWhitespace(Text textNode) { |
|
1122 |
boolean result = false; |
|
1123 |
String val; |
|
1124 |
|
|
1125 |
if ((val = textNode.getNodeValue()) != null) { |
|
1126 |
if (val != null) { |
|
1127 |
val = val.trim(); |
|
1128 |
result = (val.length() == 0); |
|
1129 |
} |
|
1130 |
} |
|
1131 |
return(result); |
|
1132 |
} |
|
1133 |
|
|
1078 | 1134 |
} |
Also available in: Unified diff
Converted some java 1.5 code to java 1.4 code. Removed usages of "String.contains()", "Node.getTextContent()" and "Node.setTextContent.
Wrote two new methods: 1) getTextContent, and 2) setTextContent, to emulate the org.w3c.dom implementation that ships with java 1.5.