jeudi 23 juin 2016

TextConverter does not import exported TextFlow

If I import a text flow into a RichText component it does not import.

I have this RichText component:

<s:RichText id="richText59">
    <s:textFlow>
        <s:TextFlow>
            <s:p>test
            </s:p>
        </s:TextFlow>
    </s:textFlow>
</s:RichText>

If I import the TextFlow below same as in the MXML file:

<s:TextFlow xmlns:s="library://ns.adobe.com/flex/spark" >
    <s:p>test
    </s:p>
</s:TextFlow>

I get a null textFlow. If I look at the parser errors vector there is an error, "Unknown namespace".

If I change the namespace to flow then then it works. I found this code that is canceling it in TextLayoutImporter.as when calling the checkNamespace() method:

/**  @private */
override protected function parseContent(rootStory:XML):TextFlow
{
    // Capture all the top-level tags of interest that can be "bound"
    // We have to do this because the attributes are applied at the point
    // of calling something like:
    // span.charAttrs = characterAttrs;
    // At one time, we just set the variable to the parameter (in the setter),
    // but now we're copying the data into a new object. This change does
    // not allow for us to parse the bindings in any order. Hence, we
    // will process the potential bindings objects first, then the
    // TextFlow objects.
    //
    // Also note the use of "..*" below. We are using this to traverse the
    // XML structure looking for particular tags and at the same time allow for
    // any namespace. So, you might see something like <flow:TextContainer> or
    // <TextContainer> and this code will capture both cases.

    var rootName:String = rootStory.name().localName;
    var textFlowElement:XML = rootName == "TextFlow" ? rootStory : rootStory..*::TextFlow[0];
    if (!textFlowElement)
    {
        reportError(GlobalSettings.resourceStringFunction("missingTextFlow")); 
        return null;
    }
    if (!checkNamespace(textFlowElement))
        return null;

    return parseTextFlow(this, textFlowElement);
}

protected function checkNamespace(xmlToParse:XML):Boolean
{
    var elementNS:Namespace = xmlToParse.namespace();
    if (!_textFlowNamespace) // Not set yet; must be parsing the TextFlow element
    {
        // TextFlow element: allow only empty namespace and flow namespace
        if (elementNS != ns) 
        {
            reportError(GlobalSettings.resourceStringFunction("unexpectedNamespace", [elementNS.toString()]));
            return false;
        }
        _textFlowNamespace = elementNS;
    }
    // Other elements: must match the namespace of the TextFlow element
    // Specifically, can't be empty unless the TextFlow element's namespace is also empty 
    else if (elementNS != _textFlowNamespace) 
    {
        reportError(GlobalSettings.resourceStringFunction("unexpectedNamespace", [elementNS.toString()]));
        return false;
    }

    return true;
}

Aucun commentaire:

Enregistrer un commentaire