public static bool TryGetDocumentationInformation(string language, string fileName,
            ref Dictionary<string, string> documentationByElementId, out string err)
        {
            if (documentationByElementId == null)
            {
                documentationByElementId = new Dictionary<string, string>();
            }
            err = null;

            //assuming local file
            if (File.Exists(fileName))
            {
                Label l = new Label();
                l.loadingTaxonomy = null;
                l.PromptUser = false;
                int numErrors;
                l.Load(fileName, out numErrors);

                if (numErrors == 0)
                {
                    l.Parse(out numErrors);

                }

                if (numErrors > 0)
                {
                    err = "Failed to load label file " + fileName;
                    return false;
                }
                if (l.LabelTable != null)
                {
                    foreach (LabelLocator ll in l.LabelTable.Values)
                    {
                        foreach (LabelDefinition ld in ll.LabelDatas)
                        {
                            //TODO: update the parse to filter out based on languange and label role...
                            if (ld.Language.Equals(language) && ld.LabelRole == DOCUMENTATION)
                            {
                                documentationByElementId[ll.href] = ld.Label;
                            }
                        }
                    }

                }

            }
            else
            {
                err = "Label file does not exist " + fileName;
            }

            return err == null;
        }
Exemplo n.º 2
0
        private void LoadLabels( out int numErrors )
        {
            numErrors = 0;
            int errors = 0;

            if ( dependantTaxonomies.Count == 0 )
            {
                int errs = LoadDependantTaxonomies(this.schemaPath);
                numErrors += errs;
                numLabelErrors += errs;
            }

            if ( labelFile == null )
            {
                labelFile = GetLinkbaseReference( TARGET_LINKBASE_URI + LABEL_ROLE );
            }

            if (tmplabelTable == null)
            {
                tmplabelTable = new Hashtable();

            }

            if ( labelFile != null )
            {
                //build the list of label files first..
                //as if there are multiple files then we want to load
                //the extended label file first....
                List<Label> labelsToLoad = new List<Label>();

                foreach ( string labFile in labelFile )
                {
                    if ( labFile == null || labFile.Length == 0 )
                        continue;

                    Label l = new Label();
                    l.OwnerHandle = OwnerHandle;
                    l.loadingTaxonomy = this.GetLoadingTaxonomy();
                    l.PromptUser = this.PromptUser;
                    l.Load(labFile, out numErrors);
                    if (IsAucentExtension && skipAucentExtensions && !this.innerTaxonomy &&
                        l.IsDocumentCreatedByRivet())
                    {
                        //if this is a top level aucent extension taxonomy and ...
                        //if the skipAucentExtensions is set to true ... we want to load just the no rivet created files...
                        //as we will merge the rivet created files later....
                        continue;
                    }
                    if ( l.ErrorList.Count > 0 )
                    {
                        for ( int i = 0; i < l.ErrorList.Count; i++ )
                            Common.WriteError( "XBRLParser.Error.Exception", validationErrors,
                                SchemaFile + ": LABEL_ROLE Error: " + l.ErrorList[i] );

                    }

                    l.Parse( out errors );
                    this.MergeLanguagesAndLabelRoles( l.SupportedLanguages, l.LabelRoles );
                    if ( errors > 0 )
                    {
                        numErrors += errors;
                        errorList.AddRange( l.ErrorList );
                        numLabelErrors += errors;
                    }

                    //add the lable file info to the linkbasefileinfo
                    LinkbaseFileInfo labLinkbaseInfo = new LinkbaseFileInfo();
                    labLinkbaseInfo.LinkType = LinkbaseFileInfo.LinkbaseType.Label;
                    labLinkbaseInfo.Filename = labFile;
                    labLinkbaseInfo.XSDFileName = schemaFile;

                    this.linkbaseFileInfos.Add(labLinkbaseInfo);

                    //TODO: Make sure we're not loading the same label file more than once

                    if ( l.LabelTable != null )
                    {
                        bool added = false;
                        if (!innerTaxonomy && this.IsAucentExtension )
                        {
                            //if this is the extended label file....
                            if (l.IsDocumentCreatedByRivet())
                            {
                                labelsToLoad.Insert(0, l);
                                added = true;
                            }

                        }
                        if (!added)
                        {
                            labelsToLoad.Add(l);

                        }

                    }

                }

                foreach (Label l in labelsToLoad)
                {
                    foreach (LabelLocator labelFileLL in l.LabelTable.Values)
                    {

                        if (tmplabelTable.Contains(labelFileLL.href))
                        {
                            //element already exists in labelTable, so add new labelLocator to the existing value
                            ArrayList labelErrors = new ArrayList();
                            LabelLocator ll = tmplabelTable[labelFileLL.href] as LabelLocator;
                            ll.AddLabels(labelFileLL, labelErrors);
                        }
                        else
                        {
                            tmplabelTable[labelFileLL.href] = labelFileLL;
                        }
                    }
                }
            }

            if ( !innerTaxonomy )
            {
                labelHrefHash = new Hashtable();
                PopulateHrefHash(this.tmplabelTable);
                // and add the dependant taxonomy label files
                foreach ( Taxonomy t in dependantTaxonomies )
                {
                    PopulateHrefHash(t.tmplabelTable);
                    //not sure what the merged label table is goin to be used for
                    //but for now leaving it alone as don't want to create any new impact
                    errors = 0;

                    //merge the supported languages and roles....
                    this.MergeLanguagesAndLabelRoles( t.supportedLanguages, t.labelRoles );
                }
            }
        }