UriHandler hpathHandler =
HistoryPathHandler.getResolvedHistoryPathHandler( nsName, uh );
Content content = nsaToken.getContentHelper();
String hpath = hpathHandler.toString();
Structure structure = nsaToken.getStructureHelper();
String uniqueUri = structure.generateUniqueUri(sToken, hpath);
if (uniqueUri != null) {
if (UriHandler.useHistoryCollectionHack) {
// XXX this is a bit silly: first compose it, now analyze it...
String nextHnStr = uniqueUri.substring(uniqueUri.lastIndexOf('/') + 1);
// XXX start with (at least) 10 to
// assure no resources are created directly in history folder
long nextHnLong = Long.parseLong(nextHnStr) + 10;
nextHnStr = String.valueOf(nextHnLong);
// make hpath/1/2/3 out of 1234
StringBuffer pathBuffer = new StringBuffer(hpath);
for (int i = 0; i < nextHnStr.length() - 1; i++) {
pathBuffer.append('/');
pathBuffer.append(nextHnStr.charAt(i));
// as we have no information how this number may look like we will have to assure the full
// path is created
String dir = pathBuffer.toString();
try {
structure.retrieve(sToken, dir);
} catch (ObjectNotFoundException onfe) {
try {
structure.create(sToken, new SubjectNode(), dir);
content.create(sToken, dir, new NodeRevisionDescriptor(0), null);
} catch (ObjectAlreadyExistsException oae) {
Domain.warn("Object " + dir + " already exists.");
} catch (RevisionAlreadyExistException rae) {
Domain.warn("Revision " + dir + " already exists.");
}
}
}
// make hpath/1/2/3/h4 out of 1234
pathBuffer.append("/h").append(nextHnStr.charAt(nextHnStr.length() - 1));
String fullPath = pathBuffer.toString();
return new UriHandler(fullPath);
} else {
return new UriHandler(uniqueUri);
}
} else {
NodeRevisionDescriptors hpathNrds = content.retrieve(sToken, hpath);
NodeRevisionDescriptor hpathNrd = content.retrieve(sToken, hpathNrds);
NodeProperty nextHnProp = hpathNrd.getProperty(I_NEXT_HISTORY_NAME, NamespaceCache.SLIDE_URI);
if (UriHandler.useHistoryCollectionHack) {
if (nextHnProp == null || nextHnProp.getValue() == null) {
// XXX start with historyCollectionHackChildren to assure no
// resources are created directly in history folder
nextHnProp = new NodeProperty(I_NEXT_HISTORY_NAME, "10", NamespaceCache.SLIDE_URI);
nextHnProp.setKind(NodeProperty.Kind.PROTECTED);
hpathNrd.setProperty(nextHnProp);
}
String nextHnStr = (String) nextHnProp.getValue();
long nextHnLong = Long.parseLong(nextHnStr);
if (nextHnLong % 10 == 0) {
// create parent collection
long dirNum = nextHnLong / 10;
char dirChar[] = Long.toString(dirNum).toCharArray();
StringBuffer buf = new StringBuffer();
for (int i = 0; i < dirChar.length - 1; i++) {
buf.append(dirChar[i]);
buf.append('/');
}
buf.append(dirChar[dirChar.length - 1]);
String dirPath = hpath + "/" + buf.toString();
try {
structure.create(sToken, new SubjectNode(), dirPath);
//content.create(sToken,dirPath,true);
//NodeRevisionDescriptors dnrds =
// structure.retrieve(stoken,dirPath);
content.create(sToken, dirPath, new NodeRevisionDescriptor(0), null);
} catch (ObjectAlreadyExistsException oae) {