Пример #1
0
        public Anexo Clone()
        {
            Anexo result = new Anexo();

            result.pid          = this.pid;
            result.dataStreamID = this.dataStreamID;
            result.mimeType     = this.mimeType;
            result.url          = this.url;
            result.checksum     = this.checksum;
            return(result);
        }
Пример #2
0
        private ListViewItem CreateNewItem(string url)
        {
            Fedora.FedoraHandler.Anexo anexoNovo = new Fedora.FedoraHandler.Anexo();
            anexoNovo.url = url;
            bool foundMimeType;

            anexoNovo.mimeType = Fedora.FedoraHandler.Utility.GetMIME(url, out foundMimeType);
            ListViewItem newItem = CreateItem(url, anexoNovo);

            newItem.Font = PermissoesHelper.fontItalic;
            return(newItem);
        }
Пример #3
0
        public void ShowAnexo(Anexo anexo)
        {
            this.Cursor = Cursors.WaitCursor;
            this.objectoActual = anexo;
            this.cmbQuality.Enabled = false;

            string url;
            bool success;
            string errorMessage;
            if (anexo.isIngested) url = SessionHelper.AppConfiguration.GetCurrentAppconfiguration().FedoraHelperSingleton.GetDatastream(anexo.pid, anexo.dataStreamID, out success, out errorMessage);
            else url = ImageHelper.getAndConvertImageResourceToPng(anexo.url, out success, out errorMessage);

            if (success)
            {
                errorLabel.Visible = false;

                Uri uri;
                if (Uri.TryCreate(url, UriKind.Absolute, out uri))
                {
                    string newPage = Fedora.FedoraHandler.Utility.GetResizableImgElement(url);

                    webBrowser.Navigate("");
                    if (webBrowser.ReadyState != WebBrowserReadyState.Uninitialized)
                    {
                        webBrowser.Document.OpenNew(false);
                        webBrowser.Document.Write(newPage);
                        webBrowser.Refresh();
                    }
                    isDocumentLoaded = true;
                }
                else { Clear(); }
            }
            else ShowError(errorMessage);

            this.Cursor = Cursors.Default;            
        }
Пример #4
0
 private ListViewItem CreateNewItem(string url)
 {
     Fedora.FedoraHandler.Anexo anexoNovo = new Fedora.FedoraHandler.Anexo();
     anexoNovo.url = url;
     bool foundMimeType;
     anexoNovo.mimeType = Fedora.FedoraHandler.Utility.GetMIME(url, out foundMimeType);
     ListViewItem newItem = CreateItem(url, anexoNovo);
     newItem.Font = PermissoesHelper.fontItalic;
     return newItem;
 }
Пример #5
0
        private void DoTheMETS(ObjDigital obj, string[] logMessage)
        {
            var idsGisa = new string[] { obj.gisa_id };
            var title   = obj.titulo;
            var type    = obj.tipologia;

            // Ficheiro METS
            mets = new MetsFile(null, null, title, type, null);

            // Header - criador, hora de criação, e IDs alternativos
            mets.header = new MetsHeaderSection(null, null, Utility.Now(), null, null);
            mets.header.AddAgent(new MetsAgent(null, MetsAgentRole.Archivist, null, MetsAgentType.Individual, null, userName, logMessage));
            foreach (string s in idsGisa.Where(id => id.Length > 0))
            {
                string typeID = s.Substring(0, s.IndexOf(':'));
                mets.header.AddAltID(new MetsAlternativeIdentifier(null, typeID, s));
            }

            // Criar a secção de Ficheiros
            mets.fileSection = new MetsFileSection(null);
            MetsFileGroup fileGrp = new MetsFileGroup(null, null, null, "Conteúdos");

            mets.fileSection.AddFileGroupElement(fileGrp);

            MetsStructMap      structa   = null;
            MetsStructDivision largeFile = null;

            if (obj.GetType() == typeof(ObjDigSimples))
            {
                ObjDigSimples objSimples = obj as ObjDigSimples;
                structa   = new MetsStructMap(null, "PHYSICAL", "Estruturação em imagens do " + title);
                largeFile = new MetsStructDivision(null, type, title, null, null, null, null, null, null);

                for (int i = 0; i < objSimples.fich_associados.Count; i++)
                {
                    Anexo ficheiro = objSimples.fich_associados[i];

                    if (ficheiro.dataStreamID == null)
                    {
                        ficheiro.dataStreamID = "IMG" + objSimples.nextDatastreamId;
                        objSimples.nextDatastreamId++;
                    }
                    string uName = ficheiro.dataStreamID;

                    MetsFileElement file = new MetsFileElement(uName, ficheiro.mimeType, (i + 1).ToString(), null, null, null, MetsChecksumType.NONE, null, null, null, null, null);
                    file.AddFLocat(new MetsXLinkElement(null, null, MetsLocatorType.Other, "Nome de Datastream", uName, null, null, null, null, null));
                    fileGrp.AddFileElement(file);

                    MetsStructDivision div = new MetsStructDivision(null, ficheiro.mimeType, title, null, null, (i + 1).ToString(), null, null, null);
                    div.AddFilePointer(new MetsFilePointer(null, uName, null));
                    largeFile.AddDivision(div);
                }
            }
            else
            {
                ObjDigComposto objComposto = obj as ObjDigComposto;
                structa   = new MetsStructMap(null, "LOGICAL", "Estruturação em partes do " + title);
                largeFile = new MetsStructDivision(null, type, title, null, null, null, null, null, null);
                foreach (ObjDigSimples sd in objComposto.objSimples)
                {
                    // Apenas queremos fazer isto se o objecto não estiver marcado como apagado
                    if (sd.state != State.deleted)
                    {
                        string             pid = sd.pid;
                        MetsStructDivision div = new MetsStructDivision(null, sd.tipologia, sd.titulo, null, null, (objComposto.objSimples.IndexOf(sd) + 1).ToString(), null, null, null);
                        div.AddFilePointer(new MetsFilePointer(null, pid, null));
                        largeFile.AddDivision(div);
                    }
                }
            }

            structa.AddDivision(largeFile);
            mets.AddStructMap(structa);
        }
Пример #6
0
        public ObjDigital GetStructureForPid(string pid, string originalTimestamp, bool loadVersions)
        {
            XmlDocument metsDoc;
            XmlDocument dcDoc;
            XmlNamespaceManager nameSpaceManager;
            XmlNamespaceManager dcNameSpaceManager;
            string versionTimestamp = null;
            try {
                versionTimestamp = manager.getDatastream(pid, "METS", originalTimestamp).createDate;

                MIMETypedStream stream = service.getDatastreamDissemination(pid, "METS", originalTimestamp);
                metsDoc = GetXmlFromStream(stream);
                nameSpaceManager = new XmlNamespaceManager(metsDoc.NameTable);
                nameSpaceManager.AddNamespace("mets", "http://www.loc.gov/METS/");
                nameSpaceManager.AddNamespace("xlink", "http://www.w3.org/TR/xlink/");

                // Temos de pedir o DC mais próximo da versão mais actualizada do METS (logo passamos o versionTimestamp)
                MIMETypedStream dcStream = service.getDatastreamDissemination(pid, "DC", versionTimestamp);
                dcDoc = GetXmlFromStream(dcStream);
                dcNameSpaceManager = new XmlNamespaceManager(dcDoc.NameTable);
                dcNameSpaceManager.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
                dcNameSpaceManager.AddNamespace("oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
                dcNameSpaceManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

            } catch (Exception ex) { throw new Exception("Datastreams METS e/ou DC inválidos para o objecto " + pid + ".", ex); }

            try {
                XmlNode structMap = metsDoc.SelectSingleNode("mets:mets/mets:structMap", nameSpaceManager);
                XmlNode mainDiv = structMap.SelectSingleNode("mets:div", nameSpaceManager);
                XmlNode recordID = metsDoc.SelectSingleNode("mets:mets/mets:metsHdr/mets:altRecordID", nameSpaceManager);

                string type;
                try { type = structMap.Attributes["TYPE"].Value.ToString().ToUpper();
                } catch { type = "PHYSICAL"; }
                ObjDigital newDocumentType = null;
                if (type == "LOGICAL")
                {
                    newDocumentType = new ObjDigComposto();
                    newDocumentType.state = State.unchanged;
                    newDocumentType.serverState = GetState(pid);
                    ObjDigSimples[] parts = new ObjDigSimples[mainDiv.SelectNodes("mets:div", nameSpaceManager).Count];

                    foreach (XmlNode subDiv in mainDiv.SelectNodes("mets:div", nameSpaceManager))
                    {
                        // Ler objecto directamente
                        XmlNode fptr = subDiv.SelectSingleNode("mets:fptr", nameSpaceManager);
                        ObjDigSimples objSimples = GetStructureForPid(fptr.Attributes["FILEID"].Value, originalTimestamp, true) as ObjDigSimples;
                        parts[int.Parse(subDiv.Attributes["ORDER"].Value) - 1] = objSimples;
                    }

                    ((ObjDigComposto)newDocumentType).objSimples.AddRange(parts);
                }
                else { 
                    newDocumentType = new ObjDigSimples();
                    newDocumentType.state = State.unchanged;
                    newDocumentType.serverState = GetState(pid);
                    Anexo[] parts = new Anexo[mainDiv.SelectNodes("mets:div", nameSpaceManager).Count];

                    foreach (XmlNode subDiv in mainDiv.SelectNodes("mets:div", nameSpaceManager))
                    {
                        XmlNode fptr = subDiv.SelectSingleNode("mets:fptr", nameSpaceManager);
                        Anexo anexo = new Anexo();

                        anexo.pid = pid;
                        anexo.dataStreamID = fptr.Attributes["FILEID"].Value;
                        anexo.mimeType = subDiv.Attributes["TYPE"].Value;
                        parts[int.Parse(subDiv.Attributes["ORDER"].Value) - 1] = anexo;

                        try
                        {
                            Datastream data = manager.getDatastream(pid, anexo.dataStreamID, null);
                            anexo.url = data.location;
                            anexo.checksum = data.checksum;
                        }
                        catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw new Exception("URL de datastream " + anexo.dataStreamID + " no objecto " + pid + " não foi encontrado.", ex);  }
                    }

                    ((ObjDigSimples)newDocumentType).nextDatastreamId = service.listDatastreams(pid, null).Count(ds => ds.ID.Contains("IMG")) + 1;
                    ((ObjDigSimples)newDocumentType).fich_associados.AddRange(parts);

                    if(loadVersions)
                        ((ObjDigSimples)newDocumentType).historico.AddRange(GetHistoric(pid));
                    
                }

                newDocumentType.pid = pid;
                newDocumentType.version = versionTimestamp;
                newDocumentType.titulo = mainDiv.Attributes["LABEL"].Value;
                if (mainDiv.Attributes["TYPE"] != null)
                    newDocumentType.tipologia = mainDiv.Attributes["TYPE"].Value;
                if (recordID != null)  // há objetos que não têm gisa_id
                    newDocumentType.gisa_id = recordID.InnerText;
                else
                    newDocumentType.gisa_id = "";

                XmlNodeList assuntos = dcDoc.SelectNodes("oai_dc:dc/dc:subject", dcNameSpaceManager);
                if (assuntos.Count > 0)
                {
                    List<string> listAssuntos = new List<string>();
                    foreach (XmlNode node in assuntos) listAssuntos.Add(node.InnerText);
                    newDocumentType.assuntos = listAssuntos;
                }

                return newDocumentType;
            }
            catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw new Exception("Erro ao analisar objecto " + pid + ".", ex); }
        }
Пример #7
0
        public ObjDigital GetStructureForPid(string pid, string originalTimestamp, bool loadVersions)
        {
            XmlDocument         metsDoc;
            XmlDocument         dcDoc;
            XmlNamespaceManager nameSpaceManager;
            XmlNamespaceManager dcNameSpaceManager;
            string versionTimestamp = null;

            try {
                versionTimestamp = manager.getDatastream(pid, "METS", originalTimestamp).createDate;

                MIMETypedStream stream = service.getDatastreamDissemination(pid, "METS", originalTimestamp);
                metsDoc          = GetXmlFromStream(stream);
                nameSpaceManager = new XmlNamespaceManager(metsDoc.NameTable);
                nameSpaceManager.AddNamespace("mets", "http://www.loc.gov/METS/");
                nameSpaceManager.AddNamespace("xlink", "http://www.w3.org/TR/xlink/");

                // Temos de pedir o DC mais próximo da versão mais actualizada do METS (logo passamos o versionTimestamp)
                MIMETypedStream dcStream = service.getDatastreamDissemination(pid, "DC", versionTimestamp);
                dcDoc = GetXmlFromStream(dcStream);
                dcNameSpaceManager = new XmlNamespaceManager(dcDoc.NameTable);
                dcNameSpaceManager.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
                dcNameSpaceManager.AddNamespace("oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
                dcNameSpaceManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            } catch (Exception ex) { throw new Exception("Datastreams METS e/ou DC inválidos para o objecto " + pid + ".", ex); }

            try {
                XmlNode structMap = metsDoc.SelectSingleNode("mets:mets/mets:structMap", nameSpaceManager);
                XmlNode mainDiv   = structMap.SelectSingleNode("mets:div", nameSpaceManager);
                XmlNode recordID  = metsDoc.SelectSingleNode("mets:mets/mets:metsHdr/mets:altRecordID", nameSpaceManager);

                string type;
                try { type = structMap.Attributes["TYPE"].Value.ToString().ToUpper(); } catch { type = "PHYSICAL"; }
                ObjDigital newDocumentType = null;
                if (type == "LOGICAL")
                {
                    newDocumentType             = new ObjDigComposto();
                    newDocumentType.state       = State.unchanged;
                    newDocumentType.serverState = GetState(pid);
                    ObjDigSimples[] parts = new ObjDigSimples[mainDiv.SelectNodes("mets:div", nameSpaceManager).Count];

                    foreach (XmlNode subDiv in mainDiv.SelectNodes("mets:div", nameSpaceManager))
                    {
                        // Ler objecto directamente
                        XmlNode       fptr       = subDiv.SelectSingleNode("mets:fptr", nameSpaceManager);
                        ObjDigSimples objSimples = GetStructureForPid(fptr.Attributes["FILEID"].Value, originalTimestamp, true) as ObjDigSimples;
                        parts[int.Parse(subDiv.Attributes["ORDER"].Value) - 1] = objSimples;
                    }

                    ((ObjDigComposto)newDocumentType).objSimples.AddRange(parts);
                }
                else
                {
                    newDocumentType             = new ObjDigSimples();
                    newDocumentType.state       = State.unchanged;
                    newDocumentType.serverState = GetState(pid);
                    Anexo[] parts = new Anexo[mainDiv.SelectNodes("mets:div", nameSpaceManager).Count];

                    foreach (XmlNode subDiv in mainDiv.SelectNodes("mets:div", nameSpaceManager))
                    {
                        XmlNode fptr  = subDiv.SelectSingleNode("mets:fptr", nameSpaceManager);
                        Anexo   anexo = new Anexo();

                        anexo.pid          = pid;
                        anexo.dataStreamID = fptr.Attributes["FILEID"].Value;
                        anexo.mimeType     = subDiv.Attributes["TYPE"].Value;
                        parts[int.Parse(subDiv.Attributes["ORDER"].Value) - 1] = anexo;

                        try
                        {
                            Datastream data = manager.getDatastream(pid, anexo.dataStreamID, null);
                            anexo.url      = data.location;
                            anexo.checksum = data.checksum;
                        }
                        catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw new Exception("URL de datastream " + anexo.dataStreamID + " no objecto " + pid + " não foi encontrado.", ex); }
                    }

                    ((ObjDigSimples)newDocumentType).nextDatastreamId = service.listDatastreams(pid, null).Count(ds => ds.ID.Contains("IMG")) + 1;
                    ((ObjDigSimples)newDocumentType).fich_associados.AddRange(parts);

                    if (loadVersions)
                    {
                        ((ObjDigSimples)newDocumentType).historico.AddRange(GetHistoric(pid));
                    }
                }

                newDocumentType.pid     = pid;
                newDocumentType.version = versionTimestamp;
                newDocumentType.titulo  = mainDiv.Attributes["LABEL"].Value;
                if (mainDiv.Attributes["TYPE"] != null)
                {
                    newDocumentType.tipologia = mainDiv.Attributes["TYPE"].Value;
                }
                if (recordID != null)  // há objetos que não têm gisa_id
                {
                    newDocumentType.gisa_id = recordID.InnerText;
                }
                else
                {
                    newDocumentType.gisa_id = "";
                }

                XmlNodeList assuntos = dcDoc.SelectNodes("oai_dc:dc/dc:subject", dcNameSpaceManager);
                if (assuntos.Count > 0)
                {
                    List <string> listAssuntos = new List <string>();
                    foreach (XmlNode node in assuntos)
                    {
                        listAssuntos.Add(node.InnerText);
                    }
                    newDocumentType.assuntos = listAssuntos;
                }

                return(newDocumentType);
            }
            catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw new Exception("Erro ao analisar objecto " + pid + ".", ex); }
        }
Пример #8
0
 public Anexo Clone()
 {
     Anexo result = new Anexo();
     result.pid = this.pid;
     result.dataStreamID = this.dataStreamID;
     result.mimeType = this.mimeType;
     result.url = this.url;
     result.checksum = this.checksum;
     return result;
 }