상속: NSObject
        //IBSelfCompressingDataWrapper_initWithData_shouldCompress_
        public virtual id InitWithData(NSData data, bool shouldCompress)
        {
            id self = this;

            _originalData = data;

            return self;
        }
예제 #2
0
        public virtual id InitWithData(NSData data)
        {
            id self = this;

            _data = data;

            return self;
        }
예제 #3
0
        public void AppendData(NSData data)
        {
            if (data == null || data.Length == 0)
                return;

            byte[] tmpData = new byte[this.Length + data.Length];
            Buffer.BlockCopy(this.Bytes, 0, tmpData, 0, this.Bytes.Length);
            Buffer.BlockCopy(data.Bytes, 0, tmpData, this.Bytes.Length, data.Bytes.Length);

            Bytes = tmpData;
        }
예제 #4
0
 public virtual void ReplaceRangeRTFD(NSRange aRange, NSData rtfdData)
 {
     this.ReplaceCharactersInRangeRTFD(aRange, rtfdData);
 }
예제 #5
0
 public virtual void ReplaceCharactersInRangeRTFD(NSRange aRange, NSData rtfData)
 {
     NSDictionary dict = (NSDictionary)NSDictionary.Alloc().Init();
     NSAttributedString attr = (NSAttributedString)NSAttributedString.Alloc().InitWithRTFD(rtfData, ref dict);
     this.ReplaceCharactersInRange(aRange, attr);
 }
 public override id InitForReadingWithData(NSData data, ref NSError outError)
 {
     return null;
 }
 public override id InitForReadingWithData(NSData data, object dummyObject = null)
 {
     NSError outErr = null;
     return InitForReadingWithData(data, ref outErr);
 }
예제 #8
0
        // Init an instance from data in std serial format.  Serial format is the
        // same as that used by NSText's RTFDFromRange: method.  This can
        // create a tree of instances with a directory instance at the top
        public virtual id InitWithSerializedRepresentation(NSData data)
        {
            // FIXME - This should use a serializer. To get that working a helper object
            // is needed that implements the NSObjCTypeSerializationCallBack protocol.
            // We should add this later, currently the NSArchiver is used.
            // Thanks to Richard, for pointing this out.
            NSFileWrapper wrapper = (NSFileWrapper)NSUnarchiver.UnarchiveObjectWithData(data);

            //RELEASE(this);
            return wrapper;
        }
예제 #9
0
        public virtual NSString AddRegularFileWithContents(NSData data, NSString filename)
        {
            NSFileWrapper wrapper;
            GSFileWrapperDirectoryTypeCheck();

            wrapper = (NSFileWrapper)NSFileWrapper.Alloc().InitRegularFileWithContents(data);
            if (wrapper != null)
            {
                wrapper.SetPreferredFilename(filename);
                return AddFileWrapper(wrapper);
            }
            else
            {
                return null;
            }
        }
예제 #10
0
        public override bool LoadModelData(NSData data, NSDictionary context)
        {
            bool loaded = false;
            NSKeyedUnarchiver unarchiver = null;

            try
            {
                if (data != null)
                {
                    unarchiver = GSXibKeyedUnarchiver.Alloc().InitForReadingWithData(data);
                    if (unarchiver != null)
                    {
                        NSArray rootObjects;
                        IBObjectContainer objects;

                        //NSDebugLLog(@"XIB", @"Invoking unarchiver");
                        // unarchiver setObjectZone: zone];
                        rootObjects = (NSArray)unarchiver.DecodeObjectForKey(@"IBDocument.RootObjects");
                        objects = (IBObjectContainer)unarchiver.DecodeObjectForKey(@"IBDocument.Objects");
                        //NSDebugLLog(@"XIB", @"rootObjects %@", rootObjects);
                        //[self awake: rootObjects inContainer: objects withContext: context];
                        this.Awake(rootObjects, objects, context);
                        loaded = true;
                        unarchiver = null;
                    }
                    else
                    {
                        NS.Log(@"Could not instantiate Xib unarchiver.");
                    }
                }
                else
                {
                    NS.Log(@"Data passed to Xib loading method is nil.");
                }
            }
            catch (Exception ex)
            {
                NS.Log(@"Exception occured while loading model: %s",ex.Message);
            }

            if (loaded == false)
            {
                NS.Log(@"Failed to load Xib\n");
            }

            return loaded;
        }
 public virtual bool LoadModelData(NSData data, NSDictionary context)
 {
     NSException.Raise(@"NSInternalInconsistencyException", @"Abstract model loader.");
     return false;
 }
        public GSXibKeyedUnarchiver InitForReadingWithData(NSData data)
        {
            NSData theData = data;

            Objects = (NSMutableDictionary)NSMutableDictionary.Alloc().Init();

            Stack = (NSMutableArray)NSMutableArray.Alloc().Init();

            Decoded = (NSMutableDictionary)NSMutableDictionary.Alloc().Init();

            if (NSClassWrapper.IsInInterfaceBuilder == false)
            {
                theData = PreProcessXib(data);
            }

            NSXMLParser theParser = (NSXMLParser)NSXMLParser.Alloc().InitWithData(theData);
            theParser.SetDelegate(this);

            theParser.Parse();

            //_tw.Close();
            return this;
        }
        private NSData PreProcessXib(NSData data)
        {
            NSData result = data;

            string xml = System.Text.Encoding.Default.GetString(data.Bytes);
            XDocument xDoc = XDocument.Parse(xml);

            NSMutableDictionary customClassDict = new NSMutableDictionary();

            var customClassNodes = xDoc.XPathSelectElements("//dictionary[@key=\"flattenedProperties\"]/string[contains(@key,\"CustomClassName\")]", null);
            if (customClassNodes != null && customClassNodes.Count() == 1)
            {

            }
            else
            {
                var flatProps = xDoc.XPathSelectElements("//object[@key=\"flattenedProperties\"]", null);
                if (flatProps != null && flatProps.Count() == 1)
                {
                    var xmlKeys = xDoc.XPathSelectElements("//object[@key=\"flattenedProperties\"]/object[@key=\"dict.sortedKeys\"]/*", null).ToArray();
                    var xmlObjs = xDoc.XPathSelectElements("//object[@key=\"flattenedProperties\"]/object[@key=\"dict.values\"]/*", null).ToArray();

                    for (int index = 0; index < xmlKeys.Count(); index++)
                    {
                        NSString key = xmlKeys[index].Value;
                        if (key.Contains("CustomClassName"))
                        {
                            customClassDict.Add(key, (NSString)xmlObjs[index].Value);
                        }
                    }
                }
            }

            if (customClassDict.Count > 0)
            {
                foreach (var kvp in customClassDict)
                {
                    NSString keyValue = ((NSString)kvp.Key).Replace(".CustomClassName", "");
                    NSString className = (NSString)kvp.Value;
                    NSString objectRecordXpath = string.Format("//object[@class=\"IBObjectRecord\"]/int[@key=\"objectID\"][text()=\"{0}\"]/../reference", keyValue);

                    var objectRecords = xDoc.XPathSelectElements(objectRecordXpath, null).ToArray();
                    if (objectRecords != null && objectRecords.Count() > 0)
                    {
                        foreach (var record in objectRecords)
                        {
                            if (record.AttributeValueOrDefault("key", "") == "object")
                            {
                                var refId = record.AttributeValueOrDefault("ref", "");
                                var refXpath = string.Format("//object[@id=\"{0}\"]", refId);
                                var classNodes = xDoc.XPathSelectElements(refXpath, null).ToArray();
                                if (classNodes != null && classNodes.Count() > 0)
                                {
                                    Class cls = Class.NSClassFromString(className);

                                    var classNode = classNodes[0];
                                    var classAttr = classNode.Attribute("class");
                                    classAttr.Value = className;

                                    if (cls != null)
                                    {

                                    }
                                }
                            }
                        }
                    }
                }
            }

            // ...
            return result;
        }
예제 #14
0
        public NSXMLParser InitWithData(NSData aData)
        {
            _data = aData;
            if (_data == null || _data.Bytes == null)
                return null;

            _xmlSource = System.Text.Encoding.Default.GetString(_data.Bytes);

            return this;
        }
예제 #15
0
        public virtual bool ReadFromData(NSData data, NSString typeName, ref NSError outError)
        {
            if (Objc.Overridden(this.GetType(), "LoadDataRepresentation"))
            {
                outError = null;
                return this.LoadDataRepresentation(data, typeName);
            }

            NSException.Raise("NSInternalInconsistencyException", @"%@ must implement %@",
                NS.StringFromClass(NSDocument.Class), SEL.StringFromSelector(new SEL("LoadDataRepresentation")));
            return false;
        }
예제 #16
0
 public virtual bool LoadDataRepresentation(NSData data, NSString type)
 {
     NSException.Raise("NSInternalInconsistencyException", @"%@ must implement %@",
         NS.StringFromClass(NSDocument.Class), SEL.StringFromSelector(new SEL("LoadDataRepresentation")));
     return false;
 }
예제 #17
0
 public static NSInputStream InputStreamWithData(NSData data)
 {
     return (NSInputStream)Alloc().InitWithData(data);
 }
예제 #18
0
        public virtual id InitWithData(NSData data)
        {
            id self = this;

            SetupLibXml();

            if (base.Init() != null)
            {
                _reserved1 = (NSXMLParserInfo)NSXMLParserInfo.Alloc().Init();

                _reserved1.saxHandler = new LibXml.xmlSAXHandler();
                _xmlStructuredErrorFuncPtr = Marshal.GetFunctionPointerForDelegate(new LibXml.xmlStructuredErrorFunc(_StructuredErrorFunc));

                _reserved1.parserContext = IntPtr.Zero;
                _reserved1.error = null;
                _reserved1.parserFlags = 0;
                _reserved1.slowStringMap = (NSMapTable)NSMapTable.Alloc().Init();

                InitializeSAX2Callbacks();
                _reserved1.parserFlags |= 0x40;
                _reserved1.parserFlags |= 0x80;

                if (data != null)
                {
                    _reserved3 = NSInputStream.InputStreamWithData(data);
                    if (data.Length < 0x100000)
                        _reserved1.chunkSize = data.Length;
                    else
                        _reserved1.chunkSize = 0x100000 * 256;
                }
            }

            return self;
        }
예제 #19
0
 public virtual id InitWithRTFD(NSData rtfData, ref NSDictionary docAttributes)
 {
     return this;
 }
예제 #20
0
 // Init instance of regular file type
 public virtual id InitRegularFileWithContents(NSData data)
 {
     if (base.Init() != null)
     {
         _wrapperData = data;
         _wrapperType = GSFileWrapperType.GSFileWrapperRegularFileType;
     }
     return this;
 }
예제 #21
0
        public static NSData DecodeBase64(NSData source)
        {
            int length;
            int declen;
            byte[] src;
            byte[] end;
            byte[] result;
            int dstIndex = 0;
            byte[] buf = new byte[4];
            uint pos = 0;
            int pad = 0;

            if (source == null)
            {
                return null;
            }

            length = source.Length;
            if (length == 0)
            {
                return NSData.Data();
            }

            declen = ((length + 3) * 3) / 4;
            src = source.Bytes;
            //end = &src[length];

            result = new byte[declen];

            for (int i = 0; (i < length) && (Convert.ToChar(src[i]) != '\0'); )
            {
                Char c = Convert.ToChar(src[i++]);

                if (Char.IsUpper(c))
                {
                    c -= 'A';
                }
                else if (Char.IsLower(c))
                {
                    c = Convert.ToChar(c - Convert.ToInt32('a') + 26);
                }
                else if (Char.IsDigit(c))
                {
                    c = Convert.ToChar(c - Convert.ToInt32('0') + 52);
                }
                else if (c == '/')
                {
                    c = Convert.ToChar(63);
                }
                else if (c == '_')
                {
                    c = Convert.ToChar(63);	/* RFC 4648 permits '_' in URLs and filenames */
                }
                else if (c == '+')
                {
                    c = Convert.ToChar(62);
                }
                else if (c == '-')
                {
                    c = Convert.ToChar(62);	/* RFC 4648 permits '-' in URLs and filenames */
                }
                else if (c == '=')
                {
                    c = Convert.ToChar(-1);
                    pad++;
                }
                else
                {
                    c = Convert.ToChar(-1);	/* Ignore ... non-standard but more tolerant. */
                    length--;	/* Don't count this as part of the length. */
                }

                if (c >= 0)
                {
                    buf[pos++] = Convert.ToByte(c);
                    if (pos == 4)
                    {
                        pos = 0;
                        Decodebase64(result, buf, dstIndex);
                        dstIndex += 3;
                    }
                }
            }

            /* If number of bytes is not a multiple of four, treat it as if the missing
             * bytes were the '=' characters normally used for padding.
             * This is not allowed by the basic standards, but permitted in some
             * variants of 6ase64 encoding, so we should tolerate it.
             */
            if (length % 4 > 0)
            {
                pad += (4 - length % 4);
            }
            if (pos > 0)
            {
                uint i;
                byte[] tail = new byte[3];

                for (i = pos; i < 4; i++)
                {
                    buf[i] = Convert.ToByte('\0');
                }
                Decodebase64(tail, buf, 0);
                if (pad > 3)
                    pad = 3;

                for (int j = 0; j < (3 - pad); j++)
                    result[dstIndex + j] = tail[j];
                dstIndex += 3 - pad;
            }

            return NSData.Alloc().InitWithBytes(result);
        }
예제 #22
0
 public static id UnarchiveObjectWithData(NSData data)
 {
     return null;
 }
예제 #23
0
        protected virtual bool ParseData(NSData data)
        {
            bool result = false;

            if ((this._reserved1.parserFlags & 0x40) == 0)
            {

            }

            LibXml.xmlSetStructuredErrorFunc(_instancePtr, _xmlStructuredErrorFuncPtr);
            if (this._reserved1.haveDetectedEncoding == true)
            {
                result = this._HandleParseResult(LibXml.xmlParseChunk(_reserved1.parserContext, data.Bytes, data.Length, 0));
            }
            else
            {
                int bomChunkLen = (_reserved1.bomChunk != null) ? _reserved1.bomChunk.Length : 0;
                int dataLen = (data != null) ? data.Length : 0;

                if (bomChunkLen + dataLen <= 3)
                {
                    NSData chunkData = data;
                    if (_reserved1.bomChunk != null)
                    {
                        chunkData = (NSMutableData)NSMutableData.Alloc().Init();
                        ((NSMutableData)chunkData).AppendData(_reserved1.bomChunk);
                        ((NSMutableData)chunkData).AppendData(data);
                        _reserved1.bomChunk = chunkData;
                    }

                    result = true;
                }
                else
                {
                    NSData chunkData = data;
                    if (_reserved1.bomChunk != null)
                    {
                        chunkData = (NSMutableData)NSMutableData.Alloc().Init();
                        ((NSMutableData)chunkData).AppendData(_reserved1.bomChunk);
                        ((NSMutableData)chunkData).AppendData(data);
                    }

                    IntPtr saxHandlerPtr = (_delegate != null) ? _saxHandlerPtr : IntPtr.Zero;
                    _reserved1.parserContext = LibXml.xmlCreatePushParserCtxt(saxHandlerPtr, _instancePtr, chunkData.Bytes, 4, null);

                    bool shouldResolveExternals = GetShouldResolveExternalEntities();
                    int parserFlags = (shouldResolveExternals) ? (int)LibXml.XmlParserOption.XML_PARSE_DTDLOAD : 0;
                    LibXml.xmlCtxtUseOptions(_reserved1.parserContext, parserFlags);
                    _reserved1.haveDetectedEncoding = true;
                    _reserved1.bomChunk = null;

                    if (bomChunkLen + dataLen >= 5)
                    {
                        byte[] dst = new byte[data.Length - 4];
                        Buffer.BlockCopy(data.Bytes, 4, dst, 0, data.Length - 4);
                        NSData tmpData = (NSMutableData)NSMutableData.Alloc().InitWithBytes(dst);
                        ParseData(tmpData);
                    }

                    result = true;
                }
            }

            LibXml.xmlSetStructuredErrorFunc(IntPtr.Zero, IntPtr.Zero);
            return result;
        }
예제 #24
0
 public virtual id InitWithICCProfileData(NSData iccData)
 {
     id self = this;
     if (base.Init() != null)
     {
         _iccData = iccData;
         _colorSpaceModel = NSColorSpaceModel.NSUnknownColorSpaceModel;
     }
     return self;
 }