/// <summary> /// Create a new node given a QName. /// </summary> /// <param name="localName">the local part of the qname.</param> /// <param name="namespaceUri">the namespace URI of the qname.</param> /// <returns>A new node or null if the qname corresponds to no known node.</returns> public TreeNode createNode(string localName, string namespaceUri) { if (namespaceUri == DataModelFactory.NS) { if ( XukAble.GetXukName(typeof(ObiRootNode)).Match(localName) //localName == XukAble.GetXukName(typeof(ObiRootNode)).z(m_Presentation.PrettyFormat) ) { return(m_Presentation.TreeNodeFactory.Create <ObiRootNode>()); } else if ( XukAble.GetXukName(typeof(PhraseNode)).Match(localName) //localName == XukAble.GetXukName(typeof(PhraseNode)).z(m_Presentation.PrettyFormat) ) { return(m_Presentation.TreeNodeFactory.Create <PhraseNode>()); } else if ( XukAble.GetXukName(typeof(SectionNode)).Match(localName) //localName == XukAble.GetXukName(typeof(SectionNode)).z(m_Presentation.PrettyFormat) ) { return(m_Presentation.TreeNodeFactory.Create <SectionNode>()); } else if (XukAble.GetXukName(typeof(EmptyNode)).Match(localName) //localName == XukAble.GetXukName(typeof(EmptyNode)).z(m_Presentation.PrettyFormat) ) { return(m_Presentation.TreeNodeFactory.Create <EmptyNode>()); } } //base.CreateNode(localName, namespaceUri); return(m_Presentation.TreeNodeFactory.Create(localName, namespaceUri));//sdk2 }
/// <summary> /// Create a phrase node belonging to this presentation. /// </summary> public PhraseNode CreatePhraseNode() { PhraseNode node = (PhraseNode)m_ObiNodeFactory.createNode(XukAble.GetXukName(typeof(PhraseNode)).z(PrettyFormat), DataModelFactory.NS); //sdk2 :local ObiNode factory used node.AddProperty(PropertyFactory.CreateChannelsProperty()); return(node); }
private void XukInMetadata(XmlReader source, IProgressHandler handler) { if (source.IsEmptyElement) { return; } while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.NamespaceURI == XukAble.XUK_NS && XukAble.GetXukName(typeof(Metadata)).Match(source.LocalName)) { Metadata md = Presentation.MetadataFactory.CreateMetadata(); md.XukIn(source, handler); m_Metadata.Insert(m_Metadata.Count, md); } } else if (source.NodeType == XmlNodeType.EndElement) { break; } if (source.EOF) { throw new exception.XukException("Unexpectedly reached EOF"); } } }
private TypeAndQNames RegisterType(Type t) { if (!typeof(T).IsAssignableFrom(t)) { string msg = String.Format( "Only Types inheriting {0} can be registered with the factory", typeof(T).FullName); throw new MethodParameterIsWrongTypeException(msg); } if (t.IsAbstract) { string msg = String.Format( "The abstract Type {0} cannot be registered with the factory", t.FullName); throw new MethodParameterIsWrongTypeException(msg); } TypeAndQNames tq = new TypeAndQNames(); tq.QName = GetXukQualifiedName(t); tq.Type = t; tq.ClassName = t.FullName; tq.AssemblyName = t.Assembly.GetName(); tryAgain: if (t.BaseType != null && typeof(T).IsAssignableFrom(t.BaseType)) // && t.BaseType != typeof(T)) { if (t.BaseType.IsAbstract) { t = t.BaseType; goto tryAgain; } TypeAndQNames existing = typeAlreadyRegistered(t.BaseType); if (existing == null) { QualifiedName qCheck = XukAble.GetXukQualifiedName(t.BaseType); if (string.IsNullOrEmpty(qCheck.NamespaceUri) || qCheck.LocalName == null || string.IsNullOrEmpty(qCheck.LocalName.Pretty) || string.IsNullOrEmpty(qCheck.LocalName.Ugly)) { #if DEBUG Debugger.Break(); #endif t = t.BaseType; goto tryAgain; } existing = RegisterType(t.BaseType); } if (existing != null) { tq.BaseQName = new QualifiedName( new UglyPrettyName(existing.QName.LocalName.Ugly, existing.QName.LocalName.Pretty), existing.QName.NamespaceUri); } } RegisterType(tq); return(tq); }
protected override void XukInAttributes(XmlReader source) { base.XukInAttributes(source); string optionalInfo = source.GetAttribute(XukStrings.OptionalInfo); string strPreserve = source.GetAttribute(XukStrings.IsPreservedForOutputFile); bool isPreserved = strPreserve == "true" ? true : false; string path = source.GetAttribute(XukStrings.OriginalRelativePath); if (isPreserved && String.IsNullOrEmpty(path)) { throw new XukException("For preserved files, the OriginalRelativePath of an ExternalFileData cannot be null or empty !"); } string uid = XukAble.ReadXukAttribute(source, DataProvider.DataProvider_NAME); if (String.IsNullOrEmpty(uid)) { throw new XukException("The DataProvider of an ExternalFileData cannot be null or empty !"); } //if (!Presentation.DataProviderManager.IsManagerOf(uid)) //{ // throw new IsNotManagerOfException( // String.Format("DataProvider cannot be found {0}", uid)); //} DataProvider prov = Presentation.DataProviderManager.GetManagedObject(uid); InitializeWithData(prov, path, isPreserved, optionalInfo); }
private void XukInPCMFormat(XmlReader source, IProgressHandler handler) { if (!source.IsEmptyElement) { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.NamespaceURI == XukAble.XUK_NS && XukAble.GetXukName(typeof(PCMFormatInfo)).Match(source.LocalName) ) { PCMFormatInfo newInfo = new PCMFormatInfo(); newInfo.XukIn(source, handler); PCMFormat = newInfo; } else if (!source.IsEmptyElement) { source.ReadSubtree().Close(); } } else if (source.NodeType == XmlNodeType.EndElement) { break; } if (source.EOF) { throw new exception.XukException("Unexpectedly reached EOF"); } } } }
protected override void XukInAttributes(XmlReader source) { base.XukInAttributes(source); string path = source.GetAttribute(XukStrings.OriginalRelativePath); if (String.IsNullOrEmpty(path)) { throw new XukException("The OriginalRelativePath of an ImageMediaData cannot be null or empty !"); } string uid = XukAble.ReadXukAttribute(source, DataProvider.DataProvider_NAME); if (String.IsNullOrEmpty(uid)) { throw new XukException("The DataProvider of an ImageMediaData cannot be null or empty !"); } //if (!Presentation.DataProviderManager.IsManagerOf(uid)) //{ // throw new IsNotManagerOfException( // String.Format("DataProvider cannot be found {0}", uid)); //} DataProvider prov = Presentation.DataProviderManager.GetManagedObject(uid); InitializeImage(prov, path); }
protected override void XukInChild(XmlReader source, IProgressHandler handler) { bool readItem = false; if (source.NamespaceURI == XukAble.XUK_NS) { readItem = true; if (m_firstXukInAttribute && XukAble.GetXukName(typeof(MetadataAttribute)).Match(source.LocalName)) { XukInMetadataAttribute(source, handler); } else if (PrettyFormat && source.LocalName == XukStrings.MetadataOtherAttributes) { XukInMetadataOtherAttributes(source, handler); } else if (!PrettyFormat && XukAble.GetXukName(typeof(MetadataAttribute)).Match(source.LocalName)) { XukInMetadataAttribute(source, handler); } else { readItem = false; } } if (!(readItem || source.IsEmptyElement)) { source.ReadSubtree().Close(); //Read past unknown child } }
private void XukInExternalFileDataItem(XmlReader source, IProgressHandler handler) { ExternalFileData data = null; if (!source.IsEmptyElement) { string uid = XukAble.ReadXukAttribute(source, XukAble.Uid_NAME); while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { data = Presentation.ExternalFilesDataFactory.Create_SkipManagerInitialization(source.LocalName, source.NamespaceURI); if (data != null) { string uid_ = XukAble.ReadXukAttribute(source, XukAble.Uid_NAME); data.XukIn(source, handler); if (string.IsNullOrEmpty(uid_) && !string.IsNullOrEmpty(uid)) { data.Uid = uid; } if (string.IsNullOrEmpty(data.Uid)) { throw new exception.XukException( "uid attribute is missing from mExternalFileDataItem attribute"); } Presentation.ExternalFilesDataManager.AddManagedObject_NoSafetyChecks(data, data.Uid); //if (IsManagerOf(data.Uid)) //{ // if (GetManagedObject(data.Uid) != data) // { // throw new exception.XukException( // String.Format("Another ExternalFileData exists in the manager with uid {0}", data.Uid)); // } //} //else //{ // SetUidOfManagedObject(data, data.Uid); //} } } else if (source.NodeType == XmlNodeType.EndElement) { break; } if (source.EOF) { throw new exception.XukException("Unexpectedly reached EOF"); } } } }
/// <summary> /// Create a section node belonging to this presentation. /// </summary> public SectionNode CreateSectionNode() { SectionNode node = (SectionNode)m_ObiNodeFactory.createNode(XukAble.GetXukName(typeof(SectionNode)).z(PrettyFormat), DataModelFactory.NS); //sdk2 :local ObiNode factory used urakawa.property.channel.ChannelsProperty channelsProperty = PropertyFactory.CreateChannelsProperty(); node.AddProperty(channelsProperty); // Create the text media object for the label with a default label TextMedia labelMedia = MediaFactory.CreateTextMedia(); labelMedia.Text = Localizer.Message("default_section_label"); channelsProperty.SetMedia(ChannelsManager.GetOrCreateTextChannel(), labelMedia); return(node); }
/// <summary> /// Reads the <see cref="XmlAttribute"/>s from the <c><mXmlAttributes></c> child element /// </summary> /// <param name="source">The source <see cref="XmlReader"/></param> /// <param name="handler">The handler for progress</param> protected virtual void XukInXmlAttribute(XmlReader source, IProgressHandler handler) { if (source.NamespaceURI == XukAble.XUK_NS && XukAble.GetXukName(typeof(XmlAttribute)).Match(source.LocalName)) { XmlAttribute attr = new XmlAttribute(); attr.XukIn(source, handler); SetAttribute(attr); } else if (!source.IsEmptyElement) { source.ReadSubtree().Close(); } }
/// <summary> /// Reads the attributes of a XmlProperty xuk element. /// </summary> /// <param name="source">The source <see cref="XmlReader"/></param> protected override void XukInAttributes(XmlReader source) { base.XukInAttributes(source); string ln = XukAble.ReadXukAttribute(source, XukAble.LocalName_NAME); if (string.IsNullOrEmpty(ln)) { throw new exception.XukException("LocalName attribute is missing from XmlProperty element"); } string nsUri = XukAble.ReadXukAttribute(source, XukAble.NamespaceUri_NAME); SetQName(ln, nsUri == null ? "" : nsUri); }
public bool UidEquals(XukAble xukAble, string uid, int uidHash) { if (!XukAble.UsePrefixedIntUniqueHashCodes && m_UidHashCollisions.Contains(xukAble.UidHash)) { #if DEBUG Debugger.Break(); #endif //DEBUG return(xukAble.Uid == uid); } return(xukAble.UidHash == uidHash); //return (object.ReferenceEquals(xukAble.Uid, string.Intern(uid))); }
protected override void XukInChild(XmlReader source, IProgressHandler handler) { bool readItem = false; if (source.NamespaceURI == XukAble.XUK_NS) { readItem = true; if (source.LocalName == XukStrings.Metadatas) { XukInMetadata(source, handler); } else if (XukAble.GetXukName(typeof(TextMedia)).Match(source.LocalName)) { if (m_Text != null) { throw new exception.XukException("AlternateContent Text XukIn, already set !"); } m_Text = Presentation.MediaFactory.CreateTextMedia(); m_Text.XukIn(source, handler); } else if (XukAble.GetXukName(typeof(ManagedAudioMedia)).Match(source.LocalName)) { if (m_Audio != null) { throw new exception.XukException("AlternateContent Audio XukIn, already set !"); } m_Audio = Presentation.MediaFactory.CreateManagedAudioMedia(); m_Audio.XukIn(source, handler); } else if (XukAble.GetXukName(typeof(ManagedImageMedia)).Match(source.LocalName)) { if (m_Image != null) { throw new exception.XukException("AlternateContent Image XukIn, already set !"); } m_Image = Presentation.MediaFactory.CreateManagedImageMedia(); m_Image.XukIn(source, handler); } else { readItem = false; } } if (!(readItem || source.IsEmptyElement)) { source.ReadSubtree().Close(); //Read past unknown child } }
/// <summary> /// Reads the attributes of a AbstractMedia xuk element. /// </summary> /// <param name="source">The source <see cref="XmlReader"/></param> protected override void XukInAttributes(XmlReader source) { base.XukInAttributes(source); string lang = XukAble.ReadXukAttribute(source, XukAble.Language_NAME); if (lang != null) { lang = lang.Trim(); } if (lang == "") { lang = null; } Language = lang; }
private void CheckUidHashCollision(XukAble xukAble) { foreach (T obj in m_managedObjects.ContentsAs_Enumerable) { if (obj == xukAble) { continue; } if (xukAble.UidHash == obj.UidHash) { if (!m_UidHashCollisions.Contains(xukAble.UidHash)) { m_UidHashCollisions.Add(xukAble.UidHash); } return; } } }
/// <summary> /// Reads a child of a Project xuk element. /// </summary> /// <param name="source">The source <see cref="XmlReader"/></param> /// <param name="handler">The handler for progress</param> protected override void XukInChild(XmlReader source, IProgressHandler handler) { bool readItem = false; if (source.NamespaceURI == XukAble.XUK_NS) { if (XukAble.GetXukName(typeof(PresentationFactory)).Match(source.LocalName)) { PresentationFactory.XukIn(source, handler); readItem = true; } else if (source.LocalName == XukStrings.Presentations) { XukInPresentations(source, handler); readItem = true; } } if (!readItem) { base.XukInChild(source, handler); } }
/// <summary> /// Reads the attributes of a XmlAttribute xuk element. /// </summary> /// <param name="source">The source <see cref="XmlReader"/></param> protected override void XukInAttributes(XmlReader source) { base.XukInAttributes(source); string name = XukAble.ReadXukAttribute(source, XukAble.LocalName_NAME); if (string.IsNullOrEmpty(name)) { throw new exception.XukException("LocalName attribute of XmlAttribute element is missing"); } string value = XukAble.ReadXukAttribute(source, XukAble.Value_NAME); if (value == null) { throw new exception.XukException("Value attribute of XmlAttribute element is missing"); } Value = value; string ns = XukAble.ReadXukAttribute(source, XukAble.NamespaceUri_NAME); SetQName(name, ns == null ? "" : ns); }
protected virtual void XukInMetadataAttribute(XmlReader source, IProgressHandler handler) { if (source.NamespaceURI == XukAble.XUK_NS && XukAble.GetXukName(typeof(MetadataAttribute)).Match(source.LocalName)) { MetadataAttribute attr = new MetadataAttribute(); attr.XukIn(source, handler); if (m_firstXukInAttribute) { NameContentAttribute = attr; m_firstXukInAttribute = false; } else { OtherAttributes.Insert(OtherAttributes.Count, attr); } } else if (!source.IsEmptyElement) { source.ReadSubtree().Close(); } }
protected override void XukInAttributes(XmlReader source) { base.XukInAttributes(source); string name = XukAble.ReadXukAttribute(source, XukAble.Name_NAME); if (string.IsNullOrEmpty(name)) { throw new exception.XukException("Name attribute of MetadataAttribute element is missing"); } Name = name; string ns = XukAble.ReadXukAttribute(source, XukAble.NamespaceUri_NAME); NamespaceUri = ns; string value = XukAble.ReadXukAttribute(source, XukAble.Value_NAME); //if (string.IsNullOrEmpty(value)) //{ // throw new exception.XukException("Value attribute of MetadataAttribute element is missing"); //} Value = value; }
private void XukInDataProviderItem(XmlReader source, IProgressHandler handler) { if (!source.IsEmptyElement) { string uid = XukAble.ReadXukAttribute(source, XukAble.Uid_NAME); bool addedProvider = false; while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { DataProvider prov = Presentation.DataProviderFactory.Create_SkipManagerInitialization("", source.LocalName, source.NamespaceURI); if (prov != null) { if (addedProvider) { throw new exception.XukException( "Multiple DataProviders within the same mDataProviderItem is not supported"); } prov.XukIn(source, handler); //string uid_ = source.GetAttribute(XukStrings.Uid); if (string.IsNullOrEmpty(prov.Uid) && !string.IsNullOrEmpty(uid)) { prov.Uid = uid; } Presentation.DataProviderManager.AddManagedObject_NoSafetyChecks(prov, prov.Uid); //if (IsManagerOf(prov.Uid)) //{ // if (GetManagedObject(prov.Uid) != prov) // { // throw new exception.XukException( // String.Format("Another DataProvider exists in the manager with uid {0}", prov.Uid)); // } //} //else //{ // SetUidOfManagedObject(prov, prov.Uid); //} if (prov is FileDataProvider) { FileDataProvider fdProv = (FileDataProvider)prov; foreach (string path in mXukedInFilDataProviderPaths) { if (path.Equals(fdProv.DataFileRelativePath, StringComparison.OrdinalIgnoreCase)) { throw new exception.XukException(String.Format( "Another FileDataProvider using data file {0} has already been Xukked in", fdProv.DataFileRelativePath)); } } if (!File.Exists(fdProv.DataFileFullPath)) { Presentation.DataProviderManager.RemoveManagedObject(fdProv); return; } mXukedInFilDataProviderPaths.Add(fdProv.DataFileRelativePath); } addedProvider = true; } else if (!source.IsEmptyElement) { source.ReadSubtree().Close(); } } else if (source.NodeType == XmlNodeType.EndElement) { break; } if (source.EOF) { throw new exception.XukException("Unexpectedly reached EOF"); } } } }
public ObjectAddedEventArgs(XukAble source, T obj) : base(source) { m_AddedObject = obj; }
private void XukInWavClip(XmlReader source) { string clipBeginAttr = source.GetAttribute(XukStrings.ClipBegin); Time cb = Time.Zero; if (clipBeginAttr != null) { try { cb = new Time(clipBeginAttr); } catch (Exception e) { throw new exception.XukException( String.Format("Invalid clip begin time {0}", clipBeginAttr), e); } } string clipEndAttr = source.GetAttribute(XukStrings.ClipEnd); Time ce = null; if (clipEndAttr != null) { try { ce = new Time(clipEndAttr); } catch (Exception e) { throw new exception.XukException( String.Format("Invalid clip end time {0}", clipEndAttr), e); } } string dataProviderUid = XukAble.ReadXukAttribute(source, DataProvider.DataProvider_NAME); if (String.IsNullOrEmpty(dataProviderUid)) { throw new exception.XukException("dataProvider attribute is missing from WavClip element"); } //if (!Presentation.DataProviderManager.IsManagerOf(dataProviderUid)) //{ // throw new exception.IsNotManagerOfException( // String.Format("DataProvider cannot be found {0}", dataProviderUid)); //} try { DataProvider prov = Presentation.DataProviderManager.GetManagedObject(dataProviderUid); mWavClips.Add(new WavClip(prov, cb, ce)); } catch (DataMissingException ex) { // TODO: this is a temporary fix ! // Instead of ignoring the fact that the underlying audio resource is missing, // we should have a system to let the consumer of the SDK // (i.e. the host application) know about the error and decide about the processing // (i.e. abandon parsing or carry-on by ignoring the resource). // This relates to the global issue of configurable error recovery, // not only for the data attached to the XUK instance, // but also for corrupted XUK markup or values. Presentation.Project.notifyDataIsMissing(this, ex); } catch (Exception ex) //MethodParameterIsOutOfBoundsException IsNotManagerOfException { Presentation.Project.notifyDataIsMissing(this, new DataMissingException(ex.Message, ex)); } if (!source.IsEmptyElement) { source.ReadSubtree().Close(); } }
public ObjectRemovedEventArgs(XukAble source, T obj, int oldPos) : base(source) { m_RemovedObject = obj; m_RemovedObjectPosition = oldPos; }
public T GetManagedObject(string uid) { int uidHash = XukAble.GetHashCode(uid); return(GetManagedObject(uid, uidHash)); }
public ObjectListProvider(XukAble owner, bool useLock) { m_Owner = owner; m_useLock = useLock; m_objects = new List <T>(); }
public override bool PreVisit(TreeNode node) { if (m_RootNode == null) { m_RootNode = node; } if (TreeNodeMustBeSkipped(node)) { return(false); } if (TreeNodeTriggersNewAudioFile(node)) { createNextAudioFile(node); } if (node.HasProperties(typeof(ChannelsProperty))) { ChannelsProperty chProp = node.GetChannelsProperty(); ManagedAudioMedia mam = chProp.GetMedia(SourceChannel) as ManagedAudioMedia; if (mam != null) { AudioMediaData amd = mam.AudioMediaData; if (mCurrentAudioFileStream == null) { createNextAudioFile(node); } else if (mCurrentAudioFilePCMFormat != null && !mCurrentAudioFilePCMFormat.Data.IsCompatibleWith(amd.PCMFormat.Data)) { #if DEBUG Debugger.Break(); #endif createNextAudioFile(node); } if (mCurrentAudioFileStream != null && mCurrentAudioFilePCMFormat == null) { writeInitialHeader(amd.PCMFormat); } Time durationFromRiffHeader = amd.AudioDuration; Time clipBegin = new Time(mCurrentAudioFilePCMFormat.Data.ConvertBytesToTime(mCurrentAudioFileStream.Position - mCurrentAudioFileStreamRiffWaveHeaderLength)); Time clipEnd = new Time(clipBegin.AsTimeSpanTicks + durationFromRiffHeader.AsTimeSpanTicks, true); //BinaryReader rd = new BinaryReader(stream); Stream stream = amd.OpenPcmInputStream(); try { const uint BUFFER_SIZE = 1024 * 1024 * 3; // 3 MB MAX BUFFER StreamUtils.Copy(stream, 0, mCurrentAudioFileStream, BUFFER_SIZE); } finally { stream.Close(); } ExternalAudioMedia eam = node.Presentation.MediaFactory.Create <ExternalAudioMedia>(); if (eam == null) { throw new exception.FactoryCannotCreateTypeException(String.Format( "The media facotry cannot create a ExternalAudioMedia matching QName {1}:{0}", XukAble.GetXukName(typeof(ExternalAudioMedia), true) ?? typeof(ExternalAudioMedia).Name, node.Presentation.Project.GetXukNamespace())); } eam.Language = mam.Language; eam.Src = node.Presentation.RootUri.MakeRelativeUri(GetCurrentAudioFileUri()).ToString(); eam.ClipBegin = clipBegin; eam.ClipEnd = clipEnd; if (chProp.GetMedia(DestinationChannel) != null) { #if DEBUG Debugger.Break(); #endif chProp.SetMedia(DestinationChannel, null); } chProp.SetMedia(DestinationChannel, eam); } } return(true); }
private void XukInChannelItem(XmlReader source, IProgressHandler handler) { bool foundChannel = false; if (!source.IsEmptyElement) { string uid = XukAble.ReadXukAttribute(source, XukAble.Uid_NAME); while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { Channel newCh = Presentation.ChannelFactory.Create_SkipManagerInitialization(source.LocalName, source.NamespaceURI); if (newCh != null) { string uid_ = XukAble.ReadXukAttribute(source, XukAble.Uid_NAME); newCh.XukIn(source, handler); if (string.IsNullOrEmpty(uid_) && !string.IsNullOrEmpty(uid)) { newCh.Uid = uid; } if (string.IsNullOrEmpty(newCh.Uid)) { throw new exception.XukException("mChannelItem element has no uid attribute"); } Presentation.ChannelsManager.AddManagedObject_NoSafetyChecks(newCh, newCh.Uid); //if (IsManagerOf(newCh.Uid)) //{ // if (GetManagedObject(newCh.Uid) != newCh) // { // throw new exception.XukException( // String.Format("Another MediaData exists in the manager with uid {0}", newCh.Uid)); // } //} //else //{ // SetUidOfManagedObject(newCh, newCh.Uid); //} foundChannel = true; } else if (!source.IsEmptyElement) { source.ReadSubtree().Close(); } } else if (source.NodeType == XmlNodeType.EndElement) { break; } if (source.EOF) { throw new exception.XukException("Unexpectedly reached EOF"); } } } if (!foundChannel) { throw new exception.XukException("Fould no Channel inside mChannelItem"); } }