public Node CreateNode( string lang, string role, int level, string currentId, Node parentNode, LocatorRelationshipInfo relation, PresentationLink pLink, bool recursive, Dimension dimensionInfo ) { Node current = null; if (e == null && pLink != null) { /* Something went wrong during mergePresentation because we should have an element at * this point. Go to the presentationLink and try to get the element. */ PresentationLocator loc = null; pLink.TryGetLocator(this.HRef, out loc); if (loc != null && loc.MyElement != null) { //update the element and the child locators e = loc.MyElement; this.childLocatorsByHRef = loc.childLocatorsByHRef; } } if (e == null) { //it is a locator to an invalid element //just return null at this point... return null; } //make sure we have the right element if there's a parent (there could be clones) Element elementToUse = e; if (dimensionInfo != null && elementToUse != null) { if (elementToUse.IsDimensionItem()) { //get the parent node if (parentNode != null) { //DimensionNode hierNode; //if (dimensionInfo.TryGetHypercubeNode(lang, // role, pLink.Role, parentNode.Id, out hierNode)) //{ // foreach (DimensionNode dn in hierNode.Children) // { // if (dn.Id == elementToUse.Id) // { // if (parentNode != null) // { // and add it // parentNode.AddChild(dn); // } // return dn; // } // } //} DimensionNode hierNode; if (dimensionInfo.TryGetHypercubeNode(lang, role, pLink.Role, parentNode.Id,true, out hierNode)) { if (hierNode.Children != null) { foreach (DimensionNode dn in hierNode.Children) { if (dn.Id == elementToUse.Id) { if (parentNode != null) { // and add it parentNode.AddChild(dn); } return dn; } } } return null; //strange ..could not find the correct hierarchy.. } else { return null; } } } } current = elementToUse==null ? new Node( href ) : elementToUse.CreateNode( lang, role, false ); if (relation != null) { current.SetOrder(relation.Order); current.CalculationWeight = relation.CalculationWeight; if (preferredLabelRole.Equals(role)) { if (relation.PrefLabel != null) { current.UpdatePreferredLabel(lang, relation.PrefLabel); } } // now check to see if it's prohibited current.IsProhibited = relation.IsProhibited; } if (parentNode != null) { // and add it parentNode.AddChild(current); } if ( childLocatorsByHRef != null && recursive ) { foreach( ChildPresentationLocator cpl in childLocatorsByHRef.Values ) { PresentationLocator childLocator; if ( !pLink.TryGetLocator( cpl.HRef, out childLocator )) { continue; } bool innerRecursive = true; if (parentNode != null && parentNode.GetParent(cpl.HRef) != null) { //this might be ok if one of the links is a prohibitted link... innerRecursive = false; //looks like we have a recursion... } //organize locators by base order //we should have only one valid LocatorRelationshipInfo for each non xlink information... LocatorRelationshipInfo currentRelationShip=null; for (int i = cpl.LocatorRelationshipInfos.Count - 1; i >= 0; i--) { LocatorRelationshipInfo lri = cpl.LocatorRelationshipInfos[i] as LocatorRelationshipInfo; if (currentRelationShip != null && lri.IsNonXlinkEquivalentRelationship(currentRelationShip)) continue; currentRelationShip = lri; // always create the child childLocator.CreateNode(lang, role, level + 1, cpl.HRef, current, lri, pLink, innerRecursive, dimensionInfo); } } //need to sort the nodes if (current.Children != null) { current.Children.Sort(new NodeOrderSorter()); } } return current; }
public Node CreateNode(string lang, string role, int level, string currentId, Node parentNode, LocatorRelationshipInfo relation, PresentationLink pLink, bool recursive, Dimension dimensionInfo) { Node current = null; if (e == null && pLink != null) { /* Something went wrong during mergePresentation because we should have an element at * this point. Go to the presentationLink and try to get the element. */ PresentationLocator loc = null; pLink.TryGetLocator(this.HRef, out loc); if (loc != null && loc.MyElement != null) { //update the element and the child locators e = loc.MyElement; this.childLocatorsByHRef = loc.childLocatorsByHRef; } } if (e == null) { //it is a locator to an invalid element //just return null at this point... return(null); } //make sure we have the right element if there's a parent (there could be clones) Element elementToUse = e; if (dimensionInfo != null && elementToUse != null) { if (elementToUse.IsDimensionItem()) { //get the parent node if (parentNode != null) { //DimensionNode hierNode; //if (dimensionInfo.TryGetHypercubeNode(lang, // role, pLink.Role, parentNode.Id, out hierNode)) //{ // foreach (DimensionNode dn in hierNode.Children) // { // if (dn.Id == elementToUse.Id) // { // if (parentNode != null) // { // and add it // parentNode.AddChild(dn); // } // return dn; // } // } //} DimensionNode hierNode; if (dimensionInfo.TryGetHypercubeNode(lang, role, pLink.Role, parentNode.Id, true, out hierNode)) { if (hierNode.Children != null) { foreach (DimensionNode dn in hierNode.Children) { if (dn.Id == elementToUse.Id) { if (parentNode != null) { // and add it parentNode.AddChild(dn); } return(dn); } } } return(null); //strange ..could not find the correct hierarchy.. } else { return(null); } } } } current = elementToUse == null ? new Node(href) : elementToUse.CreateNode(lang, role, false); if (relation != null) { current.SetOrder(relation.Order); current.CalculationWeight = relation.CalculationWeight; if (preferredLabelRole.Equals(role)) { if (relation.PrefLabel != null) { current.UpdatePreferredLabel(lang, relation.PrefLabel); } } // now check to see if it's prohibited current.IsProhibited = relation.IsProhibited; } if (parentNode != null) { // and add it parentNode.AddChild(current); } if (childLocatorsByHRef != null && recursive) { foreach (ChildPresentationLocator cpl in childLocatorsByHRef.Values) { PresentationLocator childLocator; if (!pLink.TryGetLocator(cpl.HRef, out childLocator)) { continue; } bool innerRecursive = true; if (parentNode != null && parentNode.GetParent(cpl.HRef) != null) { //this might be ok if one of the links is a prohibitted link... innerRecursive = false; //looks like we have a recursion... } //organize locators by base order //we should have only one valid LocatorRelationshipInfo for each non xlink information... LocatorRelationshipInfo currentRelationShip = null; for (int i = cpl.LocatorRelationshipInfos.Count - 1; i >= 0; i--) { LocatorRelationshipInfo lri = cpl.LocatorRelationshipInfos[i] as LocatorRelationshipInfo; if (currentRelationShip != null && lri.IsNonXlinkEquivalentRelationship(currentRelationShip)) { continue; } currentRelationShip = lri; // always create the child childLocator.CreateNode(lang, role, level + 1, cpl.HRef, current, lri, pLink, innerRecursive, dimensionInfo); } } //need to sort the nodes if (current.Children != null) { current.Children.Sort(new NodeOrderSorter()); } } return(current); }