}
public static final String[] PARAMS_listGroupChanges = {"date", "groups"};
public Document listGroupChanges(Date date, String[] groups) throws DBException {
Transaction tx = new Transaction();
try {
Date start = new Date();
Set grpSet = new HashSet();
for ( int i = 0; groups != null && i < groups.length; i++ )
grpSet.add(groups[i]);
String d = new Variant(date).getString();
StringBuffer sb = new StringBuffer(64);
sb.append("/" + Constants.CONTENT + "[" + Constants.MODIFIED + " > '" + d + "'");
if ( groups != null ) {
sb.append(" and " + Constants.GROUPS + "/" + Constants.GROUP + "[");
for ( int i = 0; i < groups.length; i++ ) {
if ( i > 0 )
sb.append(" or ");
sb.append(".='" + groups[i] + "'");
}
sb.append("]");
}
sb.append("]");
XMLSerializableAdapter col = getContentCollection();
ResultSet rs = col.queryCollection(tx, XPathQueryResolver.STYLE_XPATH, sb.toString(), null);
Map grpMap = new HashMap(); // of String to List of Element
while ( rs.next() ) {
try {
DocumentTable dt = rs.getResult();
Element elem = (Element)DTSMHelper.tableToNode(dt);
NodeList nl = elem.getElementsByTagName(Constants.GROUP);
for ( int i = 0; i < nl.getLength(); i++ ) {
Element e = (Element)nl.item(i);
String grpName = DOMUtils.getText(e);
if ( groups != null && !grpSet.contains(grpName) )
continue;
List l = (List)grpMap.get(grpName);
if ( l == null ) {
l = new ArrayList();
grpMap.put(grpName, l);
}
l.add(elem);
}
}
catch ( DTSMException e ) {
throw new DBException(FaultCodes.GEN_GENERAL_ERROR, "Can't convert DocumentTable", e);
}
}
Document doc = DOMHelper.newDocument();
Element rootElem = doc.createElement(Constants.MANIFEST);
rootElem.setAttribute(Constants.DATE, new Variant(start).getString());
doc.appendChild(rootElem);
Iterator iter = grpMap.keySet().iterator();
while ( iter.hasNext() ) {
String key = (String)iter.next();
Group g = getGroup(key, true);
Element groupElem = doc.createElement(Constants.GROUP);
groupElem.setAttribute(Constants.NAME, key);
groupElem.setAttribute(Constants.VERSION, Double.toString(g.getVersion()));
groupElem.setAttribute(Constants.STATUS, Constants.getStatusString(g.getStatus()));
rootElem.appendChild(groupElem);
List l = (List)grpMap.get(key);
Iterator i = l.iterator();
while ( i.hasNext() ) {
Node n = doc.importNode((Element)i.next(), true);
groupElem.appendChild(n);
}
}
return doc;
}
catch ( DBException e ) {
tx.cancel();
throw e;
}
finally {
if ( tx.getStatus() == Transaction.ACTIVE )
tx.commit();
}
}