// Use the standard root node to get a list of locales available. public static SortedDictionary<string, string> GetLocales() { SortedDictionary<string, string> locales = new SortedDictionary<string, string>(); getContentRequest request = new getContentRequest(); ContentService proxy = new ContentService(); getContentResponse response; request.contentIdentifier = rootContentItem.contentId; request.locale = "en-US"; // Now required otherwise an exception. try { response = proxy.GetContent(request); } catch { locales.Add("English (United States)", "en-us"); return locales; } foreach (availableVersionAndLocale av in response.availableVersionsAndLocales) { // Use the DisplayName as the key instead of the locale because // that's how we want the collection sorted. string displayName = new CultureInfo(av.locale).DisplayName; if (locales.ContainsKey(displayName) == false) locales.Add(displayName, av.locale.ToLower()); } return locales; }
// Added the loadFailSafe optimization public void Load(bool loadImages, bool loadFailSafe) { getContentRequest request = new getContentRequest(); request.contentIdentifier = contentIdentifier; request.locale = locale; request.version = collection + "." + version; List<requestedDocument> documents = new List<requestedDocument>(); requestedDocument document = new requestedDocument(); document.selector = "Mtps.Links"; document.type = documentTypes.common; documents.Add(document); document = new requestedDocument(); document.type = documentTypes.primary; document.selector = "Mtps.Toc"; documents.Add(document); document = new requestedDocument(); document.type = documentTypes.common; document.selector = "Mtps.Search"; documents.Add(document); // Mtps.Annotations removed because it caused many bugs /*document = new requestedDocument(); document.type = documentTypes.feature; document.selector = "Mtps.Annotations"; documents.Add(document);*/ if (loadFailSafe == true) { document = new requestedDocument(); document.type = documentTypes.primary; document.selector = "Mtps.Failsafe"; documents.Add(document); } request.requestedDocuments = documents.ToArray(); ContentService proxy = new ContentService(); proxy.appIdValue = new appId(); proxy.appIdValue.value = application; getContentResponse response; try { response = proxy.GetContent(request); } catch { return; } if (validateAsFilename.Match(response.contentId).Success == true) { contentId = response.contentId; } else { throw (new BadContentIdException("ContentId contains illegal characters: [" + contentId + "]")); } numImages = response.imageDocuments.Length; foreach (common commonDoc in response.commonDocuments) { if (commonDoc.Any != null) { switch (commonDoc.commonFormat.ToLower()) { case "mtps.search": metadata = commonDoc.Any[0].OuterXml; break; case "mtps.links": links = commonDoc.Any[0].OuterXml; break; } } } foreach (primary primaryDoc in response.primaryDocuments) { if (primaryDoc.Any != null) { switch (primaryDoc.primaryFormat.ToLower()) { case "mtps.failsafe": RemoveDuplicateSentences(primaryDoc.Any); xml = primaryDoc.Any.OuterXml; break; case "mtps.toc": toc = primaryDoc.Any.OuterXml; break; } } } /*foreach (feature featureDoc in response.featureDocuments) { if (featureDoc.Any != null) { if (featureDoc.featureFormat.ToLower() == "mtps.annotations") { annotations = featureDoc.Any[0].OuterXml; } } }*/ // If we get no meta/search or wiki data, plug in NOP data because // we can't LoadXml an empty string nor pass null navigators to // the transform. if (string.IsNullOrEmpty(metadata) == true) metadata = "<se:search xmlns:se=\"urn:mtpg-com:mtps/2004/1/search\" />"; //if (string.IsNullOrEmpty(annotations) == true) annotations = "<an:annotations xmlns:an=\"urn:mtpg-com:mtps/2007/1/annotations\" />"; sizeImages = 0; if (loadImages == true) { requestedDocument[] imageDocs = new requestedDocument[response.imageDocuments.Length]; // Now that we know their names, we run a request with each image. for (int i = 0; i < response.imageDocuments.Length; i++) { imageDocs[i] = new requestedDocument(); imageDocs[i].type = documentTypes.image; imageDocs[i].selector = response.imageDocuments[i].name + "." + response.imageDocuments[i].imageFormat; } request.requestedDocuments = imageDocs; response = proxy.GetContent(request); foreach (image imageDoc in response.imageDocuments) { string imageFilename = imageDoc.name + "." + imageDoc.imageFormat; if (validateAsFilename.Match(imageFilename).Success == true) { images.Add(new Image(imageDoc.name, imageDoc.imageFormat, imageDoc.Value)); sizeImages = sizeImages + imageDoc.Value.Length; } else { throw (new BadImageNameExeception( "Image filename contains illegal characters: [" + imageFilename + "]")); } } } }
// Returns the navigation node that corresponds to this content. If // we give it a navigation node already, it'll return that node, so // no harm done. public string GetNavigationNode() { // Load the contentItem. If we get a Toc entry, then we know it is // a navigation node rather than a content node. The reason is that // getNavigationPaths only returns the root node if the target node is // a navigation node already. We could check to see if we get one path // consisting of one node, but the user could give a target node that is // the same as the root node. Perf isn't an issue because this should // only be called once with the rootNode. this.Load(false); // Don't load images in case we are a content node. if(toc != null) return contentId; navigationKey root = new navigationKey(); root.contentId = rootContentItem.contentId; root.locale = locale; root.version = rootContentItem.version; navigationKey target = new navigationKey(); // target.contentId = "AssetId:" + assetId; target.contentId = contentId; target.locale = locale; target.version = collection + "." + version; ContentService proxy = new ContentService(); getNavigationPathsRequest request = new getNavigationPathsRequest(); request.root = root; request.target = target; getNavigationPathsResponse response = proxy.GetNavigationPaths(request); // We need to deal with the case where the content appears in many // places in the TOC. For now, just use the first path. if (response.navigationPaths.Length == 0) return null; // This is the last node in the first path. return response.navigationPaths[0].navigationPathNodes[ response.navigationPaths[0].navigationPathNodes.Length - 1].navigationNodeKey.contentId; }