Revision 3367
Added by barteau over 17 years ago
src/edu/ucsb/nceas/metacat/clientview/ClientFgdcHelper.java | ||
---|---|---|
42 | 42 |
*/ |
43 | 43 |
public static final String FGDC_DATA_FILE_DOCID_XPATH = "/metadata/distinfo/stdorder/digform/digtopt/onlinopt/computer/networka/networkr"; |
44 | 44 |
|
45 |
public static final String PATH4ANCESTOR = FGDC_DATA_FILE_DOCID_XPATH + "[text()='%1$s']/ancestor::node()[name()='%2$s']";
|
|
45 |
public static final String PATH4ANCESTOR = FGDC_DATA_FILE_DOCID_XPATH + "[text()='%1s']/ancestor::node()[name()='%2s']";
|
|
46 | 46 |
|
47 | 47 |
/** |
48 | 48 |
* Metadata Document ID location within an FGDC document. XPath expression. |
49 | 49 |
*/ |
50 | 50 |
public static final String FGDC_DOCID_XPATH = "/metadata/distinfo/resdesc"; |
51 | 51 |
|
52 |
public static final String XPATH_QUERY_TEMPLATE = FGDC_DOCID_XPATH + "[text()='%1$s']";
|
|
52 |
public static final String XPATH_QUERY_TEMPLATE = FGDC_DOCID_XPATH + "[text()='%1s']"; |
|
53 | 53 |
|
54 | 54 |
/** |
55 | 55 |
* Identifies the FGDC DTD. |
... | ... | |
111 | 111 |
} |
112 | 112 |
|
113 | 113 |
private static String removeDataDocIdFromFGDC(String docId, String parentDocId, ClientViewHelper clientViewHelper) throws Exception { |
114 |
String pathToDigform, revision = "", xPathQuery; |
|
114 |
String pathToDigform, revision = "", xPathQuery, tmp;
|
|
115 | 115 |
Document doc; |
116 | 116 |
InputStream response; |
117 | 117 |
BufferedReader buffy; |
... | ... | |
123 | 123 |
//*** Get the metadata document and remove the digform branch. |
124 | 124 |
doc = clientViewHelper.getMetadataDoc(); |
125 | 125 |
if (doc != null) { |
126 |
pathToDigform = String.format(PATH4ANCESTOR, docId, "digform"); |
|
126 |
//pathToDigform = String.format(PATH4ANCESTOR, docId, "digform"); |
|
127 |
tmp = PATH4ANCESTOR.replaceFirst("%1s", docId); |
|
128 |
pathToDigform = tmp.replaceFirst("%2s", "digform"); |
|
127 | 129 |
node = (Node) xpath.evaluate(pathToDigform, doc.getDocumentElement(), XPathConstants.NODE); |
128 | 130 |
node.getParentNode().removeChild(node); |
129 |
xPathQuery = String.format(XPATH_QUERY_TEMPLATE, docId); |
|
131 |
//xPathQuery = String.format(XPATH_QUERY_TEMPLATE, docId); |
|
132 |
xPathQuery = XPATH_QUERY_TEMPLATE.replaceFirst("%1s", docId); |
|
130 | 133 |
revision = clientViewHelper.nextVersion(parentDocId, xPathQuery); |
131 | 134 |
reader = XMLUtilities.getDOMTreeAsReader(doc.getDocumentElement(), false); |
132 | 135 |
clientViewHelper.getMetacatClient().update(revision, reader, null); |
src/edu/ucsb/nceas/metacat/clientview/ClientHtmlHelper.java | ||
---|---|---|
18 | 18 |
* @author barteau |
19 | 19 |
*/ |
20 | 20 |
public abstract class ClientHtmlHelper { |
21 |
private static final String SELECT_TEMPLATE = "<select name='%1$s' style='%2$s' size='%3$s'>\n%4$s</select>\n";
|
|
22 |
private static final String OPTION_TEMPLATE = "<option value='%1$s'>%2$s</option>\n";
|
|
23 |
private static final String OPTGRP_TEMPLATE = "<optgroup label='%1$s'>%2$s</optgroup>";
|
|
24 |
private static final String INPUT_TEMPLATE = "<input name='%1$s' value='%2$s' type='%4$s' class='%3$s' size='%5$s'/>\n";
|
|
21 |
private static final String SELECT_TEMPLATE = "<select name='%1s' style='%2s' size='%3s'>\n%4s</select>\n";
|
|
22 |
private static final String OPTION_TEMPLATE = "<option value='%1s'>%2s</option>\n";
|
|
23 |
private static final String OPTGRP_TEMPLATE = "<optgroup label='%1s'>%2s</optgroup>";
|
|
24 |
private static final String INPUT_TEMPLATE = "<input name='%1s' value='%2s' type='%4s' class='%3s' size='%5s'/>\n";
|
|
25 | 25 |
|
26 | 26 |
/** |
27 | 27 |
* JSP API: A static helper method which takes a map (key, value pairs) and returns |
... | ... | |
46 | 46 |
obj = map.get(key); |
47 | 47 |
if (obj instanceof String) { |
48 | 48 |
item = (String) obj; |
49 |
tmp = OPTION_TEMPLATE.replaceFirst("%1$s", key);
|
|
50 |
item = tmp.replaceFirst("%2$s", item);
|
|
49 |
tmp = OPTION_TEMPLATE.replaceFirst("%1s", key); |
|
50 |
item = tmp.replaceFirst("%2s", item); |
|
51 | 51 |
result += item; |
52 | 52 |
} else if (obj instanceof Vector) { |
53 | 53 |
vector = (Vector) obj; |
... | ... | |
55 | 55 |
completeIterIt = vector.iterator(); |
56 | 56 |
while (completeIterIt.hasNext()) { |
57 | 57 |
item = (String) completeIterIt.next(); |
58 |
tmp = OPTION_TEMPLATE.replaceFirst("%1$s", item);
|
|
59 |
item = tmp.replaceFirst("%2$s", item);
|
|
58 |
tmp = OPTION_TEMPLATE.replaceFirst("%1s", item); |
|
59 |
item = tmp.replaceFirst("%2s", item); |
|
60 | 60 |
optGrp += item; |
61 | 61 |
} |
62 |
tmp = OPTGRP_TEMPLATE.replaceFirst("%1$s", key);
|
|
63 |
item = tmp.replaceFirst("%2$s", optGrp);
|
|
62 |
tmp = OPTGRP_TEMPLATE.replaceFirst("%1s", key); |
|
63 |
item = tmp.replaceFirst("%2s", optGrp); |
|
64 | 64 |
result += item; |
65 | 65 |
} |
66 | 66 |
} |
67 |
tmp = SELECT_TEMPLATE.replaceFirst("%1$s", name);
|
|
68 |
tmp = tmp.replaceFirst("%2$s", style);
|
|
69 |
tmp = tmp.replaceFirst("%3$s", String.valueOf(size));
|
|
70 |
result = tmp.replaceFirst("%4$s", result);
|
|
67 |
tmp = SELECT_TEMPLATE.replaceFirst("%1s", name); |
|
68 |
tmp = tmp.replaceFirst("%2s", style); |
|
69 |
tmp = tmp.replaceFirst("%3s", String.valueOf(size)); |
|
70 |
result = tmp.replaceFirst("%4s", result); |
|
71 | 71 |
return(result); |
72 | 72 |
} |
73 | 73 |
|
src/edu/ucsb/nceas/metacat/clientview/ClientViewHelper.java | ||
---|---|---|
54 | 54 |
private int sizeLimit; |
55 | 55 |
private String contactName = ""; |
56 | 56 |
|
57 |
private static final String LDAP_TEMPLATE = "uid=%1$s,o=%2$s,dc=ecoinformatics,dc=org";
|
|
57 |
private static final String LDAP_TEMPLATE = "uid=%1s,o=%2s,dc=ecoinformatics,dc=org";
|
|
58 | 58 |
|
59 | 59 |
/** |
60 | 60 |
* Creates a new instance of ClientViewHelper |
61 | 61 |
*/ |
62 | 62 |
public ClientViewHelper(HttpServletRequest request) throws MetacatInaccessibleException { |
63 |
String metacatPath = "http://%1$s%2$s/metacat";
|
|
63 |
String metacatPath = "http://%1s%2s/metacat";
|
|
64 | 64 |
String host, context, button, tmp; |
65 | 65 |
|
66 | 66 |
clientSession = request.getSession(); |
... | ... | |
68 | 68 |
host = request.getHeader("host"); |
69 | 69 |
context = request.getContextPath(); |
70 | 70 |
//metacatPath = String.format(metacatPath, host, context); |
71 |
tmp = metacatPath.replaceFirst("%1$s", host);
|
|
72 |
metacatPath = tmp.replaceFirst("%2$s", context);
|
|
71 |
tmp = metacatPath.replaceFirst("%1s", host); |
|
72 |
metacatPath = tmp.replaceFirst("%2s", context); |
|
73 | 73 |
metacatClient = (MetacatClient) MetacatFactory.createMetacatConnection(metacatPath); |
74 | 74 |
sizeLimit = (new Integer(MetaCatUtil.getOption("datafilesizelimit"))).intValue(); |
75 | 75 |
} |
... | ... | |
90 | 90 |
try { |
91 | 91 |
if (action.equals("Login")) { |
92 | 92 |
//posted_ldapUserName = String.format(LDAP_TEMPLATE, clientViewBean.getUsername(), clientViewBean.getOrganization()); |
93 |
tmp = LDAP_TEMPLATE.replaceFirst("%1$s", clientViewBean.getUsername());
|
|
94 |
posted_ldapUserName = tmp.replaceFirst("%2$s", clientViewBean.getOrganization());
|
|
93 |
tmp = LDAP_TEMPLATE.replaceFirst("%1s", clientViewBean.getUsername()); |
|
94 |
posted_ldapUserName = tmp.replaceFirst("%2s", clientViewBean.getOrganization()); |
|
95 | 95 |
|
96 | 96 |
serverResponse = metacatClient.login(posted_ldapUserName, clientViewBean.getPassword()); |
97 | 97 |
setLoggedIn(serverResponse); |
... | ... | |
338 | 338 |
result = "Update not performed: the Metadata file has no prior Metacat info in it."; |
339 | 339 |
} else { |
340 | 340 |
//xPathQuery = String.format(ClientFgdcHelper.XPATH_QUERY_TEMPLATE, lastDocId); |
341 |
xPathQuery = ClientFgdcHelper.XPATH_QUERY_TEMPLATE.replaceFirst("%1$s", lastDocId);
|
|
341 |
xPathQuery = ClientFgdcHelper.XPATH_QUERY_TEMPLATE.replaceFirst("%1s", lastDocId); |
|
342 | 342 |
//*** Update the metadata with the new Doc Id version. |
343 | 343 |
newDocId = nextVersion(lastDocId, xPathQuery); |
344 | 344 |
//*** Upload the metadata file to metacat. |
... | ... | |
353 | 353 |
} |
354 | 354 |
} else { |
355 | 355 |
//*** This is a data file. |
356 |
result = "This is a data file.";
|
|
356 |
result = "This is a data file. action: " + action + " lastDocId: " + lastDocId + " fNm: " + fNm;
|
|
357 | 357 |
|
358 | 358 |
//newDocId = "TODO"; |
359 | 359 |
//reader = null; //TODO |
... | ... | |
449 | 449 |
Vector optGroup; |
450 | 450 |
final String DOCID_EXPR = "./docid"; |
451 | 451 |
final String DOCNAME_EXPR = "./createdate"; |
452 |
final String PARAM_EXPR = "./param[@name='%1$s']";
|
|
452 |
final String PARAM_EXPR = "./param[@name='%1s']"; |
|
453 | 453 |
|
454 | 454 |
path = clientViewBean.getPathExpr(); |
455 | 455 |
returnFld = clientViewBean.getReturnfield(); |
... | ... | |
457 | 457 |
|
458 | 458 |
result = new TreeMap(); |
459 | 459 |
//paramExpr = String.format(PARAM_EXPR, returnFld); |
460 |
paramExpr = PARAM_EXPR.replaceFirst("%1$s", returnFld);
|
|
460 |
paramExpr = PARAM_EXPR.replaceFirst("%1s", returnFld); |
|
461 | 461 |
//*** Query the database *** |
462 | 462 |
doc = query(path, value, returnFld); |
463 | 463 |
//*** Build the TreeMap to return *** |
... | ... | |
566 | 566 |
String result = null, tokens[], scope, ready2Split, tmp; |
567 | 567 |
int vers, docNum; |
568 | 568 |
final int LAST_TOKEN = 2; |
569 |
final String TEMPLATE = "%1$s.%2$d.%3$d";
|
|
569 |
final String TEMPLATE = "%1s.%2d.%3d";
|
|
570 | 570 |
Node node; |
571 | 571 |
|
572 | 572 |
//*** Parse the last Doc Id, and increment the version number. |
... | ... | |
579 | 579 |
try { |
580 | 580 |
vers = Integer.parseInt(tokens[LAST_TOKEN]); |
581 | 581 |
//result = String.format(TEMPLATE, scope, docNum, 1 + vers); |
582 |
tmp = TEMPLATE.replaceFirst("%1$s", scope);
|
|
583 |
tmp = tmp.replaceFirst("%2$d", String.valueOf(docNum));
|
|
584 |
result = tmp.replaceFirst("%3$d", String.valueOf(vers + 1));
|
|
582 |
tmp = TEMPLATE.replaceFirst("%1s", scope); |
|
583 |
tmp = tmp.replaceFirst("%2d", String.valueOf(docNum)); |
|
584 |
result = tmp.replaceFirst("%3d", String.valueOf(vers + 1)); |
|
585 | 585 |
|
586 | 586 |
} catch (NumberFormatException ex) { |
587 | 587 |
//*** In case the lastDocId has something other than a number. |
588 | 588 |
//result = String.format(TEMPLATE, scope, docNum, 1); |
589 |
tmp = TEMPLATE.replaceFirst("%1$s", scope);
|
|
590 |
tmp = tmp.replaceFirst("%2$d", String.valueOf(docNum));
|
|
591 |
result = tmp.replaceFirst("%3$d", "1");
|
|
589 |
tmp = TEMPLATE.replaceFirst("%1s", scope); |
|
590 |
tmp = tmp.replaceFirst("%2d", String.valueOf(docNum)); |
|
591 |
result = tmp.replaceFirst("%3d", "1"); |
|
592 | 592 |
} |
593 | 593 |
} else { |
594 | 594 |
//*** In case the lastDocId ends with a '.' |
... | ... | |
609 | 609 |
private String nextDocId(String lastDocId, String scope) { |
610 | 610 |
String result = null, tokens[], tmp; |
611 | 611 |
int vers; |
612 |
String template = scope.toLowerCase() + ".%1$d.%2$d";
|
|
612 |
String template = scope.toLowerCase() + ".%1d.%2d";
|
|
613 | 613 |
|
614 | 614 |
if(lastDocId != null && lastDocId.contains(".")) { |
615 | 615 |
lastDocId = lastDocId.replace('.','~'); //*** This is necessary for the split to work. |
... | ... | |
618 | 618 |
try { |
619 | 619 |
vers = Integer.parseInt(tokens[1]); |
620 | 620 |
//result = String.format(template, 1 + vers, 1); |
621 |
tmp = template.replaceFirst("%1$d", String.valueOf(1 + vers));
|
|
622 |
result = tmp.replaceFirst("%2$d", "1");
|
|
621 |
tmp = template.replaceFirst("%1d", String.valueOf(1 + vers)); |
|
622 |
result = tmp.replaceFirst("%2d", "1"); |
|
623 | 623 |
} catch (NumberFormatException ex) { |
624 | 624 |
//*** In case the lastDocId has something other than a number. |
625 | 625 |
//result = String.format(template, 1, 1); |
626 |
tmp = template.replaceFirst("%1$d", "1");
|
|
627 |
result = tmp.replaceFirst("%2$d", "1");
|
|
626 |
tmp = template.replaceFirst("%1d", "1"); |
|
627 |
result = tmp.replaceFirst("%2d", "1"); |
|
628 | 628 |
} |
629 | 629 |
} else { |
630 | 630 |
//*** In case the lastDocId ends with a '.' |
631 | 631 |
//result = String.format(template, 1, 1); |
632 |
tmp = template.replaceFirst("%1$d", "1");
|
|
633 |
result = tmp.replaceFirst("%2$d", "1");
|
|
632 |
tmp = template.replaceFirst("%1d", "1"); |
|
633 |
result = tmp.replaceFirst("%2d", "1"); |
|
634 | 634 |
} |
635 | 635 |
} else { |
636 | 636 |
//*** In case there isn't any doc Id's with the user name. |
637 | 637 |
//result = String.format(template, 1, 1); |
638 |
tmp = template.replaceFirst("%1$d", "1");
|
|
639 |
result = tmp.replaceFirst("%2$d", "1");
|
|
638 |
tmp = template.replaceFirst("%1d", "1"); |
|
639 |
result = tmp.replaceFirst("%2d", "1"); |
|
640 | 640 |
} |
641 | 641 |
return(result); |
642 | 642 |
} |
Also available in: Unified diff
Changes to make java 1.4 compliant.