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

org.dmfs.android.xmlmagic.builder.AndroidStringObjectBuilder 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 String from XML. It's similar to {@link AndroidCharSequenceObjectBuilder}, but it will not preserve
 * {@link android.text.Spannable} elements, whereas {@link AndroidCharSequenceObjectBuilder} does.
 * 

* 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#STRING}. * * @author Marten Gajda */ public class AndroidStringObjectBuilder extends BaseAndroidObjectBuilder { public final static AndroidStringObjectBuilder INSTANCE = new AndroidStringObjectBuilder(); @Override public String update(ElementDescriptor descriptor, String object, QualifiedName attribute, String value, ParserContext context) throws XmlObjectPullParserException { return getCharSequenceAttr(attribute, value, context).toString(); } @Override public String update(ElementDescriptor descriptor, String object, String text, ParserContext context) throws XmlObjectPullParserException { if (object == null) { return format(text, context).toString(); } else { return object; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy