try {
complexDocId = URLDecoder.decode(complexDocId, "UTF-8");
} catch (final UnsupportedEncodingException e1) {
LOGGER.log(Level.WARNING, "Unable to Decode!", e1);
}
final Container container = new Container();
StringTokenizer strTok;
String URL;
String DocID = null;
// In case of meta URL feed, separate list URL from the docID using
// "?" as a delimiter.
if (complexDocId.indexOf(SPConstants.EQUAL_TO) != -1) {
strTok = new StringTokenizer(complexDocId, "?");
URL = strTok.nextToken();
String tempDocID = strTok.nextToken();
// to remove "ID=" from docID.
DocID = tempDocID.substring(3);
} else {
// This change in case of content feed.
strTok = new StringTokenizer(complexDocId, SPConstants.DOC_TOKEN);
URL = strTok.nextToken();
if (strTok.hasMoreElements()) {
DocID = strTok.nextToken();
}
}
if (URL != null && URL.endsWith(SPConstants.DEFAULT_SITE_LANDING_PAGE)) {
// If the URL ends with default.aspx, the container type should be SITE.
container.setType(ContainerType.SITE);
} else {
container.setType(ContainerType.LIST);
}
final AuthData authData = new AuthData();
authData.setContainer(container);
boolean isAttachment = false;
try {
Integer.parseInt(DocID);
authData.setType(EntityType.LISTITEM);
} catch (final Exception e) {
if (URL.endsWith(SPConstants.DEFAULT_SITE_LANDING_PAGE)) {
authData.setType(EntityType.SITE);
} else {
if (!URL.endsWith(SPConstants.ASPX)) {
authData.setType(EntityType.LISTITEM);
} else {
authData.setType(EntityType.LIST);
}
}
}
// Fix me: Get the details of Attachments and Alert URLs in case of
// Meta and URL feed mode and find away to get required information
// to authorize.
if (FeedType.CONTENT_FEED == sharepointClientContext.getFeedType()) {
final Matcher match = SPConstants.ATTACHMENT_SUFFIX_PATTERN.matcher(URL);
if (match.find()) {
URL = match.group(2);
isAttachment = true;
} else if (URL.startsWith(SPConstants.ALERT_SUFFIX_IN_DOCID)) {
URL = URL.substring(SPConstants.ALERT_SUFFIX_IN_DOCID.length());
if (URL.endsWith("_" + SPConstants.ALERTS_TYPE)) {
URL = URL.substring(0, URL.length()
- (1 + SPConstants.ALERTS_TYPE.length()));
}
container.setType(ContainerType.SITE);
authData.setType(EntityType.ALERT);
}
} else {
Matcher match = SPConstants.ATTACHMENT_URL_PATTERN.matcher(URL);
if (match.find()) {
isAttachment = true;
DocID = match.group(2);
URL = match.group(1) + "/AllItems.aspx";
container.setType(ContainerType.LIST);
authData.setType(EntityType.LISTITEM);
} else if (complexDocId.contains(SPConstants.ALERTS_EQUALTO)) {
DocID = DocID.substring(4, DocID.indexOf("}"));
URL = URL.substring(0, URL.indexOf("_layouts"));
container.setType(ContainerType.SITE);
authData.setType(EntityType.ALERT);
}
}
container.setUrl(URL);
if (isAttachment) {
AttachmentKey attachmentKey = new AttachmentKey(URL, DocID);
if (attachments.containsKey(attachmentKey)) {
attachments.get(attachmentKey).add(originalComplexDocId);