Changeset 22300
- Timestamp:
- 2010-06-24T13:45:34+12:00 (14 years ago)
- Location:
- other-projects/gs3-webservices-java-client/trunk/src/GS3Fedora/org/greenstone/fedora/services
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/gs3-webservices-java-client/trunk/src/GS3Fedora/org/greenstone/fedora/services/FedoraCommons.java
r15222 r22300 88 88 } 89 89 90 /** Given a n Element, this will return its String representation properly90 /** Given a DOM node, this will return its String representation properly 91 91 * indented for display. 92 * @return a string representation of e, formatted for display.93 * @param e is the elementto be converted to its string representation.92 * @return a string representation of n, formatted for display. 93 * @param n is the DOM node to be converted to its string representation. 94 94 */ 95 public static String elementToFormattedString(Element e) 96 throws TransformerException 95 public static String displayAsString(Node n) 97 96 { 98 DOMSource domSource = new DOMSource(e); 99 Transformer transformer = TransformerFactory.newInstance().newTransformer(); 100 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); 101 //transformer.setOutputProperty(OutputKeys.METHOD, "xml"); 102 //transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); 103 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); 104 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 97 try { 98 99 DOMSource domSource = new DOMSource(n); 100 Transformer transformer = TransformerFactory.newInstance().newTransformer(); 101 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); 102 //transformer.setOutputProperty(OutputKeys.METHOD, "xml"); 103 //transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); 104 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); 105 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 106 107 StringWriter sw = new StringWriter(); 108 transformer.transform(domSource, new StreamResult(sw)); 109 return sw.toString(); 110 } catch(Exception e) { 111 System.err.println("Couldn't display node as String."); 112 return ""; 113 } 114 115 } 105 116 106 StringWriter sw = new StringWriter(); 107 transformer.transform(domSource, new StreamResult(sw)); 108 return sw.toString(); 109 } 117 110 118 } -
other-projects/gs3-webservices-java-client/trunk/src/GS3Fedora/org/greenstone/fedora/services/FedoraConnection.java
r21855 r22300 20 20 21 21 package org.greenstone.fedora.services; 22 22 import org.greenstone.gsdl3.util.GSXML; 23 23 24 24 import fedora.client.utility.AutoFinder; … … 95 95 96 96 /* Some fixed strings of known literals */ 97 protected static final String TYPE = "type";98 protected static final String INTERNAL_NODE = "internalNode";99 97 protected static final String GET= "/get/"; 100 98 … … 632 630 * @see <a href="http://www.fedora.info/definitions/1/0/api/Fedora-API-A.html">Fedora access API, API-A for method findObjects</a> 633 631 * @see <a href="http://www.fedora.info/definitions/1/0/types/#complexType_FieldSearchQuery_Link031D7D80">XML type definition of FieldSearchQuery</a> 634 * @see <a href="http://www.fedora.info/download/2.2.1/javadocs/fedora/server/types/gen/FieldSearchQuery.html >Type definition of 2.2.1 FieldSearchQuery</a>632 * @see <a href="http://www.fedora.info/download/2.2.1/javadocs/fedora/server/types/gen/FieldSearchQuery.html">Type definition of 2.2.1 FieldSearchQuery</a> 635 633 * @see <a href="http://www.fedora.info/download/2.1.1/userdocs/server/serverdocs/fedora/server/search/FieldSearchQuery.html">does not apply: type definition of 2.1.1 FieldSearchQuery</a> 636 634 * @see <a href="http://john.drc-dev.ohiolink.edu/browser/drc-core/trunk/src/java/edu/ohiolink/drc/drcdl/BrowseController.java?rev=462">BrowseController.java for an example</a> … … 1237 1235 } 1238 1236 1239 /** @return the XML content of the TOC of just that portion of the TOC which 1240 * contains the section denoted by sectionID and its direct child subsections. 1241 * The children are returned in the order they are encountered, which 1242 * happens to be in the required order of ascending sectionID. 1243 * @param docPID - a fedora pid identifying a greenstone document object. 1244 * @param sectionID - identifyies the particular section in the 1245 * document denoted by docPID, may be a section name or number. */ 1246 public Element getChildrenOfSectionXML(String docPID, String sectionID) 1247 throws RemoteException, UnsupportedEncodingException, 1248 SAXException, IOException 1249 { 1250 // Store just the number 1251 String sectionNumber = removePrefix(sectionID, SECTION); 1252 // get the TOC XML datastream as a String 1253 String xmlTOC = getTOC(docPID); 1254 1255 // convert it into a DOM document 1256 InputSource source = new InputSource(new StringReader(xmlTOC)); 1257 Document doc = builder.parse(source); 1258 // toplevel element docEl = <Section id="1"></Section> 1259 Element docEl = doc.getDocumentElement(); 1260 1261 // check whether we're requested to return the toplevel element itself 1262 if(sectionID.equals("") || // subSection of entire docPID is requested 1263 (docEl.hasAttribute(ID) && docEl.getAttribute(ID).equals(sectionNumber))) 1264 return getSubstructure(docEl, false); 1265 1266 // Otherwise, get all <Section> elements and find the 1267 // <Section id="sectionNumber"></Section> and return that and its 1268 // children 1269 NodeList sections = docEl.getElementsByTagName(SECTION_ELEMENT); 1270 for(int i = 0; i < sections.getLength(); i++) { 1271 Element e = (Element)sections.item(i); 1272 if(e.hasAttribute(ID) 1273 && e.getAttribute(ID).equals(sectionNumber)) 1274 { 1275 //System.err.println("Found: " + e.getAttribute(ID)); 1276 return getSubstructure(e, false); // false: get just e and children 1277 } 1278 } 1279 return null; // not found 1280 } 1281 1282 /** @return a string representing the XML content of the TOC of just 1283 * that portion of the TOC which contains the section denoted by sectionID 1284 * and its direct child subsections. 1285 * The children are returned in the order they are encountered, which 1286 * happens to be in the required order of ascending sectionID. 1287 * @param docPID - a fedora pid identifying a greenstone document object. 1288 * @param sectionID - identifyies the particular section in the 1289 * document denoted by docPID, may be a section name or number. */ 1290 public String getChildrenOfSection(String docPID, String sectionID) 1291 throws RemoteException, UnsupportedEncodingException, 1292 SAXException, IOException, TransformerException 1293 { 1294 Element children = getChildrenOfSectionXML(docPID, sectionID); 1295 return (children == null) ? "" : FedoraCommons.elementToString(children); 1296 } 1297 1298 /** @return the part of the TOC XML file (which outlines doc structure) 1299 * relating to the given section. This includes the section denoted by 1300 * sectionID as well as all descendent subsections thereof. 1301 * @param docPID - a fedora pid identifying a greenstone document object. 1302 * @param sectionID - identifyies the particular section in the 1303 * document denoted by docPID, may be a section name or number. */ 1304 public Element getSubsectionXML(String docPID, String sectionID) 1305 throws RemoteException, UnsupportedEncodingException, 1306 SAXException, IOException 1307 { 1308 // get the TableOfContents (TOC) XML datastream as a String 1309 String xmlTOC = getTOC(docPID); 1310 1311 // convert it into a DOM document 1312 InputSource source = new InputSource(new StringReader(xmlTOC)); 1313 Document doc = builder.parse(source); 1314 // toplevel element docEl = <Section id="1"></Section> 1315 Element docEl = doc.getDocumentElement(); 1316 1317 if(sectionID.equals("")) // subSection of entire docPID is requested 1318 return docEl; 1319 1320 // Store just the number 1321 String sectionNumber = removePrefix(sectionID, SECTION); 1322 // Check whether we're requested to return the toplevel element itself 1323 // If sectionNumber=1, then the top-level element/document element 1324 // of the TOC XML is requested, so return the TOC as is. 1325 if(sectionNumber.equals("1")) { 1326 return docEl; 1327 } 1328 1329 // Get all <Section> elements and find the 1330 // <Section id="sectionNumber"></Section> and return that 1331 NodeList sections = docEl.getElementsByTagName(SECTION_ELEMENT); 1332 for(int i = 0; i < sections.getLength(); i++) { 1333 Element e = (Element)sections.item(i); 1334 if(e.hasAttribute(ID) 1335 && e.getAttribute(ID).equals(sectionNumber)) { 1336 //System.err.println("Found: " + e.getAttribute(ID)); 1337 return getSubstructure(e, true); // true:get all descendents 1338 } 1339 } 1340 return null; // not found 1341 } 1342 1343 /** @return a String representation of the part of the TOC XML file 1344 * (which outlines doc structure) relating to the given section. This 1345 * includes the section denoted by sectionID as well as all descendent 1346 * subsections thereof. 1347 * @param docPID a fedora pid identifying a greenstone document object. 1348 * @param sectionID identifyies the particular section in the 1349 * document denoted by docPID, may be a section name or number. */ 1350 public String getSubsection(String docPID, String sectionID) 1351 throws RemoteException, UnsupportedEncodingException, SAXException, 1352 IOException, TransformerException 1353 { 1354 // Store just the number 1355 String sectionNumber = removePrefix(sectionID, SECTION); 1356 // get the TableOfContents (TOC) XML datastream as a String 1357 String xmlTOC = getTOC(docPID); 1358 1359 // Check whether we're requested to return the toplevel element itself 1360 // If sectionNumber=1, then the top-level element/document element 1361 // of the TOC XML is requested, so return the TOC as is. 1362 if(sectionNumber.equals("1")) 1363 return xmlTOC; 1364 1365 // else 1366 Element subsection = getSubsectionXML(docPID, sectionID); 1367 return (subsection == null) ? "" : FedoraCommons.elementToString(subsection); 1368 } 1237 /** Given a documentNode element, adds the nodetype attribute to all of its 1238 * docNode descendants. The nodetype is either Root, Internal or Leaf to indicate 1239 * whether the docnode is a toplevel document Node, or has children or has none. 1240 * @param e - the documentNode element whose descendants' nodetypes will be set 1241 * at method's end. */ 1242 protected void addNodeTypeToDescendants(Element e) { 1243 NodeList sections = e.getElementsByTagName(SECTION_ELEMENT); 1244 for(int i = 0; i < sections.getLength(); i++) { 1245 Element section = (Element)sections.item(i); 1246 NodeList descendants = section.getElementsByTagName(SECTION_ELEMENT); 1247 if(descendants.getLength() > 0) { 1248 // if there are any descendants (which includes children) that are SECTIONS 1249 section.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERNAL); 1250 } else { 1251 section.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF); 1252 } 1253 } 1254 } 1255 1256 1257 /** @return the part of the TOC XML file (which outlines doc structure) 1258 * relating to the given section. This includes the section denoted by 1259 * sectionID as well as all descendent subsections thereof. 1260 * @param docPID - a fedora pid identifying a greenstone document object. 1261 * @param sectionID - identifyies the particular section in the 1262 * document denoted by docPID, may be a section name or number. 1263 * @param structure can contain any combination of: ancestors, parent, 1264 * siblings, children, descendants, entire, specifying the portion of 1265 * the structure to retrieve. 1266 * @param info can contain any combination of: siblingPosition, numSiblings, 1267 * numChildren, requesting additional information about the structure. */ 1268 public Element getSectionStructureXML(String docPID, String sectionID, String structure, String info) 1269 throws RemoteException, UnsupportedEncodingException, SAXException, IOException 1270 { 1271 // get the TableOfContents (TOC) XML datastream as a String 1272 String xmlTOC = getTOC(docPID); 1273 1274 // convert it into a DOM document 1275 InputSource source = new InputSource(new StringReader(xmlTOC)); 1276 Document doc = builder.parse(source); 1277 // toplevel element docEl = <Section id="1"></Section> 1278 Element docEl = doc.getDocumentElement(); 1279 addNodeTypeToDescendants(docEl); 1280 docEl.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT); 1281 1282 if(structure.indexOf("entire") != -1) { // don't need to find the specific section, doc root is what's required 1283 docEl = getStructureInfo(docEl.getOwnerDocument(), docEl, info); 1284 return docEl; 1285 } 1286 1287 if(sectionID.equals("")) { 1288 sectionID = "1"; 1289 } 1290 1291 // Store just the number 1292 String sectionNumber = removePrefix(sectionID, SECTION); 1293 // Check whether we're requested to return the toplevel element itself 1294 // If sectionNumber=1, then the top-level element/document element 1295 // of the TOC XML is requested, so return the TOC as is. 1296 if(sectionNumber.equals("1") && structure.indexOf("descendants") != -1) { 1297 docEl = getStructureInfo(docEl.getOwnerDocument(), docEl, info); 1298 return docEl; 1299 } 1300 1301 // if the root is the section required, return that 1302 if(docEl.getTagName().equals(SECTION_ELEMENT) 1303 && docEl.getAttribute(ID).equals(sectionNumber)) { 1304 Element substructure = getSubstructure(docEl, structure); 1305 return getStructureInfo(substructure.getOwnerDocument(), docEl, info); 1306 //return docEl; 1307 } 1308 1309 1310 // Else, get all <Section> elements and find the 1311 // <Section id="sectionNumber"></Section> and return that 1312 NodeList sections = docEl.getElementsByTagName(SECTION_ELEMENT); 1313 for(int i = 0; i < sections.getLength(); i++) { 1314 1315 Element e = (Element)sections.item(i); 1316 if(e.hasAttribute(ID) && e.getAttribute(ID).equals(sectionNumber)) { 1317 Element substructure = getSubstructure(e, structure); 1318 return getStructureInfo(substructure.getOwnerDocument(), e, info); 1319 } 1320 } 1321 1322 return null; // not found 1323 } 1324 1369 1325 1370 1326 /** Implements browsing document titles of a greenstone collection stored in 1371 1327 * the fedora repository by letter. 1372 1328 * @return the document pids whose titles start with the given letter. 1329 * @param collName - the name of the collection. 1373 1330 * @param letter - the starting letter to browse by. 1374 1331 */ … … 1435 1392 // We want to do the following kind of search (when written in Fedora's 1436 1393 // REST format - see http://localhost:8080/fedora/search): 1437 // pid~greenstone:<colname> * title~<1st word of titleContents>1394 // pid~greenstone:<colname>-* title~<1st word of titleContents> 1438 1395 1439 1396 // We don't need to normalise the word first (to search titles starting … … 1452 1409 // only pids of those titles that contain the entire phrase titleContents 1453 1410 1454 final String pid = GREENSTONE_+collName+ WILDCARD;1411 final String pid = GREENSTONE_+collName+HYPHEN+WILDCARD; 1455 1412 1456 1413 int indexOfFirstSpace = titleContents.indexOf(' '); // check for space … … 1562 1519 throws RemoteException, FedoraVersionNotSupportedException 1563 1520 { 1564 // Searching for pids of the form "greenstone:gs2mgdemo *";1565 final String pid = GREENSTONE_+collName+ WILDCARD;1521 // Searching for pids of the form "greenstone:gs2mgdemo-*"; 1522 final String pid = GREENSTONE_+collName+HYPHEN+WILDCARD; 1566 1523 1567 1524 Condition[] conditions = new Condition[2]; … … 1614 1571 return collPID.substring(collPID.indexOf(':')+1, collPID.indexOf('-')); 1615 1572 } 1616 1617 /** Convert the given Element to a String representing the same XML. 1618 * @return an element containing a copy element e with either only its child 1619 * elements or with all its descendents (depending on whether parameter 1620 * descendents is true or false). 1621 * @param e - the element to start copying from. 1622 * @param descendents - if true, e is copied with all its descendetns into the 1623 * element that's returned. If false, only e and its direct children are copied 1624 * @see <a href="http://forum.java.sun.com/thread.jspa?threadID=678472&tstart=30">Sun java thread on transforming a DOM XML to a String</a> 1625 */ 1626 protected Element getSubstructure(Element e, boolean descendents) 1627 { 1628 Document doc = builder.newDocument(); 1629 Node n = doc.importNode(e, descendents); 1630 // descendents=true: import/copy descendents. 1631 // Else, copy just current node e (later copy its direct children) 1632 doc.appendChild(n); // need to put the copied node into a document 1633 // else it won't have a parent doc (DOMSource can't work with it 1634 // without it having a document parent). 1635 1636 // if we are not recursively copying all descendents, then copy just 1637 // the childnodes: 1638 if(!descendents) { // then copy just the children 1639 // get e's children and copy them into the new document 1640 NodeList children = e.getChildNodes(); 1641 for(int i = 0; i < children.getLength(); i++) { 1642 // create copy 1643 n = doc.importNode(children.item(i), false); 1644 // attach it to parent 1645 doc.getDocumentElement().appendChild(n); 1646 1647 // Now we need to indicate whether this new node (child) is a leaf 1648 // or not. (This is necessary for getChildrenOfSection(), else 1649 // it's hard to know if the children are leaves or have further 1650 // subsections. 1651 if(n.getNodeName().equals(SECTION_ELEMENT)) { 1652 // we're dealing only with section children 1653 1654 // Check if the matching original had children: 1655 Element originalsChild = (Element)children.item(i); 1656 NodeList grandchildren = 1657 originalsChild.getElementsByTagName(SECTION_ELEMENT); 1658 if(grandchildren.getLength() > 0) { 1659 // original's child has children, so indicate this 1660 // in the copied child: 1661 Element child = (Element)n; 1662 child.setAttribute(TYPE, INTERNAL_NODE); 1663 } 1664 } 1573 1574 1575 /** Return the TOC substructure requested 1576 * @return an element containing a copy if element e with either only its child 1577 * elements or with all its descendants and/or its ancestors or only its parent 1578 * and/or its siblings (depending on what the parameter structure specifies). 1579 * @param e - the element to start copying from and whose structure is requested. 1580 * @param structure - a string containing any combination of the values: 1581 * ancestors, parent, siblings, children, descendants, 1582 * specifying the portion of the structure to retrieve. 1583 * @see <a href="http://forum.java.sun.com/thread.jspa?threadID=678472&tstart=30">Sun java thread on transforming a DOM XML to a String</a> 1584 */ 1585 protected Element getSubstructure(Element original, String structure) 1586 { 1587 Document doc = builder.newDocument(); 1588 1589 boolean descendants = (structure.indexOf("descendants") != -1) ? true : false; 1590 Node current = doc.importNode(original, descendants); 1591 1592 // descendants=true: import/copy descendants. 1593 // Else, copy just current node original (later copy its direct children) 1594 1595 Node parentOfCurrent = null; 1596 Node parentOfOriginal = original.getParentNode(); 1597 if(parentOfOriginal == original.getOwnerDocument()) { // don't want document node (original is docRoot) 1598 parentOfOriginal = null; 1599 } 1600 1601 if(parentOfOriginal == null) { // no parentNode, so current is the root node. 1602 // can't get ancestors/parent/siblings, since all these need parentNode 1603 doc.appendChild(current); 1604 } else { // siblings, ancestors and parent requests all require parent node to exist 1605 // First check if we need to get ancestors, else for whether parent is required 1606 if(structure.indexOf("ancestors") != -1) { 1607 parentOfCurrent = doc.importNode(parentOfOriginal, false); 1608 1609 Node child = null; 1610 Node parent = parentOfCurrent; // the copy 1611 Node n = parentOfOriginal.getParentNode(); // the doc to copy from 1612 1613 while(n != null && n != original.getOwnerDocument()) { 1614 child = parent; 1615 parent = doc.importNode(n, false); // no descendants 1616 parent.appendChild(child); 1617 n = n.getParentNode(); 1618 } 1619 1620 doc.appendChild(parent); // need to put the copied node into a document 1621 // else it won't have a parent doc (DOMSource can't work with it 1622 // without it having a document parent). 1623 1624 } else if(structure.indexOf("parent") != -1) { 1625 parentOfCurrent = doc.importNode(parentOfOriginal, false); 1626 //parentOfCurrent.appendChild(current); 1627 doc.appendChild(parentOfCurrent); 1628 } 1629 1630 // a request for siblings is independently tested for 1631 if(structure.indexOf("siblings") != -1) { 1632 // only import parent if we didn't already import 1633 // it for a request for ancestors or parent 1634 if(parentOfCurrent == null) { 1635 parentOfCurrent = doc.importNode(parentOfOriginal, false); 1636 doc.appendChild(parentOfCurrent); // this becomes the root 1637 } 1638 // now the siblings of current (children of parentOfCurrent) 1639 NodeList children = parentOfOriginal.getChildNodes(); 1640 for(int i = 0; i < children.getLength(); i++) { 1641 Node n = children.item(i); 1642 1643 if(n.getNodeName().equals(SECTION_ELEMENT)) { 1644 if((Element)n != original) { // skip original which was already imported 1645 Node child = doc.importNode(n, false); // no descendants 1646 parentOfCurrent.appendChild(child); 1647 } else { // already imported Current element, insert at this position 1648 parentOfCurrent.appendChild(current); 1649 } 1650 1651 } 1652 } 1653 } else if(parentOfCurrent != null) { // include current node for ancestors and parent requests 1654 // (sibling request adds the current node into a particular position) 1655 parentOfCurrent.appendChild(current); 1656 // need to put the copied node into a document 1657 // else it won't have a parent doc (DOMSource can't work with it 1658 // without it having a document parent). 1659 } else { // when only children or descendants were requested, current becomes root document 1660 doc.appendChild(current); 1661 } 1662 } 1663 1664 // if we are not recursively copying all descendants, then copy just 1665 // the childnodes of current: 1666 if(structure.indexOf("children") != -1 && !descendants) { // then copy just the children 1667 1668 // get e's children and copy them into the new document 1669 NodeList children = original.getChildNodes(); 1670 for(int i = 0; i < children.getLength(); i++) { 1671 // create copy 1672 Node n = doc.importNode(children.item(i), false); 1673 // attach it to parent 1674 current.appendChild(n); 1675 1676 // Now we need to indicate whether this new node (child) is a leaf 1677 // or not. (This is necessary for getChildrenOfSection(), else 1678 // it's hard to know if the children are leaves or have further 1679 // subsections. 1680 if(n.getNodeName().equals(SECTION_ELEMENT)) { 1681 // we're dealing only with section children 1682 1683 // Check if the matching original had children: 1684 Element originalsChild = (Element)children.item(i); 1685 NodeList grandchildren = originalsChild.getElementsByTagName(SECTION_ELEMENT); 1686 if(grandchildren.getLength() > 0) { 1687 // original's child has children, so indicate this 1688 // in the copied child: 1689 Element child = (Element)current; 1690 // child.setAttribute(TYPE, INTERNAL_NODE); 1691 1692 } 1693 } 1694 } 1695 } 1696 1697 return doc.getDocumentElement(); 1698 } 1699 1700 1701 /** Return the TOC substructure with the requested structural info. 1702 * @return an element containing a copy if element e with either only its child 1703 * elements or with all its descendants and/or its ancestors or only its parent 1704 * and/or its siblings (depending on what the parameter structure specifies). 1705 * Returns null if the element, e, passed in is null. 1706 * @param doc - the new document into whose root element the structural information 1707 * will be inserted as attributes. 1708 * @param e - the element to start copying from and whose structure is requested. 1709 * @param info - a string containing any combination of the values: numChildren, 1710 * numSiblings, siblingPosition. The requested info gets added as attributes to 1711 * the returned root element. 1712 * @see <a href="http://forum.java.sun.com/thread.jspa?threadID=678472&tstart=30">Sun java thread on transforming a DOM XML to a String</a> 1713 */ 1714 protected Element getStructureInfo(Document doc, Element e, String info) 1715 { 1716 if(e == null) { 1717 return null; 1718 } 1719 1720 Element root = doc.getDocumentElement(); 1721 1722 if(!info.equals("")) { 1723 if(info.indexOf("numChildren") != -1) { 1724 //int numChildren = e.getElementsByTagName(SECTION_ELEMENT).getLength(); 1725 int numChildren = 0; 1726 1727 NodeList children = e.getChildNodes(); 1728 for(int i = 0; i < children.getLength(); i++) { 1729 Node n = children.item(i); 1730 if(n.getNodeName().equals(SECTION_ELEMENT)) { 1731 numChildren++; 1732 } 1733 } 1734 1735 root.setAttribute("numChildren", Integer.toString(numChildren)); 1736 } 1737 1738 if(info.indexOf("ibling") != -1) { // siblingPosition or numSiblings 1739 int numSiblings = 0; 1740 int siblingPosition = 0; 1741 1742 Node parent = e.getParentNode(); 1743 if(parent == null) { 1744 numSiblings = 0; 1745 siblingPosition = 1; 1746 } else { 1747 //numSiblings = parent.getChildNodes().getLength(); 1748 NodeList siblings = parent.getChildNodes(); 1749 1750 for(int i = 0; i < siblings.getLength(); i++) { 1751 Node n = siblings.item(i); 1752 if(n.getNodeName().equals(SECTION_ELEMENT)) { 1753 if(e == (Element)n) { 1754 siblingPosition = numSiblings+1; 1755 } else { // count every sibling section element, except e itself 1756 numSiblings++; 1757 } 1665 1758 } 1666 } 1667 return doc.getDocumentElement(); 1668 } 1669 1670 1759 } 1760 } 1761 1762 if(info.indexOf("numSiblings") != -1) { 1763 root.setAttribute("numSiblings", Integer.toString(numSiblings)); 1764 } 1765 1766 if(info.indexOf("siblingPosition") != -1) { 1767 root.setAttribute("siblingPosition", Integer.toString(siblingPosition)); 1768 } 1769 } 1770 } 1771 1772 return root; 1773 } 1774 1775 1671 1776 /** 1672 1777 * Return a datastream of a document, given the document's id … … 1790 1895 String sectionID = "SECTION1"; //SECTION1.5 1791 1896 System.out.println("\n"); 1792 System.out.println(sectionID+ " - entire subsection:\n"1793 + fedoraCon.getSubsection(docPID, sectionID));1794 1795 System.out.println(sectionID + " and children:\n"1796 + fedoraCon.getChildrenOfSection(docPID, sectionID));1797 1897 1798 1898 System.out.println( … … 1816 1916 System.out.println("Unable to instantiate FedoraConnection\n" + e); 1817 1917 e.printStackTrace(); 1818 //LOG.error("Unable to instantiate FedoraConnection\n" + e );1918 //LOG.error("Unable to instantiate FedoraConnection\n" + e, e); 1819 1919 } 1820 1920 } -
other-projects/gs3-webservices-java-client/trunk/src/GS3Fedora/org/greenstone/fedora/services/FedoraGS3Connection.java
r21924 r22300 90 90 * then query services will not be offered */ 91 91 protected String[] serviceNames; 92 93 /** constant CHILDREN indicates that a DocumentStructureRetrieve is to94 * return only the child nodes of a section, not any further descendants */95 protected static final int CHILDREN = 0;96 97 /** constant DESCENDANTS indicates that a DocumentStructureRetrieve is to98 * return all descendants of a section */99 protected static final int DESCENDANTS = 1;100 92 101 93 /** The object used to connect to FedoraGenericSearch, which is used … … 362 354 * @return a GS3 DocumentMetadataRetrieve response message containing the 363 355 * EX metadata for all the requested collections */ 364 365 return getMetadata(collIDs);356 public String getCollectionMetadata(String[] collIDs) { 357 return getMetadata(collIDs, new String[] {"all"}); 366 358 } 367 359 … … 372 364 * "<pid>-sectionNumber". 373 365 * @return a GS3 DocumentMetadataRetrieve response message containing the 374 * EX, DC, DLS metadata for all the requested documents */ 375 public String getDocumentMetadata(String[] docIDs) { 376 return getMetadata(docIDs); 366 * EX, DC, DLS metadata for all the requested documents 367 * @param metadata is the list of metadata elements to be retrieved for each doc */ 368 public String getDocumentMetadata(String[] docIDs, String[] metadata) { 369 return getMetadata(docIDs, metadata); 377 370 } 378 371 … … 381 374 * @param collID is a fedora pid identifying a collection in its repository 382 375 * @return a GS3 DocumentMetadataRetrieve response message containing the 383 * EX metadata for the requested collection */ 376 * EX metadata for the requested collection 377 * @param metadata is the list of metadata elements to be retrieved for each doc */ 384 378 public String getCollectionMetadata(String collID) { 385 return getMetadata(new String[] {collID});379 return getMetadata(new String[] {collID}, new String[] {"all"}); 386 380 } 387 381 … … 393 387 * @return a GS3 DocumentMetadataRetrieve response message containing the 394 388 * EX, DC, DLS metadata for the requested document */ 395 public String getDocumentMetadata(String docID) {396 return getMetadata(new String[] {docID});389 public String getDocumentMetadata(String docID, String[] metadata) { 390 return getMetadata(new String[] {docID}, metadata); 397 391 } 398 392 … … 402 396 * fedora pids for collections, or otherwise may be a document identifier. 403 397 * In the last case, the document ID may consist of either 404 * "documentPID-sectionNumber" or may just be just fedora documentPID */ 405 public String getMetadata(String[] docIDsOrCollIDs) 398 * "documentPID-sectionNumber" or may just be just fedora documentPID 399 * @param metadata is the list of metadata elements to be retrieved for each doc */ 400 public String getMetadata(String[] docIDsOrCollIDs, String[] metadata) 406 401 { 407 402 Document doc = builder.newDocument(); … … 415 410 // create the <documentNode> containing the metadata 416 411 // for each document docID 417 Element docNode = getMetadata(doc, docIDsOrCollIDs[i]);412 Element docNode = getMetadata(doc, docIDsOrCollIDs[i], metadata); 418 413 docNodeList.appendChild(docNode); 419 414 } … … 426 421 GSXML.REQUEST_TYPE_PROCESS, "DocumentMetadataRetrieve"); 427 422 try{ 428 return FedoraCommons.elementTo FormattedString(responseMsg);423 return FedoraCommons.elementToString(responseMsg); 429 424 } catch(TransformerException e) { 430 425 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg … … 444 439 * document given by parameter ID 445 440 * @param id denotes a collection pid, a document pid or a docID of the 446 * form "documentpid-sectionNumber" */ 447 protected Element getMetadata(Document doc, String id) 441 * form "documentpid-sectionNumber" 442 * @param metadata is the list of metadata elements to be retrieved for each doc */ 443 protected Element getMetadata(Document doc, String id, String[] metadata) 448 444 throws RemoteException, UnsupportedEncodingException, 449 445 SAXException, IOException … … 500 496 } 501 497 498 String metafields = ""; 499 for(int i = 0; i < metadata.length; i++) { 500 metafields = metafields + metadata[i] + "|"; 501 } 502 502 503 // Adding in metadata sets in alphabetical order 503 504 // DC metadata for a top-level document is different from EX, DLS: … … 506 507 if(!dc.equals("")) { 507 508 addMetadataWithNamespacedTagNames(doc, metadataList, 508 dc, DC);509 dc, DC, metafields); 509 510 } 510 511 … … 513 514 // in which case, dls and dc will be non-empty strings 514 515 if(!dls.equals("")) { 515 addMetadataWithFixedTagName(doc, metadataList, dls, DLS);516 addMetadataWithFixedTagName(doc, metadataList, dls, DLS, metafields); 516 517 } 517 518 … … 519 520 // collection object, top-level document object, 520 521 // and document section item 521 addMetadataWithFixedTagName(doc, metadataList, ex, EX );522 addMetadataWithFixedTagName(doc, metadataList, ex, EX, metafields); 522 523 523 524 // now the metadataList has been built up … … 539 540 * Dublin Core metadata stored in the Fedora repository). 540 541 * @param metadataSet is the constant datastream identifier, e.g. "DC". 541 * At present this method only applies to the DC metadata as that's the only 542 * one where each tagname is different except for the constant dc: namespace. 542 * At present this method applies to the DC metadata and any others like it 543 * where each tagname is different except for the constant dc: namespace. 544 * @param metafields is a | separated string containing the metadatafields to 545 * extract or "all" if all fields are requested 543 546 */ 544 protected void addMetadataWithNamespacedTagNames(Document doc, 545 Element metadataList, String metaDatastream, String metadataSet)547 protected void addMetadataWithNamespacedTagNames(Document doc, Element metadataList, 548 String metaDatastream, String metadataSet, String metafields) 546 549 throws SAXException, IOException 547 550 { … … 551 554 // The following doesn't work for some reason: to retrieve all elements 552 555 // whose namespace prefix starts with "dc", we pass "*" for localName 553 //NodeList dcMetaTags = src.getElementsByTagNameNS( DC.toLowerCase(), "*");556 //NodeList dcMetaTags = src.getElementsByTagNameNS(metadataSet.toLowerCase(), "*"); 554 557 555 558 // Longer way: get the children of the root document … … 558 561 for(int i = 0; i < children.getLength(); i++) { 559 562 String nodeName = children.item(i).getNodeName(); 560 // check that the nodename starts with the "dc"namespace,563 // check that the nodename starts with the metadataSet ("dc") namespace, 561 564 // which simultaneously ensures that the node's an element: 562 if(nodeName.startsWith(DC.toLowerCase())) { 563 // need to have a period for Greenstone instead of Fedora's colon 564 nodeName = nodeName.replace(COLON, PERIOD); 565 if(nodeName.toLowerCase().startsWith(metadataSet.toLowerCase())) { 566 // need to have a period for Greenstone instead of Fedora's colon 567 nodeName = nodeName.replace(COLON, PERIOD); 568 if(metadataSet.equals(DC)) { // dc:title -> dc.Title 569 nodeName = "dc" + PERIOD + Character.toString(Character.toUpperCase(nodeName.charAt(3))) 570 + nodeName.substring(4); 571 } 572 573 // get the requested metadata fields 574 if(metafields.indexOf("all") != -1 || metafields.indexOf(nodeName) != -1) { 565 575 Element metatag = (Element)children.item(i); 566 576 String value = FedoraCommons.getValue(metatag); 567 577 // <dc:tagname>value</dc:tagname> 568 // we're going to put usethis in our metadata element as569 // <metadata name="dc :tagname">value</metadata>578 // we're going to put this in our metadata element as 579 // <metadata name="dc.Tagname">value</metadata> 570 580 571 581 // create metadata of (name, value) pairs in target DOM (doc) 572 582 Element metadata = doc.createElement(GSXML.METADATA_ELEM); 573 583 Attr attribute = doc.createAttribute(GSXML.NAME_ATT); 584 574 585 attribute.setValue(nodeName); 575 586 metadata.setAttributeNode(attribute); … … 577 588 metadata.appendChild(content); 578 589 metadataList.appendChild(metadata); 590 } 579 591 } 580 592 } … … 586 598 * is the name of the metadata (like author, title). For each element 587 599 * it creates a corresponding new element of the form 588 * <metadata name="namespace:metadataName">value</metadata>. Each of these589 * are then appended to the metadataList parameter.600 * <metadata name="namespace:metadataName">value</metadata>. 601 * Each of these are then appended to the metadataList parameter. 590 602 * @param doc is the Document object using which the new metadata Elements 591 603 * are to be constructed … … 599 611 * At present this method applies to the DLS and EX metadata as they have 600 612 * constant tagnames throughout. 613 * @param metafields is a | separated string containing the metadatafields to 614 * extract or "all" if all fields are requested. 601 615 */ 602 protected void addMetadataWithFixedTagName(Document doc, 603 Element metadataList, String metaDatastream, String metadataSet)616 protected void addMetadataWithFixedTagName(Document doc, Element metadataList, 617 String metaDatastream, String metadataSet, String metafields) 604 618 throws SAXException, IOException 605 619 { … … 630 644 name = name + HYPHEN + metatag.getAttribute(QUALIFIER); 631 645 } 632 String value = FedoraCommons.getValue(metatag); 633 634 // create metadata of (name, value) pairs in target DOM (doc) 635 Element metadata = doc.createElement(GSXML.METADATA_ELEM); 636 Attr attribute = doc.createAttribute(GSXML.NAME_ATT); 637 attribute.setValue(namespacePrefix + name); 638 // prefix with namespace, if any 639 metadata.setAttributeNode(attribute); 640 Text content = doc.createTextNode(value); 641 metadata.appendChild(content); 642 643 metadataList.appendChild(metadata); 646 name = namespacePrefix + name; // prefix with namespace, if any 647 if(metafields.indexOf("all") != -1 || metafields.indexOf(name) != -1) { 648 String value = FedoraCommons.getValue(metatag); 649 650 // create metadata of (name, value) pairs in target DOM (doc) 651 Element metadata = doc.createElement(GSXML.METADATA_ELEM); 652 Attr attribute = doc.createAttribute(GSXML.NAME_ATT); 653 attribute.setValue(name); 654 metadata.setAttributeNode(attribute); 655 Text content = doc.createTextNode(value); 656 metadata.appendChild(content); 657 658 metadataList.appendChild(metadata); 659 } 644 660 } 645 661 } … … 688 704 GSXML.REQUEST_TYPE_PROCESS, "DocumentMetadataRetrieve"); 689 705 try{ 690 return FedoraCommons.elementTo FormattedString(responseMsg);706 return FedoraCommons.elementToString(responseMsg); 691 707 } catch(TransformerException e) { 692 708 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg … … 747 763 } 748 764 749 750 /** @return the documentStructure of the document or section given by docID. 751 * The structure is returned in the XML format of a Greenstone3 752 * DocumentStructureRetrieve response message. This method returns the entire 753 * subSection of the docID (that is, all descendants included). 754 * @param docID the identifier for the document whose structure is required. 755 * This is of the format "greenstone:<collectionName>-<docPID>" 756 * OR "greenstone:<collectionName>-<docPID>-<sectioNumber>" 757 * where "greenstone:<collectionName>-<docPID>-1" is the same as 758 * "greenstone:<collectionName>-<docPID>" and will return the 759 * same response */ 760 public String getDocumentStructure(String docID) { 761 return getStructure(new String[]{docID}, DESCENDANTS); 762 } 763 764 /** @return a view of the structure of the document or section given by docID 765 * which contains only the section and its direct children. This structure is 766 * returned in the XML format of a Greenstone3 DocumentStructureRetrieve 767 * response message. 768 * @param docID the identifier for the document whose structure is required. 769 * This is of the format "greenstone:<collectionName>-<docPID>" 770 * OR "greenstone:<collectionName>-<docPID>-<sectioNumber>" 771 * where "greenstone:<collectionName>-<docPID>-1" is the same as 772 * "greenstone:<collectionName>-<docPID>" and will return the 773 * same response */ 774 public String getChildren(String docID) { 775 return getStructure(new String[]{docID}, CHILDREN); 776 } 777 778 /** @return the documentStructure of the documents or sections given by docIDs. 779 * The structure is returned in the XML format of a Greenstone3 780 * DocumentStructureRetrieve response message. This method returns the entire 781 * subSection of each docID (that is, all descendants included). 782 * @param docIDs is an array of identifiers for the documents whose structures 783 * are required. 784 * This is of the format "greenstone:<collectionName>-<docPID>" 785 * OR "greenstone:<collectionName>-<docPID>-<sectioNumber>" 786 * where "greenstone:<collectionName>-<docPID>-1" is the same as 787 * "greenstone:<collectionName>-<docPID>" and will return the 788 * same response */ 789 public String getDocumentStructure(String[] docIDs) { 790 return getStructure(docIDs, DESCENDANTS); 791 } 792 793 /** @return the documentStructure of the documents or sections given by docIDs 794 * but only the sections and their children (not any further descendants). 795 * The structure is returned in the XML format of a Greenstone3 796 * DocumentStructureRetrieve response message. 797 * @param docIDs the identifiers for the documents whose structures are 798 * required. The docids are of the format "greenstone:<collectionName>-<docPID>" 799 * OR "greenstone:<collectionName>-<docPID>-<sectioNumber>" 800 * where "greenstone:<collectionName>-<docPID>-1" is the same as 801 * "greenstone:<collectionName>-<docPID>" and will return the 802 * same response */ 803 public String getChildren(String[] docIDs) { 804 return getStructure(docIDs, CHILDREN); 805 } 806 807 /** 765 /** @return a String representing Greenstone3 DocumentMetadataRetrieve XML 766 * containing the requested portion of the document structure of the documents 767 * indicated by docIDs: 768 * @param docID is the document identifier of the document whose hierarchical 769 * structure is requested. The name of the collection is already included in the 770 * docID for a Fedora DL. 771 * @param structure - strings specifying the required structure of the document. 772 * It can be a combination of: ancestors, parent, siblings, children, descendants, entire. 773 * @param info - strings specifying the required structural info of the document. 774 * It can be any combination of: siblingPosition, numSiblings, numChildren. 775 */ 776 public String getDocumentStructure(String docID, String[] structure, String[] info) { 777 return getStructure(new String[]{docID}, structure, info); 778 } 779 780 781 /** @return a String representing Greenstone3 DocumentMetadataRetrieve XML 782 * containing the requested portion of the document structure of the documents 783 * indicated by docIDs: 784 * @param docIDs is an array of document identifiers of documents whose 785 * hierarchical structures are requested. The name of the collection is already 786 * included in the docID for a Fedora DL. 787 * @param structure - strings specifying the required structure of each document. 788 * It can be a combination of: ancestors, parent, siblings, children, descendants, entire. 789 * @param info - strings specifying the required structural info of each document. 790 * It can be any combination of: siblingPosition, numSiblings, numChildren. 791 */ 792 public String getDocumentStructure(String[] docIDs, String[] structure, String[] info) { 793 return getStructure(docIDs, structure, info); 794 } 795 796 /** 808 797 * Returns a greenstone3 DocumentStructureRetrieve XML response message 809 798 * containing the document structures for the given docIDs. … … 814 803 * @param docIDs the documentIDs for which the section's structure is returned; 815 804 * where a docID is either a fedora pid <docPID> or <docPID>-<sectionNumber>. 816 * @param levels - either CHILDREN or DESCENDANTS. 817 * CHILDREN returns only the first-level descendants (children) of the 818 * requested document sections indicated by docIDs. 819 * DESCENDANTS returns all descendants of all the document-sections denoted by 820 * docIDs. 805 * @param structure - the structure of the sections to return. Can be any combination of: 806 * ancestors, parent, siblings, children, descendants, entire. 807 * @param infos - strings containing any combination of the values: numChildren, numSiblings, 808 * siblingPosition. The requested info gets added as attributes to the returned root element. 821 809 * @return a greenstone3 DocumentStructureRetrieve XML response message in 822 810 * String format with the structure of the docIDs requested. 823 811 */ 824 protected String getStructure(String[] docIDs, int levels)812 protected String getStructure(String[] docIDs, String[] structure, String[] infos) 825 813 { 826 814 Document doc = builder.newDocument(); … … 833 821 // append the <documentNodes> for the docIDs 834 822 // to the docNodeList 835 getStructureElement(docNodeList, docIDs, levels); 823 //getStructureElement(docNodeList, docIDs, levels); 824 getStructureElement(docNodeList, docIDs, structure, infos); 836 825 } catch(Exception e) { 837 826 ex = new FedoraGS3RunException(e); … … 842 831 GSXML.REQUEST_TYPE_PROCESS, "DocumentStructureRetrieve"); 843 832 try{ 844 return FedoraCommons.elementTo FormattedString(responseMsg);833 return FedoraCommons.elementToString(responseMsg); 845 834 } catch(TransformerException e) { 846 835 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg … … 848 837 } 849 838 } 850 851 /** Given a <documentNodeList> portion of a greenstone3 839 840 841 /** Given a <documentNodeList> portion of a greenstone3 852 842 * DocumentStructureRetrieve XML response message, this method will populate 853 843 * it with the <documentNodes> that represent the structure of the given docIDs. … … 856 846 * @param docIDs the documentIDs for which the section's structure is returned; 857 847 * where a docID is either a fedora pid <docPID> or <docPID>-<sectionNumber>. 858 * @param levels - either CHILDREN or DESCENDANTS. 859 * CHILDREN returns only the first-level descendants (children) of the 860 * requested document sections indicated by docIDs. 861 * DESCENDANTS returns all descendants of all the document-sections denoted by 862 * docIDs. 848 * @param structures - the structure of the sections to return. Can be any combination of: 849 * ancestors, parent, siblings, children, descendants, entire. 850 * @param infos - a string containing any combination of the values: numChildren, numSiblings, 851 * siblingPosition. The requested info gets added as attributes to the returned root element. 863 852 */ 864 protected void getStructureElement(Element docNodeList, 865 String[] docIDs, int levels)853 protected void getStructureElement(Element docNodeList, String[] docIDs, 854 String[] structures, String[] infos) 866 855 throws RemoteException, UnsupportedEncodingException, SAXException, 867 856 IOException 868 857 { 869 // process each docID 870 for(int i = 0; i < docIDs.length; i++) { 871 // work out the document's fedora PID and section ID 872 String sectionID = getSectionIDFromDocID(docIDs[i]); 873 String docPID = getDocPIDFromDocID(docIDs[i]); 874 875 // get the required section, along with children or descendants 876 Element srcDocElement = null; 877 if(levels == CHILDREN) // get the requested section with its children 878 srcDocElement = this.getChildrenOfSectionXML(docPID, sectionID); 879 else // levels == DESCENDANTS, get the section with all its descendants 880 srcDocElement = this.getSubsectionXML(docPID, sectionID); 881 882 // copy-and-convert that structure into a structure format for GS3 883 Element docNode = getStructure(docNodeList.getOwnerDocument(), 884 docIDs[i], docPID, srcDocElement); 885 886 // add it to our list of documentNodes 887 docNodeList.appendChild(docNode); 888 } 889 } 858 // Make one string out of requested structure components, and one string from info components 859 String structure = ""; 860 String info = ""; 861 for(int i = 0; i < structures.length; i++) { 862 structure = structure + structures[i] + "|"; 863 } 864 for(int i = 0; i < infos.length; i++) { 865 info = info + infos[i] + "|"; 866 } 867 868 // process each docID 869 for(int i = 0; i < docIDs.length; i++) { 870 // work out the document's fedora PID and section ID 871 String sectionID = getSectionIDFromDocID(docIDs[i]); 872 String docPID = getDocPIDFromDocID(docIDs[i]); 873 if(sectionID.equals("")) { 874 sectionID = "1"; 875 } 876 877 // get the required section, along with children or descendants 878 Element srcDocElement = getSectionStructureXML(docPID, sectionID, structure, info); 879 Document doc = docNodeList.getOwnerDocument(); 880 881 // copy-and-convert that structure into a structure format for GS3 882 Element docNode = getStructure(doc, docIDs[i], docPID, srcDocElement); 883 884 if(!info.equals("")) { 885 // <nodeStructureInfo> 886 // <info name="" value="" /> 887 // <info name="" value="" /> 888 // ... 889 // </nodeStructureInfo> 890 Element nodeStructureInfo = doc.createElement(GSXML.NODE_STRUCTURE_ELEM+GSXML.INFO_ATT); 891 Element root = srcDocElement.getOwnerDocument().getDocumentElement(); 892 893 if(root.hasAttribute("numSiblings")) { 894 String numSiblings = root.getAttribute("numSiblings"); 895 Element infoEl = doc.createElement(GSXML.INFO_ATT); 896 infoEl.setAttribute(GSXML.NAME_ATT, "numSiblings"); 897 infoEl.setAttribute(GSXML.VALUE_ATT, numSiblings); 898 nodeStructureInfo.appendChild(infoEl); 899 } 900 901 if(root.hasAttribute("siblingPosition")) { 902 String siblingPosition = root.getAttribute("siblingPosition"); 903 Element infoEl = doc.createElement(GSXML.INFO_ATT); 904 infoEl.setAttribute(GSXML.NAME_ATT, "siblingPosition"); 905 infoEl.setAttribute(GSXML.VALUE_ATT, siblingPosition); 906 nodeStructureInfo.appendChild(infoEl); 907 } 908 909 if(root.hasAttribute("numChildren")) { 910 String numChildren = root.getAttribute("numChildren"); 911 Element infoEl = doc.createElement(GSXML.INFO_ATT); 912 infoEl.setAttribute(GSXML.NAME_ATT, "numChildren"); 913 infoEl.setAttribute(GSXML.VALUE_ATT, numChildren); 914 nodeStructureInfo.appendChild(infoEl); 915 } 916 docNode.appendChild(nodeStructureInfo); 917 } 918 919 // add it to our list of documentNodes 920 docNodeList.appendChild(docNode); 921 } 922 } 923 890 924 891 925 /** … … 916 950 Attr attribute = doc.createAttribute(GSXML.NODE_ID_ATT); 917 951 attribute.setValue(requestingDocID); //requestingDocID.replace(HYPHEN+SECTION, "") 918 docNode.setAttributeNode(attribute); 952 docNode.setAttributeNode(attribute); 919 953 920 954 // <nodeStructure> … … 932 966 return docNode; 933 967 } 934 968 969 935 970 /** Recursive method that creates a documentStructure mirroring parameter 936 971 * section, starting from parameter parent down to all descendants … … 983 1018 String sectionID = subSection.hasAttribute(ID) ? 984 1019 subSection.getAttribute(ID) : ""; 985 nodeID.setValue(docID + HYPHEN + sectionID); 1020 if(sectionID.equals("1") 1021 && subSection.getElementsByTagName(SECTION_ELEMENT).getLength() > 0) { // root, non-leaf case 1022 // reset the attribute without the section number 1023 nodeID.setValue(docID+ HYPHEN + sectionID); // maybe important for democlient? 1024 } else { 1025 nodeID.setValue(docID + HYPHEN + sectionID); 1026 } 1027 //nodeID.setValue(docID + HYPHEN + sectionID); 986 1028 docNode.setAttributeNode(nodeID); 987 1029 988 1030 Attr nodeType = doc.createAttribute(GSXML.NODE_TYPE_ATT); 989 if(sectionID.equals("1")) { // root case 990 nodeType.setValue(GSXML.NODE_TYPE_ROOT); 991 // reset the attribute without the section number 992 docNode.setAttribute(GSXML.NODE_ID_ATT, docID); 993 } 994 else if(subSection.getElementsByTagName(SECTION_ELEMENT).getLength() > 0) 995 // this section has further <Section> children, so it's an internal node 996 nodeType.setValue(GSXML.NODE_TYPE_INTERNAL); 997 else if(subSection.hasAttribute(TYPE)) 998 nodeType.setValue(GSXML.NODE_TYPE_INTERNAL); 999 else // leaf 1000 nodeType.setValue(GSXML.NODE_TYPE_LEAF); 1031 if(subSection.hasAttribute(GSXML.NODE_TYPE_ATT)) { 1032 nodeType.setValue(subSection.getAttribute(GSXML.NODE_TYPE_ATT)); 1033 } 1001 1034 docNode.setAttributeNode(nodeType); 1002 1035 return docNode; … … 1068 1101 GSXML.REQUEST_TYPE_PROCESS, "DocumentContentRetrieve"); 1069 1102 try{ 1070 return FedoraCommons.elementTo FormattedString(responseMsg);1103 return FedoraCommons.elementToString(responseMsg); 1071 1104 } catch(TransformerException e) { 1072 1105 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg … … 1202 1235 GSXML.REQUEST_TYPE_DESCRIBE, ""); 1203 1236 try { 1204 return FedoraCommons.elementTo FormattedString(responseMsg);1237 return FedoraCommons.elementToString(responseMsg); 1205 1238 }catch(TransformerException e) { 1206 1239 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg … … 1247 1280 GSXML.REQUEST_TYPE_DESCRIBE, ""); 1248 1281 try{ 1249 return FedoraCommons.elementTo FormattedString(responseMsg);1282 return FedoraCommons.elementToString(responseMsg); 1250 1283 }catch(TransformerException e) { 1251 1284 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg … … 1305 1338 GSXML.REQUEST_TYPE_DESCRIBE, collectionName); 1306 1339 try{ 1307 return FedoraCommons.elementTo FormattedString(responseMsg);1340 return FedoraCommons.elementToString(responseMsg); 1308 1341 }catch(TransformerException e) { 1309 1342 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg … … 1337 1370 GSXML.REQUEST_TYPE_DESCRIBE, collectionName); 1338 1371 try{ 1339 return FedoraCommons.elementTo FormattedString(responseMsg);1372 return FedoraCommons.elementToString(responseMsg); 1340 1373 }catch(TransformerException e) { 1341 1374 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg … … 1420 1453 GSXML.REQUEST_TYPE_DESCRIBE, from); 1421 1454 try{ 1422 return FedoraCommons.elementTo FormattedString(responseMsg);1455 return FedoraCommons.elementToString(responseMsg); 1423 1456 }catch(TransformerException e) { 1424 1457 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg … … 1694 1727 * user to browse the titles of documents in the given collection by letter 1695 1728 * and returning the results. 1729 * @param collectionName is the name of the collection whose documents 1730 * starting with the given letter will be returned. 1696 1731 * @param classifierIDs are the ids of the classifiers on which to browse. In 1697 1732 * this case, the classifier indicates whether we browse titles by letter, or 1698 1733 * browse (documents) by collection; and it is of the form <CL(letter)>. 1699 * @param collectionName is the name of the collection whose documents 1700 * starting with the given letter will be returned. 1701 * @return a GS3 DocumentStructureRetrieve response message which lists all 1734 * @param structures - the requested browse substructure. Can be any combination 1735 * of ancestors, parent, siblings, children, descendants. 1736 * @param infos - the requested structural info. Can be numSiblings, 1737 * siblingPosition, numChildren. 1738 * @return a GS3 ClassifierBrowse response message which lists all 1702 1739 * the documents that start with the letter indicated by parameter classifier. 1703 1740 */ 1704 public String browse(String collectionName, String[] classifierIDs) 1741 public String browse(String collectionName, String[] classifierIDs, 1742 String[] structures, String[] infos) 1705 1743 { 1706 Document doc = builder.newDocument(); 1707 FedoraGS3RunException ex = null; //any RemoteException or UnsupportedEncodingException 1708 1709 // <classifierNodeList> 1710 Element classifierNodeList = doc.createElement( 1711 GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER); 1712 1713 for(int i = 0; i < classifierIDs.length; i++) { 1714 // <classifierNode nodeID="classifierNum"> 1715 Element requestedClassifierNode = doc.createElement( 1716 GSXML.CLASS_NODE_ELEM); 1744 // Construct one string from the structures and structural info arrays 1745 String structure = ""; 1746 String info = ""; 1747 for(int i = 0; i < structures.length; i++) { 1748 structure = structure + structures[i] + "|"; 1749 } 1750 for(int i = 0; i < infos.length; i++) { 1751 info = info + infos[i] + "|"; 1752 } 1753 1754 Document doc = builder.newDocument(); 1755 FedoraGS3RunException ex = null; //any RemoteException or UnsupportedEncodingException 1756 1757 // <classifierNodeList> 1758 Element classifierNodeList = doc.createElement(GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER); 1759 1760 for(int i = 0; i < classifierIDs.length; i++) { 1761 if(classifierIDs[i].startsWith("CL1")) { // browse by titles 1762 browseTitlesByLetterClassifier(doc, classifierNodeList, 1763 collectionName, classifierIDs[i], 1764 structure, info); 1765 } 1766 } 1767 1768 Element responseMsg = createResponseMessage(doc, classifierNodeList, ex, 1769 GSXML.REQUEST_TYPE_DESCRIBE, /*collectionName+/ */"ClassifierBrowse"); 1770 try { 1771 return FedoraCommons.elementToString(responseMsg); 1772 } catch(TransformerException e) { 1773 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg 1774 + " " + e; 1775 } 1776 } 1777 1778 /** CL1 browsing classifier: browsing titles by starting letter. 1779 * The browsing structure is retrieved. 1780 * @param doc - the document object that will contain the CL1 browsing structure. 1781 * @param classifierNodeList - the classifiers will be added to this nodeList. 1782 * @param collectionName - name of the collection through which we are browsing CL1. 1783 * @param classifierID - the ID of the (sub)classifier. Can be CL1, CL1.x, where x is 1784 * a letter. 1785 * @param structure - the requested browse substructure. Can be any combination 1786 * of ancestors, parent, siblings, children, descendants. siblings not yet implemented. 1787 * @param info - the requested structural info. Can be numSiblings, siblingPosition, 1788 * numChildren. 1789 * @return the classifierNodeList with the CL1 classifier browse structure. 1790 */ 1791 public Element browseTitlesByLetterClassifier(Document doc, Element classifierNodeList, 1792 String collectionName, String classifierID, 1793 String structure, String info) 1794 { 1795 FedoraGS3RunException ex = null; //any RemoteException or UnsupportedEncodingException 1796 1797 // TODO 1798 if(structure.indexOf("siblings") != -1) { 1799 LOG.error("Structure: siblings. Not yet implemented\n"); 1800 } 1801 1802 if(structure.indexOf("entire") != -1) { 1803 structure = structure + "ancestors|descendants"; 1804 } 1805 1806 // Structure of ancestors and children only at this stage 1807 int firstLevel = classifierID.indexOf('.'); 1808 int secondLevel = classifierID.lastIndexOf('.'); 1809 1810 // <nodeStructure> 1811 Element nodeStructure = doc.createElement(GSXML.NODE_STRUCTURE_ELEM); 1812 1813 // requested classifier node 1814 Element classNode = doc.createElement(GSXML.CLASS_NODE_ELEM); 1815 Attr attribute = doc.createAttribute(GSXML.NODE_ID_ATT); 1816 attribute.setValue(classifierID); 1817 classNode.setAttributeNode(attribute); 1818 1819 if(firstLevel == -1) { // CL1 - toplevel node 1820 Element root = (Element)classNode.cloneNode(true); // clone the node before appending children 1821 1822 classifierNodeList.appendChild(classNode); 1823 classNode.appendChild(nodeStructure); 1824 1825 nodeStructure.appendChild(root); 1826 if(structure.indexOf("descendants") != -1) { 1827 getTitlesByLetterStructure(collectionName, root, classifierID, true); 1828 } else if(structure.indexOf("children") != -1) { 1829 getTitlesByLetterStructure(collectionName, root, classifierID, false); 1830 } 1831 } 1832 else if(firstLevel == secondLevel) { // CL1.x, where x is a number 1833 1834 if(structure.indexOf("parent") != -1 || structure.indexOf("ancestors") != -1) { 1835 String toplevelID = classifierID.substring(0, firstLevel); 1836 Element toplevelNode = doc.createElement(GSXML.CLASS_NODE_ELEM); 1837 attribute = doc.createAttribute(GSXML.NODE_ID_ATT); 1838 attribute.setValue(toplevelID); 1839 toplevelNode.setAttributeNode(attribute); 1840 Element node = (Element)toplevelNode.cloneNode(true); // clone nodes before appending children 1841 1842 classifierNodeList.appendChild(toplevelNode); 1843 toplevelNode.appendChild(nodeStructure); 1844 1845 nodeStructure.appendChild(node); 1846 node.appendChild(classNode); 1847 } else { 1848 Element node = (Element)classNode.cloneNode(true); 1849 classifierNodeList.appendChild(node); 1850 node.appendChild(nodeStructure); 1851 nodeStructure.appendChild(classNode); 1852 } 1853 1854 int num = Integer.parseInt(classifierID.substring(firstLevel+1)); // get x from CL1.x 1855 char ch = (char)(num - 1 + 'A'); 1856 if(structure.indexOf("descendants") != -1) { 1857 getTitlesForLetter(ch, collectionName, classNode, "descendants"); 1858 } else if(structure.indexOf("children") != -1) { 1859 getTitlesForLetter(ch, collectionName, classNode, "children"); 1860 } 1861 } 1862 else { // ought to be a doc structure retrieve request, not classifierbrowse structure retrieve 1863 LOG.error("ClassifierID: " + classifierID + ". Shouldn't be in browse method"); 1864 } 1865 1866 return classifierNodeList; 1867 } 1868 1869 /** Creates a (CL1) subclassifier element for the docs whose titles start with 1870 * the given letter. 1871 * @param ch - the starting letter of the document titles to retrieve. 1872 * @param collectionName - name of the collection through which we are browsing CL1. 1873 * @param classifierNode - the docNodes found will be appended to this node. 1874 * @param depthStructure - can be descendants or children. Specifies what to retrieve: 1875 * gets descendants of any documents found, otherwise gets just the children. 1876 * @return the given classifierNode which will have the child (or descendant) documents 1877 * appended to it. 1878 */ 1879 public Element getTitlesForLetter(char ch, String collectionName, 1880 Element classifierNode, String depthStructure) 1881 { 1882 Document doc = classifierNode.getOwnerDocument(); 1883 FedoraGS3RunException ex = null; //any RemoteException or UnsupportedEncodingException 1884 1885 1886 // Retrieve the document structure for each subClassifierID: 1887 // all the documents that begin with its letter. 1888 String letter = String.valueOf(ch); 1889 try { 1890 String[] docPIDs = this.browseTitlesByLetter(collectionName, letter); 1891 if(docPIDs.length == 0) { 1892 return classifierNode; // skip letters that don't have any kids 1893 } 1894 1895 for(int i = 0; i < docPIDs.length; i++) { 1896 // work out the document's fedora PID and section ID 1897 String sectionID = getSectionIDFromDocID(docPIDs[i]); 1898 String docPID = getDocPIDFromDocID(docPIDs[i]); 1899 1900 // get the required section, along with children or descendants 1901 Element section = getSectionStructureXML(docPID, sectionID, depthStructure, ""); 1902 1903 // <documentNode nodeID="docID" docType="hierarchy" nodeType="root"> 1904 Element docRootNode = createDocNodeFromSubsection(doc, section, docPID); 1905 1906 // fills in the subtree of the rootNode in our nodeStructure element 1907 createDocStructure(doc, section, docRootNode, docPID); //where section represents the root section 1908 classifierNode.appendChild(docRootNode); 1909 } 1910 } catch(Exception e) { 1911 ex = new FedoraGS3RunException(e); 1912 ex.setSpecifics("requested portion of TOC file or trouble with fielded search "); 1913 } 1914 1915 return classifierNode; 1916 } 1917 1918 1919 /** Creates all the subclassifiers (CL1.x) for CL1, the classifier to browse by the 1920 * starting letter of the alphabet. X is each letter of the alphabet for which there 1921 * are matching document titles. 1922 * @param collectionName - name of the collection through which we are browsing CL1. 1923 * @param classifierNode - the docNodes found will be appended to this node. 1924 * @param classifierID - the ID of parent classifier, i.e. CL1, which is used to create 1925 * the IDs for the subclassifiers (CL.x). 1926 * @param getDescendants - if true, get descendants of any documents found, otherwise 1927 * get just the children. 1928 * @return the given classifierNode, with the CL.x subclassifiers for the letters of 1929 * the alphabet that are represented in the document titles. 1930 */ 1931 public Element getTitlesByLetterStructure(String collectionName, Element classifierNode, 1932 String classifierID, boolean getDescendants) 1933 { 1934 Document doc = classifierNode.getOwnerDocument(); 1935 FedoraGS3RunException ex = null; // any RemoteException or UnsupportedEncodingException 1936 1937 // We're going to loop to the end of the alphabet 1938 int count = 1; 1939 for(char ch = 'A'; ch <= 'Z'; ch++, count++) { 1940 // Retrieve the document structure for each subClassifierID: 1941 // all the documents that begin with its letter. 1942 String letter = String.valueOf(ch); 1943 try { 1944 String[] docPIDs = this.browseTitlesByLetter(collectionName, letter); 1945 if(docPIDs.length == 0) { 1946 continue; // skip letters that don't have any kids 1947 } 1948 1949 // <classifierNode nodeID="CL1.x"> 1950 Element subClassifier = doc.createElement(GSXML.CLASS_NODE_ELEM); 1717 1951 Attr attribute = doc.createAttribute(GSXML.NODE_ID_ATT); 1718 attribute.setValue(classifierIDs[i]); 1719 requestedClassifierNode.setAttributeNode(attribute); 1720 classifierNodeList.appendChild(requestedClassifierNode); 1721 1722 // <nodeStructure> 1723 Element nodeStructure = doc.createElement(GSXML.NODE_STRUCTURE_ELEM); 1724 requestedClassifierNode.appendChild(nodeStructure); 1725 1726 // And one more time, the top level classifierNode: 1727 Element classifierNode = doc.createElement(GSXML.CLASS_NODE_ELEM); 1728 attribute = doc.createAttribute(GSXML.NODE_ID_ATT); 1729 attribute.setValue(classifierIDs[i]); 1730 classifierNode.setAttributeNode(attribute); 1731 nodeStructure.appendChild(classifierNode); 1732 1733 // Work out what we're browsing base on the classifierID's number 1734 // classifier CL1 = browse titles by letter; 1735 // classifier CL2 = browse by collection; 1736 // remove the CL prefix and decimal point to obtain the number from the id: 1737 String classifier = classifierIDs[i].replace("CL", ""); 1738 int decimal = classifier.indexOf('.'); // look for decimal point 1739 if(decimal != -1) { 1740 classifier = classifier.substring(0, decimal); 1741 } 1742 int classifierNum = Integer.parseInt(classifier); 1743 switch(classifierNum) { 1744 case 1: 1745 // we're going to loop to the end of the alphabet 1746 int num = 1; 1747 for(char ch = 'A'; ch <= 'Z'; ch++, num++) { 1748 // Retrieve the document structure for each subClassifierID: 1749 // all the documents that begin with its letter. 1750 String letter = String.valueOf(ch); 1751 try { 1752 String[] docPIDs = this.browseTitlesByLetter( 1753 collectionName, letter); 1754 if(docPIDs.length == 0) { 1755 continue; // skip letters that don't have any kids 1756 } 1757 1758 // <classifierNode nodeID="CL3.1"> 1759 Element subClassifier = doc.createElement( 1760 GSXML.CLASS_NODE_ELEM); 1761 attribute = doc.createAttribute(GSXML.NODE_ID_ATT); 1762 attribute.setValue(classifierIDs[i]+"."+num); 1763 subClassifier.setAttributeNode(attribute); 1764 classifierNode.appendChild(subClassifier); 1765 1766 // append the <docNodes> for the docPIDs found as children 1767 // of subclassifier 1768 getStructureElement(subClassifier, docPIDs, DESCENDANTS); 1769 //CHILDREN); // for testing 1770 } catch(Exception e) { 1771 ex = new FedoraGS3RunException(e); 1772 ex.setSpecifics("requested portion of TOC file or " 1773 + "trouble with fielded search "); 1774 } 1775 } 1776 // No titles in this collection that start with a letter at all 1777 if(!classifierNode.hasChildNodes()) { 1778 // <classifierNode nodeID="CL1.0"> which we will equate with A-Z 1779 Element subClassifier = doc.createElement( 1780 GSXML.CLASS_NODE_ELEM); 1781 attribute = doc.createAttribute(GSXML.NODE_ID_ATT); 1782 attribute.setValue(classifierIDs[i]+"."+0); // 1783 subClassifier.setAttributeNode(attribute); 1784 classifierNode.appendChild(subClassifier); 1785 } 1786 break; 1787 case 2: 1788 break; 1789 default: 1790 ex = new FedoraGS3RunException( // cause is regular exception 1791 new Exception("Unknown classifier ID: " + classifierIDs[i])); 1792 } 1793 } 1794 Element responseMsg = createResponseMessage(doc, classifierNodeList, ex, 1795 GSXML.REQUEST_TYPE_DESCRIBE, /*collectionName+*/"/ClassifierBrowse"); 1796 try{ 1797 return FedoraCommons.elementToFormattedString(responseMsg); 1798 }catch(TransformerException e) { 1799 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg 1800 + " " + e; 1801 } 1802 } 1952 attribute.setValue(classifierID+"."+count); 1953 subClassifier.setAttributeNode(attribute); 1954 classifierNode.appendChild(subClassifier); 1955 1956 if(getDescendants) { // get the documents 1957 1958 // append the <docNodes> for the docPIDs found as children 1959 // of subclassifier 1960 1961 for(int i = 0; i < docPIDs.length; i++) { 1962 // work out the document's fedora PID and section ID 1963 String sectionID = getSectionIDFromDocID(docPIDs[i]); 1964 String docPID = getDocPIDFromDocID(docPIDs[i]); 1965 1966 // get the required section, along with children or descendants 1967 Element section = getSectionStructureXML(docPID, sectionID, "descendants", ""); 1968 1969 // <documentNode nodeID="docID" docType="hierarchy" nodeType="root"> 1970 Element rootNode = createDocNodeFromSubsection(doc, section, docPID); 1971 1972 // fills in the subtree of the rootNode in our nodeStructure element 1973 createDocStructure(doc, section, rootNode, docPID); //where section represents the root section 1974 subClassifier.appendChild(rootNode); 1975 } 1976 } 1977 } catch(Exception e) { 1978 ex = new FedoraGS3RunException(e); 1979 ex.setSpecifics("requested portion of TOC file or " 1980 + "trouble with fielded search "); 1981 } 1982 } 1983 return classifierNode; 1984 } 1985 1803 1986 1804 1987 /** This method performs something equivalent to a greenstone3 1805 1988 * ClassifierBrowseMetadataRetrieve on the classifierNodeIDs 1806 * @param classNodeIDs array of classifierNode IDs offor which the metadata1989 * @param classNodeIDs array of classifierNode IDs for which the metadata 1807 1990 * needs to be returned. 1991 * @param metafields are the classifier metadata fields that are to be returned. 1992 * At present this method ignores them/pretends the requested metafields are 1993 * "all" and always returns the Title meta for the requested classifier nodes 1994 * (because that is all the metadata this Fedora classifier has at present). 1808 1995 * @return a GS3 ClassifierBrowseMetadataRetrieve response message which 1809 1996 * lists the metadata for all the classifierNodes passed as parameter.*/ 1810 public String browseMetadataRetrieve(String[] classNodeIDs )1997 public String browseMetadataRetrieve(String[] classNodeIDs, String[] metafields) 1811 1998 { 1812 1999 Document doc = this.builder.newDocument(); … … 1860 2047 "ClassifierBrowseMetadataRetrieve"); 1861 2048 try{ 1862 return FedoraCommons.elementTo FormattedString(responseMsg);2049 return FedoraCommons.elementToString(responseMsg); 1863 2050 }catch(TransformerException e) { 1864 2051 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg … … 1895 2082 // now create the displayItem children for classifier: 1896 2083 // <displayItem name="name">#letter</displayItem> 1897 // <displayItem name="description"> 1898 //Browse titles starting with #letter</displayItem> 2084 // <displayItem name="description">Browse titles starting with #letter</displayItem> 1899 2085 Element displayItem = createNameValuePairElement(doc, 1900 2086 GSXML.DISPLAY_TEXT_ELEM, GSXML.DISPLAY_TEXT_NAME, displayNameVal); … … 2013 2199 } 2014 2200 2015 /** 2201 /** @return a String representing Greenstone3 XML for a query process 2016 2202 * response returning the results for the query denoted by parameter 2017 2203 * nameValParamsMap. … … 2040 2226 String pids[] = {}; 2041 2227 // (2) for Textquery, we simply search ALL_FIELDS using FedoraGSearch 2042 if(service.e quals("TextQuery")) {2228 if(service.endsWith("TextQuery")) { 2043 2229 try { 2044 2230 // get the Query field: … … 2142 2328 GSXML.REQUEST_TYPE_PROCESS, service); 2143 2329 try{ 2144 return FedoraCommons.elementTo FormattedString(responseMsg);2330 return FedoraCommons.elementToString(responseMsg); 2145 2331 }catch(TransformerException e) { 2146 2332 return FedoraGS3RunException.xmlToStringConversionFailureResponseMsg … … 2186 2372 // along with EX of the top-level document: 2187 2373 System.out.println("\nGET META for greenstone:gs2mgdemo-HASH01d667303fe98545f03c14ae:"); 2188 System.out.println(con.getDocumentMetadata(new String[]{"greenstone:gs2mgdemo-HASH01d667303fe98545f03c14ae"} ));2374 System.out.println(con.getDocumentMetadata(new String[]{"greenstone:gs2mgdemo-HASH01d667303fe98545f03c14ae"}, new String[]{"all"})); 2189 2375 2190 2376 … … 2197 2383 System.out.println("\nGET META:"); 2198 2384 for(int i = 0; i < docIDs.length; i++) { 2199 System.out.println(con.getDocumentMetadata(docIDs[i] ));2385 System.out.println(con.getDocumentMetadata(docIDs[i], new String[]{"all"})); 2200 2386 } 2201 2387 … … 2211 2397 // their sections 2212 2398 for(int i = 0; i < getTitlesFor.length; i++) { 2213 System.out.println(con.getDocumentMetadata(getTitlesFor[i]));2399 System.out.println(con.getDocumentMetadata(getTitlesFor[i], new String[]{"all"})); 2214 2400 } 2215 2401 … … 2219 2405 System.out.println("\nGET STRUCTURE:"); 2220 2406 for(int i = 0; i < docIDs.length; i++) { 2221 System.out.println(con.getChildren(docIDs[i])); 2222 System.out.println(con.getDocumentStructure(docIDs[i])); 2407 System.out.println("Descendents and numChildren:\n" 2408 + con.getDocumentStructure(docIDs[i], new String[] {"descendants"}, new String[] {"numChildren"})); 2409 System.out.println("Parent and numSiblings:\n" 2410 + con.getDocumentStructure(docIDs[i], new String[] {"parent"}, new String[] {"numSiblings"})); 2223 2411 } 2224 2412 … … 2229 2417 "greenstone:demo-pinky" }; 2230 2418 System.out.println(con.getContent(errorCases)); 2231 System.out.println(con.getDocumentMetadata(errorCases ));2232 System.out.println(con.getDocumentStructure(errorCases));2419 System.out.println(con.getDocumentMetadata(errorCases, new String[]{"all"})); 2420 System.out.println(con.getDocumentStructure(errorCases, new String[] {"descendants"}, new String[] {"numChildren"})); 2233 2421 2234 2422 System.out.println("\nCLASSIFIER BROWSE"); 2235 2423 System.out.println(con.browse("gs2mgdemo", //"ClassifierBrowse", 2236 new String[]{"CL1"} ));2424 new String[]{"CL1"}, new String[] {""}, new String[] {""})); 2237 2425 2238 2426 System.out.println("\nCLASSIFIER BROWSE METADATA RETRIEVE"); … … 2243 2431 } 2244 2432 System.out.println(con.browseMetadataRetrieve(//"gs2mgdemo", 2245 classNodeIDs));2433 classNodeIDs, new String[]{"all"})); 2246 2434 2247 2435 System.out.println("Testing query services"); -
other-projects/gs3-webservices-java-client/trunk/src/GS3Fedora/org/greenstone/fedora/services/FedoraGS3DL.java
r15222 r22300 331 331 /* METHODS FOR GETTING THE STRUCTURE OF DOCUMENTS */ 332 332 333 /** @return the XML content of the TOC of just that portion of the TOC which334 * contains the section denoted by sectionID and its direct child subsections.335 * The children are returned in the order they are encountered, which336 * happens to be in the required order of ascending sectionID.337 * @param docPID is a fedora pid identifying a greenstone document object.338 * @param sectionID identifies the particular section in the339 * document denoted by docPID, may be a section name or number. */340 public Element getChildrenOfSectionXML(String docPID, String sectionID)341 throws RemoteException, UnsupportedEncodingException,342 SAXException, IOException;343 344 /** @return a string representing the XML content of the TOC of just345 * that portion of the TOC which contains the section denoted by sectionID346 * and its direct child subsections.347 * The children are returned in the order they are encountered, which348 * happens to be in the required order of ascending sectionID.349 * @param docPID is a fedora pid identifying a greenstone document object.350 * @param sectionID identifies the particular section in the351 * document denoted by docPID, may be a section name or number. */352 public String getChildrenOfSection(String docPID, String sectionID)353 throws RemoteException, UnsupportedEncodingException,354 SAXException, IOException, TransformerException;355 356 333 /** @return the part of the TOC XML file (which outlines doc structure) 357 334 * relating to the given section. This includes the section denoted by 358 335 * sectionID as well as all descendent subsections thereof. 359 * @param docPID is a fedora pid identifying a greenstone document object. 360 * @param sectionID identifies the particular section in the 361 * document denoted by docPID, may be a section name or number. */ 362 public Element getSubsectionXML(String docPID, String sectionID) 363 throws RemoteException, UnsupportedEncodingException, 364 SAXException, IOException; 365 366 /** @return a String representation of the part of the TOC XML file 367 * (which outlines doc structure) relating to the given section. This 368 * includes the section denoted by sectionID as well as all descendent 369 * subsections thereof. 370 * @param docPID is a fedora pid identifying a greenstone document object. 371 * @param sectionID identifies the particular section in the 372 * document denoted by docPID, may be a section name or number. */ 373 public String getSubsection(String docPID, String sectionID) 374 throws RemoteException, UnsupportedEncodingException, SAXException, 375 IOException, TransformerException; 336 * @param docPID - a fedora pid identifying a greenstone document object. 337 * @param sectionID - identifies the particular section in the 338 * document denoted by docPID, may be a section name or number. 339 * @param structure can contain any combination of: ancestors, parent, 340 * siblings, children, descendants, entire, specifying the portion of 341 * the structure to retrieve. 342 * @param info can contain any combination of: siblingPosition, numSiblings, 343 * numChildren, requesting additional information about the structure. */ 344 public Element getSectionStructureXML(String docPID, String sectionID, String structure, String info) 345 throws RemoteException, UnsupportedEncodingException, SAXException, IOException; 376 346 377 347 /* BROWSING */ -
other-projects/gs3-webservices-java-client/trunk/src/GS3Fedora/org/greenstone/fedora/services/FedoraToGS3Interface.java
r21835 r22300 159 159 160 160 /* RETRIEVE SERVICE: DOCUMENT STRUCTURE RETRIEVE */ 161 162 /** @return the documentStructure of the document or section given by docID. 163 * The structure is returned in the XML format of a Greenstone3 164 * DocumentStructureRetrieve response message. This method returns the entire 165 * subSection of the docID (that is, all descendents included). 166 * @param docID the identifier for the document whose structure is required. 167 * This is either of the format "greenstone:<collectionName>-<docPID>" 168 * OR "greenstone:<collectionName>-<docPID>-" 169 * where "greenstone:<collectionName>-<docPID>-1" is the same as 170 * "greenstone:<collectionName>-<docPID>" and will return the same response */ 171 public String getDocumentStructure(String docID); 172 173 /** @return a view of the structure of the document or section given by docID 174 * which contains only the section and its direct children. This structure is 175 * returned in the XML format of a Greenstone3 DocumentStructureRetrieve 176 * response message. 177 * @param docID the identifier for the document whose structure is required. 178 * This is of the format "greenstone:<collectionName>-<docPID>" 179 * OR "greenstone:<collectionName>-<docPID>-" 180 * where "greenstone:<collectionName>-<docPID>-1" is the same as 181 * "greenstone:<collectionName>-<docPID>" and will return the same response */ 182 public String getChildren(String docID); 183 184 /** @return the documentStructure of the documents or sections given by docIDs. 185 * The structure is returned in the XML format of a Greenstone3 186 * DocumentStructureRetrieve response message. This method returns the entire 187 * subSection of each docID (that is, all descendents included). 188 * @param docIDs an array of document identifiers whose structures are requested 189 * These are of the format "greenstone:<collectionName>-<docPID>" 190 * OR "greenstone:<collectionName>-<docPID>-<sectionNumber>" 191 * where "greenstone:<collectionName>-<docPID>-1" is the same as 192 * "greenstone:<collectionName>-<docPID>" and will return the same response */ 193 public String getDocumentStructure(String[] docIDs); 194 195 /** @return the documentStructure of the documents or sections given by docIDs 196 * but only the sections and their children (not any further descendents). 197 * The structure is returned in the XML format of a Greenstone3 198 * DocumentStructureRetrieve response message. 199 * @param docIDs an array of document identifiers whose structures are requested 200 * These are of the format "greenstone:<collectionName>-<docPID>" 201 * OR "greenstone:<collectionName>-<docPID>-<sectionNumber>" 202 * where "greenstone:<collectionName>-<docPID>-1" is the same as 203 * "greenstone:<collectionName>-<docPID>" and will return the same response */ 204 public String getChildren(String[] docIDs); 205 161 162 /** @return a String representing Greenstone3 DocumentMetadataRetrieve XML 163 * containing the requested portion of the document structure of the documents 164 * indicated by docIDs: 165 * @param collection is the name of the collection. It's already included in the 166 * docID for a Fedora DL. 167 * @param docID is the document identifier of the document whose hierarchical 168 * structure is requested. The collection name is already included in the 169 * docID for a Fedora DL. 170 * @param structure - strings specifying the required structure of the document. 171 * Any combination of: ancestors, parent, siblings, children, descendants, entire. 172 * @param info - strings specifying the required structural info of the document. 173 * It can be any combination of: siblingPosition, numSiblings, numChildren. 174 */ 175 public String getDocumentStructure(String docID, String[] structure, String[] info); 176 177 /** @return a String representing Greenstone3 DocumentMetadataRetrieve XML 178 * containing the requested portion of the document structure of the documents 179 * indicated by docIDs: 180 * @param docIDs is an array of document identifiers of documents whose 181 * hierarchical structures are requested. The collection name is already included 182 * in the docID for a Fedora DL. 183 * @param structure - strings specifying the required structure of each document. 184 * Any combination of: ancestors, parent, siblings, children, descendants, entire. 185 * @param info - strings specifying the required structural info of each document. 186 * It can be any combination of: siblingPosition, numSiblings, numChildren. 187 */ 188 public String getDocumentStructure(String[] docIDs, String[] structure, String[] info); 189 206 190 207 191 /* RETRIEVE SERVICE: DOCUMENT METADATA RETRIEVE */ … … 221 205 * @return a GS3 DocumentMetadataRetrieve response message containing the 222 206 * EX, DC, DLS metadata for all the requested documents */ 223 public String getDocumentMetadata(String[] docIDs);207 public String getDocumentMetadata(String[] docIDs, String[] metadata); 224 208 225 209 /** Given a collectionID, returns a GS3 DocumentMetadataRetrieve … … 237 221 * @return a GS3 DocumentMetadataRetrieve response message containing the 238 222 * EX, DC, DLS metadata for all the requested document */ 239 public String getDocumentMetadata(String docID);223 public String getDocumentMetadata(String docID, String[] metadata); 240 224 241 225 /** @return a greenstone DocumentMetadataRetrieve response for the … … 245 229 * In the last case, the document ID may consist of either 246 230 * "documentPID-sectionNumber" or may just be just fedora documentPID */ 247 public String getMetadata(String[] docIDsOrCollIDs);231 public String getMetadata(String[] docIDsOrCollIDs, String[] metadata); 248 232 249 233 /** Given a document identifier, returns a GS3 DocumentMetadataRetrieve … … 271 255 * @param classNodeIDs are the IDs of the classifierNode for which the metadata 272 256 * needs to be returned 257 * @param metafields are the classifier metadata fields that are to be returned. 273 258 * @return a GS3 ClassifierBrowseMetadataRetrieve response message which 274 259 * lists the metadata for all the classifierNodes passed as parameter.*/ 275 public String browseMetadataRetrieve(String[] classNodeIDs );260 public String browseMetadataRetrieve(String[] classNodeIDs, String[] metafields); 276 261 277 262 /** This method performs the implemented browse operation: allowing the … … 283 268 * @param collectionName is the name of the collection whose documents 284 269 * starting with the given letter will be returned. 270 * @param structure - the requested browse substructure. Can be any combination 271 * of ancestors, parent, siblings, children, descendants. 272 * @param info - the requested structural info. Can be numSiblings, siblingPosition, 273 * numChildren 285 274 * @return a GS3 DocumentStructureRetrieve response message which lists all 286 275 * the documents that start with the letter indicated by parameter classifier. 287 276 */ 288 public String browse(String collectionName, String[] classifierIDs );277 public String browse(String collectionName, String[] classifierIDs, String[] structures, String[] infos); 289 278 290 279 /* @returns the document identifiers returned for a search on the titles of
Note:
See TracChangeset
for help on using the changeset viewer.