Ejemplo n.º 1
0
        /// <summary>
        ///		Carga los atributos
        /// </summary>
        private MLAttributesCollection LoadAttributes(XmlAttributeCollection objColXMLAttributes)
        {
            MLAttributesCollection objColAttributes = new MLAttributesCollection();

            // Carga los atributos
            if (objColXMLAttributes != null)
            {
                foreach (XmlAttribute objXMLAttribute in objColXMLAttributes)
                {
                    if (objXMLAttribute.Prefix != "xmlns")
                    {
                        MLAttribute objAttribute = objColAttributes.Add(objXMLAttribute.LocalName,
                                                                        Decode(objXMLAttribute.InnerText));

                        // Asigna los valores
                        objAttribute.Prefix = objXMLAttribute.Prefix;
                    }
                }
            }
            // Devuelve los atributos
            return(objColAttributes);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///		Convierte un atributo
 /// </summary>
 private string ConvertAttribute(MLAttribute attributeML)
 {
     return(ConvertAttribute(attributeML.Name, attributeML.Value));
 }
Ejemplo n.º 3
0
 /// <summary>
 ///		Comprueba si un atributo se corresponde con la negrita
 /// </summary>
 public bool CheckIsBold(MLAttribute attributeML)
 {
     return(attributeML.Name == TagBold);
 }
Ejemplo n.º 4
0
 /// <summary>
 ///		Comprueba si un atributo es una referencia
 /// </summary>
 public bool CheckIsHref(MLAttribute attributeML)
 {
     return(attributeML.Name == TagHref);
 }
Ejemplo n.º 5
0
 /// <summary>
 ///		Comprueba si un atributo se corresponde con la cursiva
 /// </summary>
 public bool CheckIsItalic(MLAttribute attributeML)
 {
     return(attributeML.Name == TagItalic);
 }
 /// <summary>
 ///		Convierte un atributo
 /// </summary>
 private string ConvertAttribute(MLAttribute objMLAttribute)
 {
     return(ConvertAttribute(objMLAttribute.Name, objMLAttribute.Value));
 }
 /// <summary>
 ///		Comprueba si un atributo es una referencia
 /// </summary>
 public bool CheckIsHref(MLAttribute objMLAttribute)
 {
     return(objMLAttribute.Name == cnstStrTagHref);
 }
 /// <summary>
 ///		Comprueba si un atributo se corresponde con la cursiva
 /// </summary>
 public bool CheckIsItalic(MLAttribute objMLAttribute)
 {
     return(objMLAttribute.Name == cnstStrTagItalic);
 }
 /// <summary>
 ///		Comprueba si un atributo se corresponde con la negrita
 /// </summary>
 public bool CheckIsBold(MLAttribute objMLAttribute)
 {
     return(objMLAttribute.Name == cnstStrTagBold);
 }
Ejemplo n.º 10
0
        /// <summary>
        ///		Interpreta los atributos de un nodo "id":"value","id":"value", ... ó "id":{object} ó "id":[array]
        /// </summary>
        private void ParseNodeAttributes(ParserTokenizer tokenizer, MLNode nodeMLParent)
        {
            bool end = false;

            // Obtiene los nodos
            while (!tokenizer.IsEof() && !end)
            {
                // Lee el siguiente Token, debería ser un identificador
                GetNextToken(tokenizer);
                // Comprueba que sea correcto
                if (_idActualType == TokenType.BracketClose)                         // ... es un objeto vacío
                {
                    end = true;
                }
                else if (_idActualType != TokenType.String)                         // ... no se ha encontrado el identificador
                {
                    throw new ParserException("Se esperaba el identificador del elemento");
                }
                else
                {
                    MLAttribute attributeML = new MLAttribute();

                    // Asigna el código del atributo
                    attributeML.Name = _actualToken.Lexema;
                    // Lee el siguiente token. Deberían ser dos puntos
                    GetNextToken(tokenizer);
                    // Comprueba que sea correcto
                    if (_idActualType != TokenType.Colon)
                    {
                        throw new ParserException("Se esperaban dos puntos (separador de identificador / valor)");
                    }
                    else
                    {
                        // Lee el siguiente token...
                        GetNextToken(tokenizer);
                        // Interpreta el valor
                        switch (_idActualType)
                        {
                        case TokenType.String:
                        case TokenType.True:
                        case TokenType.False:
                        case TokenType.Numeric:
                        case TokenType.Null:
                            // Asigna el valor al atributo
                            switch (_idActualType)
                            {
                            case TokenType.Null:
                                attributeML.Value = "";
                                break;

                            case TokenType.String:
                                attributeML.Value = ParseUnicode(_actualToken.Lexema);
                                break;

                            default:
                                attributeML.Value = _actualToken.Lexema;
                                break;
                            }
                            // Añade el atributo al nodo
                            nodeMLParent.Attributes.Add(attributeML);
                            break;

                        case TokenType.BracketOpen:                                                 // ... definición de objeto
                            MLNode nodeML = ParseNode(attributeML.Name, tokenizer, false);

                            // Añade el nodo como objeto
                            nodeMLParent.Nodes.Add(nodeML);
                            break;

                        case TokenType.BraceOpen:                                                 // ... definición de array
                            nodeMLParent.Nodes.Add(ParseNodesArray(attributeML.Name, tokenizer));
                            break;

                        default:
                            throw new ParserException($"Cadena desconocida. {_actualToken.Lexema}");
                        }
                    }
                    // Lee el siguiente token
                    GetNextToken(tokenizer);
                    // Si es una coma, seguir con el siguiente atributo del nodo, si es una llave de cierre, terminar
                    switch (_idActualType)
                    {
                    case TokenType.Comma:
                        // ... no hace nada, simplemente pasa a la creación del siguiente nodo
                        break;

                    case TokenType.BracketClose:
                        end = true;
                        break;

                    default:
                        throw new ParserException("Cadena desconocida. " + _actualToken.Lexema);
                    }
                }
            }
        }
Ejemplo n.º 11
0
		/// <summary>
		///		Interpreta los atributos de un nodo "id":"value","id":"value", ... ó "id":{object} ó "id":[array]
		/// </summary>
		private void ParseNodeAttributes(ParserTokenizer objTokenizer, MLNode objMLNodeParent)
		{ bool blnEnd = false;

				// Obtiene los nodos
					while (!objTokenizer.IsEof() && !blnEnd)		
						{ // Lee el siguiente Token, debería ser un identificador
								GetNextToken(objTokenizer);
							// Comprueba que sea correcto
								if (intIDActualType == TokenType.BracketClose) // ... es un objeto vacío
									blnEnd = true;
								else if (intIDActualType != TokenType.String) // ... no se ha encontrado el identificador
									throw new ParserException("Se esperaba el identificador del elemento");
								else
									{ MLAttribute objMLAttribute = new MLAttribute();

											// Asigna el código del atributo
												objMLAttribute.Name = objActualToken.Lexema;
											// Lee el siguiente token. Deberían ser dos puntos
												GetNextToken(objTokenizer);
											// Comprueba que sea correcto
												if (intIDActualType != TokenType.Colon)
													throw new ParserException("Se esperaban dos puntos (separador de identificador / valor)");
												else
													{ // Lee el siguiente token...
															GetNextToken(objTokenizer);
														// Interpreta el valor
															switch (intIDActualType)
																{ case TokenType.String:
																	case TokenType.True:
																	case TokenType.False:
																	case TokenType.Numeric:
																	case TokenType.Null:
																			// Asigna el valor al atributo
																				switch (intIDActualType)
																					{ case TokenType.Null:
																								objMLAttribute.Value = "";
																							break;
																						case TokenType.String:
																								objMLAttribute.Value = ParseUnicode(objActualToken.Lexema);
																							break;
																						default:
																								objMLAttribute.Value = objActualToken.Lexema;
																							break;
																					}
																			// Añade el atributo al nodo
																				objMLNodeParent.Attributes.Add(objMLAttribute);
																		break;
																	case TokenType.BracketOpen: // ... definición de objeto
																			MLNode objMLNode = ParseNode(objMLAttribute.Name, objTokenizer, false);

																				// Añade el nodo como objeto
																					objMLNodeParent.Nodes.Add(objMLNode);
																		break;
																	case TokenType.BraceOpen: // ... definición de array
																			objMLNodeParent.Nodes.Add(ParseNodesArray(objMLAttribute.Name, objTokenizer));
																		break;
																	default:
																		throw new ParserException("Cadena desconocida. " + objActualToken.Lexema);
																}
													}
											// Lee el siguiente token
												GetNextToken(objTokenizer);
											// Si es una coma, seguir con el siguiente atributo del nodo, si es una llave de cierre, terminar
												switch (intIDActualType)
													{ case TokenType.Comma:
																// ... no hace nada, simplemente pasa a la creación del siguiente nodo
															break;
														case TokenType.BracketClose:
																blnEnd = true;
															break;
														default:
															throw new ParserException("Cadena desconocida. " + objActualToken.Lexema);
													}
									}
						}
		}