All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dmfs.android.xmlmagic.builder.AndroidCharSequenceObjectBuilder Maven / Gradle / Ivy

There is a newer version: 0.1.2
Show newest version
/*
 * Copyright (C) 2015 Marten Gajda 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.dmfs.android.xmlmagic.builder;

import org.dmfs.xmlobjects.ElementDescriptor;
import org.dmfs.xmlobjects.QualifiedName;
import org.dmfs.xmlobjects.pull.ParserContext;
import org.dmfs.xmlobjects.pull.XmlObjectPullParserException;


/**
 * A builder that builds a CharSequence from XML. It's similar to {@link AndroidStringObjectBuilder}, but it will preserve {@link android.text.Spannable}
 * elements, whereas {@link AndroidStringObjectBuilder} won't.
 * 

* This builder accepts the value in an attribute called value or as text value. In either case placeholder tokens will be evaluated. The attribute * version is more efficient when directly referring to a resource string. *

* Examples: * *

 * {@code
 *   
 * {{@literal @}string:some_string}  
 * 
 * 
 * Some text
 * 
 * 
 * http://{{@literal @}cursor:hostname}/
 * }
 * 
* * Note: if both, an attribute and a text value, are present, the attribute takes precedence over the text value. *

* Also note: when using the text version the text must not contain any XML or HTML elements. *

* A concrete {@link ElementDescriptor} using this builder is {@link org.dmfs.android.xmlmagic.Model#CHAR_SEQUENCE}. * * @author Marten Gajda */ public class AndroidCharSequenceObjectBuilder extends BaseAndroidObjectBuilder { public final static AndroidCharSequenceObjectBuilder INSTANCE = new AndroidCharSequenceObjectBuilder(); @Override public CharSequence update(ElementDescriptor descriptor, CharSequence object, QualifiedName attribute, String value, ParserContext context) throws XmlObjectPullParserException { return getCharSequenceAttr(attribute, value, context); } @Override public CharSequence update(ElementDescriptor descriptor, CharSequence object, String text, ParserContext context) throws XmlObjectPullParserException { if (object == null) { return format(text, context); } else { return object; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy