public bool Validate(urakawa.metadata.Metadata metadata, MetadataDefinition definition) { switch (definition.DataType) { case MetadataDataType.ClockValue: return(_validateClockValue(metadata, definition)); case MetadataDataType.Date: return(_validateDate(metadata, definition)); case MetadataDataType.FileUri: return(_validateFileUri(metadata, definition)); case MetadataDataType.Integer: return(_validateInteger(metadata, definition)); case MetadataDataType.Double: return(_validateDouble(metadata, definition)); case MetadataDataType.Number: return(_validateNumber(metadata, definition)); case MetadataDataType.LanguageCode: return(_validateLanguageCode(metadata, definition)); case MetadataDataType.String: return(_validateString(metadata, definition)); } return(true); }
public AddEntry(ProjectView.ProjectView view) : base(view) { mEntry = view.Presentation.MetadataFactory.CreateMetadata(); mEntry.NameContentAttribute = new MetadataAttribute(); SetDescriptions(Localizer.Message("add_metadata_entry")); }
/// <summary> /// Delete a metadata entry (with event.) /// </summary> public void DeleteMetadata(urakawa.metadata.Metadata entry) { Metadatas.Remove(entry); //sdk2 deleteMetadata(entry); //sdk2-todo use SDK 2.0 events if (MetadataEntryDeleted != null) { MetadataEntryDeleted(this, new MetadataEventArgs(entry)); } }
public void SetMetadataEntryName(urakawa.metadata.Metadata entry, string name) { entry.NameContentAttribute.Name = name; //sdk2 entry.setName(name); //sdk2-todo use SDK 2.0 events if (MetadataEntryNameChanged != null) { MetadataEntryNameChanged(this, new MetadataEventArgs(entry)); } }
/// <summary> /// Add a new metadata entry (with event.) /// </summary> public void AddMetadata(urakawa.metadata.Metadata entry) { Metadatas.Insert(Metadatas.Count, entry); //sdk2 addMetadata(entry); //sdk2-todo use SDK 2.0 events if (MetadataEntryAdded != null) { MetadataEntryAdded(this, new MetadataEventArgs(entry)); } }
//works for both double and int private bool _validateNumber(urakawa.metadata.Metadata metadata, MetadataDefinition definition) { //bool res = _validateInteger(metadata, definition); //if (!res) return false; bool res = _validateDouble(metadata, definition); if (!res) { return(false); } return(true); }
public void SetMetadataEntryContent(urakawa.metadata.Metadata entry, string content) { entry.NameContentAttribute.Value = content; if (entry.NameContentAttribute.Name == Metadata.DC_LANGUAGE) { this.Language = content; } //sdk2 entry.setContent(content); //sdk2-todo use SDK 2.0 events if (MetadataEntryContentChanged != null) { MetadataEntryContentChanged(this, new MetadataEventArgs(entry)); } }
/// <summary> /// Add a new channel with the given name to the presentation's channel manager. /// </summary> //sdk2 //internal Channel AddChannel(string name) //{ // Channel channel = getChannelFactory().createChannel(); // channel.setName(name); // getChannelsManager().addChannel(channel); // return channel; //} /// <summary> /// Convenience method to create a new metadata object with a name/value pair. /// Skip it if there is no value (the toolkit doesn't like it.) /// </summary> private urakawa.metadata.Metadata AddMetadata(string name, string value) { if (value != null) { urakawa.metadata.Metadata meta = MetadataFactory.CreateMetadata(); meta.NameContentAttribute = new MetadataAttribute(); meta.NameContentAttribute.Name = name; meta.NameContentAttribute.Value = value; AddMetadata(meta); return(meta); } else { return(null); } }
private Dictionary <string, string> PopulateSmilMetadataDictionary() { Dictionary <string, string> metadataItems = new Dictionary <string, string> (); /* * List<urakawa.metadata.Metadata> items = m_Presentation.getListOfMetadata (); * items.Sort ( delegate ( urakawa.metadata.Metadata a, urakawa.metadata.Metadata b ) * { * int names = a.getName ().CompareTo ( b.getName () ); * return names == 0 ? a.getContent ().CompareTo ( b.getContent () ) : names; * } ); * * * XmlNode headNode = nccDocument.GetElementsByTagName ( "head" )[0]; * // add existing metadata items to ncc * foreach (urakawa.metadata.Metadata m in items) * { * if ( metadataMap.ContainsKey(m.getName () )) * { */ ObiPresentation presentation = (ObiPresentation)m_Presentation; urakawa.metadata.Metadata identifier = presentation.GetFirstMetadataItem("dc:Identifier"); if (identifier != null) { metadataItems.Add(m_MetadataMap[identifier.NameContentAttribute.Name], identifier.NameContentAttribute.Value); } urakawa.metadata.Metadata format = presentation.GetFirstMetadataItem("dc:Format"); if (format != null) { metadataItems.Add(m_MetadataMap[format.NameContentAttribute.Name], format.NameContentAttribute.Value); } urakawa.metadata.Metadata generator = presentation.GetFirstMetadataItem("generator"); if (generator != null) { metadataItems.Add(m_MetadataMap[generator.NameContentAttribute.Name], generator.NameContentAttribute.Value); } return(metadataItems); }
// Update metadata before exporting private void UpdatePublicationMetadata() { string date = DateTime.Today.ToString("yyyy-MM-dd"); urakawa.metadata.Metadata dc_Date = GetFirstMetadataItem(Metadata.DC_DATE); urakawa.metadata.Metadata producedDate = GetFirstMetadataItem(Metadata.DTB_PRODUCED_DATE); urakawa.metadata.Metadata revision = GetFirstMetadataItem(Metadata.DTB_REVISION); urakawa.metadata.Metadata revisionDate = GetFirstMetadataItem(Metadata.DTB_REVISION_DATE); if (dc_Date == null) { SetSingleMetadataItem(Metadata.DC_DATE, date); } if (producedDate == null) { System.Diagnostics.Debug.Assert(revisionDate == null && revision == null); SetSingleMetadataItem(Metadata.DTB_PRODUCED_DATE, date); } else { if (revision != null) { System.Diagnostics.Debug.Assert(revisionDate != null); //int rev = Int32.Parse(revision.getContent()) + 1; //int rev = Int32.Parse(revision.NameContentAttribute.Value) + 1;//sdk2 int rev; Int32.TryParse(revision.NameContentAttribute.Value, out rev); rev = rev + 1; SetMetadataEntryContent(revision, rev.ToString()); if (revisionDate == null) { SetSingleMetadataItem(Metadata.DTB_REVISION_DATE, date); } else { SetMetadataEntryContent(revisionDate, date); } } else { System.Diagnostics.Debug.Assert(revisionDate == null); SetSingleMetadataItem(Metadata.DTB_REVISION, "1"); SetSingleMetadataItem(Metadata.DTB_REVISION_DATE, date); } } }
private bool _validateDouble(urakawa.metadata.Metadata metadata, MetadataDefinition definition) { try { double x = Convert.ToDouble(metadata.NameContentAttribute.Value); } catch (Exception) { MetadataFormatValidationError err = new MetadataFormatValidationError(metadata, definition, m_EventAggregator); err.Hint = m_NumericHint; m_ParentValidator.ReportError(err); return(false); } return(true); }
private bool _validateItem(urakawa.metadata.Metadata metadata) { MetadataDefinition metadataDefinition = MetadataDefinitions.GetMetadataDefinition(metadata.NameContentAttribute.Name, true); if (metadataDefinition == null) { metadataDefinition = MetadataDefinitions.UnrecognizedItemFallbackDefinition; } //check the occurrence requirement bool meetsOccurrenceRequirement = m_OccurrenceValidator.Validate(metadata, metadataDefinition); //check the data type bool meetsDataTypeRequirement = m_DataTypeValidator.Validate(metadata, metadataDefinition); return(meetsOccurrenceRequirement && meetsDataTypeRequirement); }
private bool _validateLanguageCode(urakawa.metadata.Metadata metadata, MetadataDefinition definition) { string lang = metadata.NameContentAttribute.Value; bool valid = true; if (m_InvalidLanguageCodes.Contains(lang)) { valid = false; } else { try { CultureInfo info = CultureInfo.GetCultureInfo(lang); if (info != null) { return(true); } } catch { valid = false; if (!m_InvalidLanguageCodes.Contains(lang)) { m_InvalidLanguageCodes.Add(lang); } } } if (valid) { return(true); } MetadataFormatValidationError err = new MetadataFormatValidationError(metadata, definition, m_EventAggregator); err.Hint = m_LanguageHint; m_ParentValidator.ReportError(err); return(false); }
public bool Validate(urakawa.metadata.Metadata metadata, MetadataDefinition definition) { //neither required nor optional fields may be empty //check both an empty string and our "magic" string value that is //used upon creation of a new metadata item if (!string.IsNullOrEmpty(metadata.NameContentAttribute.Value) && metadata.NameContentAttribute.Value != SupportedMetadata_Z39862005.MagicStringEmpty) { return(true); } else { MetadataFormatValidationError err = new MetadataFormatValidationError(metadata, definition, m_EventAggregator); err.Hint = m_NonEmptyHint; m_ParentValidator.ReportError(err); return(false); } }
public void CheckAndCreateDefaultMetadataItems(UserProfile userProfile) { if (GetFirstMetadataItem(Metadata.DC_PUBLISHER) == null) { SetSingleMetadataItem(Obi.Metadata.DC_PUBLISHER, userProfile.Organization); } if (GetFirstMetadataItem(Metadata.DC_LANGUAGE) == null) { SetSingleMetadataItem(Obi.Metadata.DC_LANGUAGE, userProfile.Culture.ToString()); } if (GetFirstMetadataItem(Metadata.DC_CREATOR) == null) { SetSingleMetadataItem(Obi.Metadata.DC_CREATOR, Localizer.Message("Metadata_CreatorNameForInitializing")); //it is important for DAISY 2.02 } if (GetFirstMetadataItem(Metadata.DTB_NARRATOR) == null) { SetSingleMetadataItem(Obi.Metadata.DTB_NARRATOR, userProfile.Name); } urakawa.metadata.Metadata mdGenerator = GetFirstMetadataItem(Metadata.GENERATOR); if (mdGenerator == null) { SetSingleMetadataItem(Obi.Metadata.GENERATOR, DataModelFactory.Generator); } else { mdGenerator.NameContentAttribute.Value = DataModelFactory.Generator; } urakawa.metadata.Metadata mdXukVersion = GetFirstMetadataItem(Metadata.OBI_XUK_VERSION); if (mdXukVersion == null) { SetSingleMetadataItem(Obi.Metadata.OBI_XUK_VERSION, DataModelFactory.XUK_VERSION); } else { mdXukVersion.NameContentAttribute.Value = DataModelFactory.XUK_VERSION; } }
public MetadataFormatValidationError(urakawa.metadata.Metadata target, MetadataDefinition definition, IEventAggregator eventAggregator) : base(target, definition, eventAggregator) { }
private bool _validateClockValue(urakawa.metadata.Metadata metadata, MetadataDefinition definition) { return(true); }
private bool _validateDate(urakawa.metadata.Metadata metadata, MetadataDefinition definition) { MetadataFormatValidationError err = new MetadataFormatValidationError(metadata, definition, m_EventAggregator); err.Hint = m_DateHint; string date = metadata.NameContentAttribute.Value; //Require at least the year field //The max length of the entire datestring is 10 if (date.Length < 4 || date.Length > 10) { m_ParentValidator.ReportError(err); return(false); } string[] dateArray = date.Split('-'); //the year has to be 4 digits if (dateArray[0].Length != 4) { m_ParentValidator.ReportError(err); return(false); } //the year has to be digits try { int year = Convert.ToInt32(dateArray[0]); } catch { m_ParentValidator.ReportError(err); return(false); } //check for a month value (it's optional) if (dateArray.Length >= 2) { //the month has to be numeric int month = 0; try { month = Convert.ToInt32(dateArray[1]); } catch { m_ParentValidator.ReportError(err); return(false); } //the month has to be in this range if (month < 1 || month > 12) { m_ParentValidator.ReportError(err); return(false); } } //check for a day value (it's optional but only if a month is specified) if (dateArray.Length == 3) { //the day has to be a number int day = 0; try { day = Convert.ToInt32(dateArray[2]); } catch { m_ParentValidator.ReportError(err); return(false); } //it has to be in this range if (day < 1 || day > 31) { m_ParentValidator.ReportError(err); return(false); } } return(true); }
private void CreateNCCMetadata(XmlDocument nccDocument, string tocItems) { List <urakawa.metadata.Metadata> items = m_Presentation.Metadatas.ContentsAs_ListCopy; items.Sort(delegate(urakawa.metadata.Metadata a, urakawa.metadata.Metadata b) { int names = a.NameContentAttribute.Name.CompareTo(b.NameContentAttribute.Name); return(names == 0 ? a.NameContentAttribute.Value.CompareTo(b.NameContentAttribute.Value) : names); }); XmlNode headNode = nccDocument.GetElementsByTagName("head")[0]; // create first meta node XmlNode firstMetaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(firstMetaNode); CreateAppendXmlAttribute(nccDocument, firstMetaNode, "content", "text/html; charset=utf-8"); CreateAppendXmlAttribute(nccDocument, firstMetaNode, "http-equiv", "Content-type"); //<meta content="text/html; charset=utf-8" http-equiv="Content-type"/> ObiPresentation presentation = (ObiPresentation)m_Presentation; urakawa.metadata.Metadata titleMetadata = presentation.GetFirstMetadataItem("dc:Title"); if (titleMetadata != null) { XmlNode titleMetadataNode = nccDocument.CreateElement(null, "title", headNode.NamespaceURI); headNode.AppendChild(titleMetadataNode); titleMetadataNode.AppendChild( nccDocument.CreateTextNode(titleMetadata.NameContentAttribute.Value)); } // add dc:date from produced date in case dc:date do not exists urakawa.metadata.Metadata producedDateMetadata = presentation.GetFirstMetadataItem(Metadata.DTB_PRODUCED_DATE); if (presentation.GetFirstMetadataItem(Metadata.DC_DATE) == null && producedDateMetadata != null) { XmlNode dateMetadataNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(dateMetadataNode); CreateAppendXmlAttribute(nccDocument, dateMetadataNode, "name", "dc:date"); CreateAppendXmlAttribute(nccDocument, dateMetadataNode, "content", producedDateMetadata.NameContentAttribute.Value); } // add existing metadata items to nccn foreach (urakawa.metadata.Metadata m in items) { if (m_MetadataMap.ContainsKey(m.NameContentAttribute.Name)) { XmlNode metaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(metaNode); CreateAppendXmlAttribute(nccDocument, metaNode, "name", m_MetadataMap[m.NameContentAttribute.Name]); CreateAppendXmlAttribute(nccDocument, metaNode, "content", m.NameContentAttribute.Value); } } // to do add more metadata items. // add dc:format XmlNode formatNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(formatNode); CreateAppendXmlAttribute(nccDocument, formatNode, "name", "dc:format"); CreateAppendXmlAttribute(nccDocument, formatNode, "content", "Daisy 2.02"); // ncc:charset XmlNode charsetNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(charsetNode); CreateAppendXmlAttribute(nccDocument, charsetNode, "name", "ncc:charset"); CreateAppendXmlAttribute(nccDocument, charsetNode, "content", "utf-8"); XmlNode pageMetaNode = null; // ncc:pageFront pageMetaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(pageMetaNode); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "name", "ncc:pageFront"); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "content", m_PageFrontCount.ToString()); // ncc:maxPageNormal and pageNormal pageMetaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(pageMetaNode); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "name", "ncc:maxPageNormal"); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "content", m_MaxPageNormal.ToString()); // ncc:pageNormal pageMetaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(pageMetaNode); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "name", "ncc:pageNormal"); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "content", m_PageNormalCount.ToString()); // ncc:pageSpecial pageMetaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(pageMetaNode); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "name", "ncc:pageSpecial"); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "content", m_PageSpecialCount.ToString()); // ncc:prodNotes // ncc:tocItems XmlNode tocItemNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(tocItemNode); CreateAppendXmlAttribute(nccDocument, tocItemNode, "name", "ncc:tocItems"); CreateAppendXmlAttribute(nccDocument, tocItemNode, "content", tocItems); // ncc:totalTime XmlNode totalTimeNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(totalTimeNode); CreateAppendXmlAttribute(nccDocument, totalTimeNode, "name", "ncc:totalTime"); //CreateAppendXmlAttribute ( nccDocument, totalTimeNode, "content", m_SmilElapseTime.ToString ().Split ( '.' )[0] ); CreateAppendXmlAttribute(nccDocument, totalTimeNode, "content", GetStringTotalTimeRoundedOff(new TimeSpan(m_SmilElapseTime.AsTimeSpanTicks))); XmlNode multimediaType = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(multimediaType); CreateAppendXmlAttribute(nccDocument, multimediaType, "name", "ncc:multimediaType"); CreateAppendXmlAttribute(nccDocument, multimediaType, "content", "audioNcc"); // ncc:depth XmlNode depthNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(depthNode); CreateAppendXmlAttribute(nccDocument, depthNode, "name", "ncc:depth"); CreateAppendXmlAttribute(nccDocument, depthNode, "content", m_MaxDepth.ToString()); // ncc:files int filesCount = m_FilesList.Count + 2; XmlNode filesCountNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(filesCountNode); CreateAppendXmlAttribute(nccDocument, filesCountNode, "name", "ncc:files"); CreateAppendXmlAttribute(nccDocument, filesCountNode, "content", filesCount.ToString()); }
public MetadataEventArgs(urakawa.metadata.Metadata entry) : base() { mEntry = entry; }
private bool _validateString(urakawa.metadata.Metadata metadata, MetadataDefinition definition) { return(true); }
private void CreateFileSet(List <SectionNode> sectionsList) { XmlDocument nccDocument = CreateNCCStubDocument(); m_IdCounter = 0; // initialize page counts to 0 m_PageFrontCount = 0; m_PageNormalCount = 0; m_PageSpecialCount = 0; m_MaxPageNormal = 0; m_ExportedSectionCount = 0; // generate smil metadata dictionary. m_SmilMetadata = PopulateSmilMetadataDictionary(); m_SmilFile_TitleMap.Clear(); m_SmilElapseTime = new Time(); for (int i = 0; i < sectionsList.Count; i++) { try { if (m_MaxDepth < sectionsList[i].Level) { m_MaxDepth = sectionsList[i].Level; } CreateElementsForSection(nccDocument, sectionsList[i], i); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } } int tocItemsCount = m_ExportedSectionCount + m_PageFrontCount + m_PageNormalCount + m_PageSpecialCount; CreateNCCMetadata(nccDocument, tocItemsCount.ToString()); // write ncc file WriteXmlDocumentToFile(nccDocument, Path.Combine(m_ExportDirectory, "ncc.html")); // create master.smil file XmlDocument smilDocument = CreateSmilStubDocument(); XmlNode bodyNode = smilDocument.GetElementsByTagName("body")[0]; foreach (string smilFileName in m_SmilFile_TitleMap.Keys) { XmlNode refNode = smilDocument.CreateElement(null, "ref", bodyNode.NamespaceURI); bodyNode.AppendChild(refNode); CreateAppendXmlAttribute(smilDocument, refNode, "title", m_SmilFile_TitleMap[smilFileName]); CreateAppendXmlAttribute(smilDocument, refNode, "src", smilFileName); CreateAppendXmlAttribute(smilDocument, refNode, "id", "ms_" + Path.GetFileNameWithoutExtension(smilFileName)); } // add dc:title, this is mandatory for master.smil urakawa.metadata.Metadata titleMetadata = ((ObiPresentation)m_Presentation).GetFirstMetadataItem("dc:Title"); if (titleMetadata != null) { XmlNode masterSmilHeadNode = smilDocument.GetElementsByTagName("head")[0]; XmlNode smilTitleMetadataNode = smilDocument.CreateElement(null, "meta", masterSmilHeadNode.NamespaceURI); masterSmilHeadNode.AppendChild(smilTitleMetadataNode); CreateAppendXmlAttribute(smilDocument, smilTitleMetadataNode, "name", "dc:title"); CreateAppendXmlAttribute(smilDocument, smilTitleMetadataNode, "content", titleMetadata.NameContentAttribute.Value); } //AddSmilHeadElements ( smilDocument, null, m_SmilElapseTime.ToString ().Split ( '.' )[0] ); AddSmilHeadElements(smilDocument, null, GetStringTotalTimeRoundedOff(new TimeSpan(m_SmilElapseTime.AsTimeSpanTicks))); WriteXmlDocumentToFile(smilDocument, Path.Combine(m_ExportDirectory, "master.smil")); }