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

org.apache.maven.profiles.io.xpp3.ProfilesXpp3Reader Maven / Gradle / Ivy

There is a newer version: 4.0.0-rc-2
Show newest version
// =================== DO NOT EDIT THIS FILE ====================
// Generated by Modello 2.1.1,
// any modifications will be overwritten.
// ==============================================================

package org.apache.maven.profiles.io.xpp3;

  //---------------------------------/
 //- Imported classes and packages -/
//---------------------------------/

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.text.DateFormat;
import org.apache.maven.profiles.Activation;
import org.apache.maven.profiles.ActivationFile;
import org.apache.maven.profiles.ActivationOS;
import org.apache.maven.profiles.ActivationProperty;
import org.apache.maven.profiles.Profile;
import org.apache.maven.profiles.ProfilesRoot;
import org.apache.maven.profiles.Repository;
import org.apache.maven.profiles.RepositoryBase;
import org.apache.maven.profiles.RepositoryPolicy;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
import org.codehaus.plexus.util.xml.pull.MXParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParser;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

/**
 * Class ProfilesXpp3Reader.
 * 
 * @version $Revision$ $Date$
 */
@SuppressWarnings( "all" )
public class ProfilesXpp3Reader
{

      //--------------------------/
     //- Class/Member Variables -/
    //--------------------------/

    /**
     * If set the parser will be loaded with all single characters
     * from the XHTML specification.
     * The entities used:
     * 
    *
  • http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
  • *
  • http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
  • *
  • http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent
  • *
*/ private boolean addDefaultEntities = true; /** * Field contentTransformer. */ public final ContentTransformer contentTransformer; //----------------/ //- Constructors -/ //----------------/ public ProfilesXpp3Reader() { this( new ContentTransformer() { public String transform( String source, String fieldName ) { return source; } } ); } //-- org.apache.maven.profiles.io.xpp3.ProfilesXpp3Reader() public ProfilesXpp3Reader(ContentTransformer contentTransformer) { this.contentTransformer = contentTransformer; } //-- org.apache.maven.profiles.io.xpp3.ProfilesXpp3Reader(ContentTransformer) //-----------/ //- Methods -/ //-----------/ /** * Method checkFieldWithDuplicate. * * @param parser a parser object. * @param parsed a parsed object. * @param alias a alias object. * @param tagName a tagName object. * @throws XmlPullParserException XmlPullParserException if * any. * @return boolean */ private boolean checkFieldWithDuplicate( XmlPullParser parser, String tagName, String alias, java.util.Set parsed ) throws XmlPullParserException { if ( !( parser.getName().equals( tagName ) || parser.getName().equals( alias ) ) ) { return false; } if ( !parsed.add( tagName ) ) { throw new XmlPullParserException( "Duplicated tag: '" + tagName + "'", parser, null ); } return true; } //-- boolean checkFieldWithDuplicate( XmlPullParser, String, String, java.util.Set ) /** * Method checkUnknownAttribute. * * @param parser a parser object. * @param strict a strict object. * @param tagName a tagName object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @throws IOException IOException if any. */ private void checkUnknownAttribute( XmlPullParser parser, String attribute, String tagName, boolean strict ) throws XmlPullParserException, IOException { // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too if ( strict ) { throw new XmlPullParserException( "Unknown attribute '" + attribute + "' for tag '" + tagName + "'", parser, null ); } } //-- void checkUnknownAttribute( XmlPullParser, String, String, boolean ) /** * Method checkUnknownElement. * * @param parser a parser object. * @param strict a strict object. * @throws XmlPullParserException XmlPullParserException if * any. * @throws IOException IOException if any. */ private void checkUnknownElement( XmlPullParser parser, boolean strict ) throws XmlPullParserException, IOException { if ( strict ) { throw new XmlPullParserException( "Unrecognised tag: '" + parser.getName() + "'", parser, null ); } for ( int unrecognizedTagCount = 1; unrecognizedTagCount > 0; ) { int eventType = parser.next(); if ( eventType == XmlPullParser.START_TAG ) { unrecognizedTagCount++; } else if ( eventType == XmlPullParser.END_TAG ) { unrecognizedTagCount--; } } } //-- void checkUnknownElement( XmlPullParser, boolean ) /** * Returns the state of the "add default entities" flag. * * @return boolean */ public boolean getAddDefaultEntities() { return addDefaultEntities; } //-- boolean getAddDefaultEntities() /** * Method getBooleanValue. * * @param s a s object. * @param parser a parser object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return boolean */ private boolean getBooleanValue( String s, String attribute, XmlPullParser parser ) throws XmlPullParserException { return getBooleanValue( s, attribute, parser, null ); } //-- boolean getBooleanValue( String, String, XmlPullParser ) /** * Method getBooleanValue. * * @param s a s object. * @param defaultValue a defaultValue object. * @param parser a parser object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return boolean */ private boolean getBooleanValue( String s, String attribute, XmlPullParser parser, String defaultValue ) throws XmlPullParserException { if ( s != null && s.length() != 0 ) { return Boolean.valueOf( s ).booleanValue(); } if ( defaultValue != null ) { return Boolean.valueOf( defaultValue ).booleanValue(); } return false; } //-- boolean getBooleanValue( String, String, XmlPullParser, String ) /** * Method getByteValue. * * @param s a s object. * @param strict a strict object. * @param parser a parser object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return byte */ private byte getByteValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Byte.valueOf( s ).byteValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a byte", parser, nfe ); } } } return 0; } //-- byte getByteValue( String, String, XmlPullParser, boolean ) /** * Method getCharacterValue. * * @param s a s object. * @param parser a parser object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return char */ private char getCharacterValue( String s, String attribute, XmlPullParser parser ) throws XmlPullParserException { if ( s != null ) { return s.charAt( 0 ); } return 0; } //-- char getCharacterValue( String, String, XmlPullParser ) /** * Method getDateValue. * * @param s a s object. * @param parser a parser object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return Date */ private java.util.Date getDateValue( String s, String attribute, XmlPullParser parser ) throws XmlPullParserException { return getDateValue( s, attribute, null, parser ); } //-- java.util.Date getDateValue( String, String, XmlPullParser ) /** * Method getDateValue. * * @param s a s object. * @param parser a parser object. * @param dateFormat a dateFormat object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return Date */ private java.util.Date getDateValue( String s, String attribute, String dateFormat, XmlPullParser parser ) throws XmlPullParserException { if ( s != null ) { String effectiveDateFormat = dateFormat; if ( dateFormat == null ) { effectiveDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"; } if ( "long".equals( effectiveDateFormat ) ) { try { return new java.util.Date( Long.parseLong( s ) ); } catch ( NumberFormatException e ) { throw new XmlPullParserException( e.getMessage(), parser, e ); } } else { try { DateFormat dateParser = new java.text.SimpleDateFormat( effectiveDateFormat, java.util.Locale.US ); return dateParser.parse( s ); } catch ( java.text.ParseException e ) { throw new XmlPullParserException( e.getMessage(), parser, e ); } } } return null; } //-- java.util.Date getDateValue( String, String, String, XmlPullParser ) /** * Method getDoubleValue. * * @param s a s object. * @param strict a strict object. * @param parser a parser object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return double */ private double getDoubleValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Double.valueOf( s ).doubleValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe ); } } } return 0; } //-- double getDoubleValue( String, String, XmlPullParser, boolean ) /** * Method getFloatValue. * * @param s a s object. * @param strict a strict object. * @param parser a parser object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return float */ private float getFloatValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Float.valueOf( s ).floatValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a floating point number", parser, nfe ); } } } return 0; } //-- float getFloatValue( String, String, XmlPullParser, boolean ) /** * Method getIntegerValue. * * @param s a s object. * @param strict a strict object. * @param parser a parser object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return int */ private int getIntegerValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Integer.valueOf( s ).intValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be an integer", parser, nfe ); } } } return 0; } //-- int getIntegerValue( String, String, XmlPullParser, boolean ) /** * Method getLongValue. * * @param s a s object. * @param strict a strict object. * @param parser a parser object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return long */ private long getLongValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Long.valueOf( s ).longValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a long integer", parser, nfe ); } } } return 0; } //-- long getLongValue( String, String, XmlPullParser, boolean ) /** * Method getRequiredAttributeValue. * * @param s a s object. * @param strict a strict object. * @param parser a parser object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return String */ private String getRequiredAttributeValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s == null ) { if ( strict ) { throw new XmlPullParserException( "Missing required value for attribute '" + attribute + "'", parser, null ); } } return s; } //-- String getRequiredAttributeValue( String, String, XmlPullParser, boolean ) /** * Method getShortValue. * * @param s a s object. * @param strict a strict object. * @param parser a parser object. * @param attribute a attribute object. * @throws XmlPullParserException XmlPullParserException if * any. * @return short */ private short getShortValue( String s, String attribute, XmlPullParser parser, boolean strict ) throws XmlPullParserException { if ( s != null ) { try { return Short.valueOf( s ).shortValue(); } catch ( NumberFormatException nfe ) { if ( strict ) { throw new XmlPullParserException( "Unable to parse element '" + attribute + "', must be a short integer", parser, nfe ); } } } return 0; } //-- short getShortValue( String, String, XmlPullParser, boolean ) /** * Method getTrimmedValue. * * @param s a s object. * @return String */ private String getTrimmedValue( String s ) { if ( s != null ) { s = s.trim(); } return s; } //-- String getTrimmedValue( String ) /** * Method interpolatedTrimmed. * * @param value a value object. * @param context a context object. * @return String */ private String interpolatedTrimmed( String value, String context ) { return getTrimmedValue( contentTransformer.transform( value, context ) ); } //-- String interpolatedTrimmed( String, String ) /** * Method nextTag. * * @param parser a parser object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return int */ private int nextTag( XmlPullParser parser ) throws IOException, XmlPullParserException { int eventType = parser.next(); if ( eventType == XmlPullParser.TEXT ) { eventType = parser.next(); } if ( eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_TAG ) { throw new XmlPullParserException( "expected START_TAG or END_TAG not " + XmlPullParser.TYPES[eventType], parser, null ); } return eventType; } //-- int nextTag( XmlPullParser ) /** * Method read. * * @param parser a parser object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return ProfilesRoot */ public ProfilesRoot read( XmlPullParser parser, boolean strict ) throws IOException, XmlPullParserException { ProfilesRoot profilesRoot = null; int eventType = parser.getEventType(); boolean parsed = false; while ( eventType != XmlPullParser.END_DOCUMENT ) { if ( eventType == XmlPullParser.START_TAG ) { if ( strict && ! "profilesXml".equals( parser.getName() ) ) { throw new XmlPullParserException( "Expected root element 'profilesXml' but found '" + parser.getName() + "'", parser, null ); } else if ( parsed ) { // fallback, already expected a XmlPullParserException due to invalid XML throw new XmlPullParserException( "Duplicated tag: 'profilesXml'", parser, null ); } profilesRoot = parseProfilesRoot( parser, strict ); profilesRoot.setModelEncoding( parser.getInputEncoding() ); parsed = true; } eventType = parser.next(); } if ( parsed ) { return profilesRoot; } throw new XmlPullParserException( "Expected root element 'profilesXml' but found no element at all: invalid XML document", parser, null ); } //-- ProfilesRoot read( XmlPullParser, boolean ) /** * @see ReaderFactory#newXmlReader * * @param reader a reader object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return ProfilesRoot */ public ProfilesRoot read( Reader reader, boolean strict ) throws IOException, XmlPullParserException { XmlPullParser parser = addDefaultEntities ? new MXParser(EntityReplacementMap.defaultEntityReplacementMap) : new MXParser( ); parser.setInput( reader ); return read( parser, strict ); } //-- ProfilesRoot read( Reader, boolean ) /** * @see ReaderFactory#newXmlReader * * @param reader a reader object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return ProfilesRoot */ public ProfilesRoot read( Reader reader ) throws IOException, XmlPullParserException { return read( reader, true ); } //-- ProfilesRoot read( Reader ) /** * Method read. * * @param in a in object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return ProfilesRoot */ public ProfilesRoot read( InputStream in, boolean strict ) throws IOException, XmlPullParserException { return read( ReaderFactory.newXmlReader( in ), strict ); } //-- ProfilesRoot read( InputStream, boolean ) /** * Method read. * * @param in a in object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return ProfilesRoot */ public ProfilesRoot read( InputStream in ) throws IOException, XmlPullParserException { return read( ReaderFactory.newXmlReader( in ) ); } //-- ProfilesRoot read( InputStream ) /** * Method parseActivation. * * @param parser a parser object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return Activation */ private Activation parseActivation( XmlPullParser parser, boolean strict ) throws IOException, XmlPullParserException { String tagName = parser.getName(); Activation activation = new Activation(); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "activeByDefault", null, parsed ) ) { activation.setActiveByDefault( getBooleanValue( interpolatedTrimmed( parser.nextText(), "activeByDefault" ), "activeByDefault", parser, "false" ) ); } else if ( checkFieldWithDuplicate( parser, "jdk", null, parsed ) ) { activation.setJdk( interpolatedTrimmed( parser.nextText(), "jdk" ) ); } else if ( checkFieldWithDuplicate( parser, "os", null, parsed ) ) { activation.setOs( parseActivationOS( parser, strict ) ); } else if ( checkFieldWithDuplicate( parser, "property", null, parsed ) ) { activation.setProperty( parseActivationProperty( parser, strict ) ); } else if ( checkFieldWithDuplicate( parser, "file", null, parsed ) ) { activation.setFile( parseActivationFile( parser, strict ) ); } else { checkUnknownElement( parser, strict ); } } return activation; } //-- Activation parseActivation( XmlPullParser, boolean ) /** * Method parseActivationFile. * * @param parser a parser object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return ActivationFile */ private ActivationFile parseActivationFile( XmlPullParser parser, boolean strict ) throws IOException, XmlPullParserException { String tagName = parser.getName(); ActivationFile activationFile = new ActivationFile(); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "missing", null, parsed ) ) { activationFile.setMissing( interpolatedTrimmed( parser.nextText(), "missing" ) ); } else if ( checkFieldWithDuplicate( parser, "exists", null, parsed ) ) { activationFile.setExists( interpolatedTrimmed( parser.nextText(), "exists" ) ); } else { checkUnknownElement( parser, strict ); } } return activationFile; } //-- ActivationFile parseActivationFile( XmlPullParser, boolean ) /** * Method parseActivationOS. * * @param parser a parser object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return ActivationOS */ private ActivationOS parseActivationOS( XmlPullParser parser, boolean strict ) throws IOException, XmlPullParserException { String tagName = parser.getName(); ActivationOS activationOS = new ActivationOS(); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "name", null, parsed ) ) { activationOS.setName( interpolatedTrimmed( parser.nextText(), "name" ) ); } else if ( checkFieldWithDuplicate( parser, "family", null, parsed ) ) { activationOS.setFamily( interpolatedTrimmed( parser.nextText(), "family" ) ); } else if ( checkFieldWithDuplicate( parser, "arch", null, parsed ) ) { activationOS.setArch( interpolatedTrimmed( parser.nextText(), "arch" ) ); } else if ( checkFieldWithDuplicate( parser, "version", null, parsed ) ) { activationOS.setVersion( interpolatedTrimmed( parser.nextText(), "version" ) ); } else { checkUnknownElement( parser, strict ); } } return activationOS; } //-- ActivationOS parseActivationOS( XmlPullParser, boolean ) /** * Method parseActivationProperty. * * @param parser a parser object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return ActivationProperty */ private ActivationProperty parseActivationProperty( XmlPullParser parser, boolean strict ) throws IOException, XmlPullParserException { String tagName = parser.getName(); ActivationProperty activationProperty = new ActivationProperty(); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "name", null, parsed ) ) { activationProperty.setName( interpolatedTrimmed( parser.nextText(), "name" ) ); } else if ( checkFieldWithDuplicate( parser, "value", null, parsed ) ) { activationProperty.setValue( interpolatedTrimmed( parser.nextText(), "value" ) ); } else { checkUnknownElement( parser, strict ); } } return activationProperty; } //-- ActivationProperty parseActivationProperty( XmlPullParser, boolean ) /** * Method parseProfile. * * @param parser a parser object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return Profile */ private Profile parseProfile( XmlPullParser parser, boolean strict ) throws IOException, XmlPullParserException { String tagName = parser.getName(); Profile profile = new Profile(); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "id", null, parsed ) ) { profile.setId( interpolatedTrimmed( parser.nextText(), "id" ) ); } else if ( checkFieldWithDuplicate( parser, "activation", null, parsed ) ) { profile.setActivation( parseActivation( parser, strict ) ); } else if ( checkFieldWithDuplicate( parser, "properties", null, parsed ) ) { while ( parser.nextTag() == XmlPullParser.START_TAG ) { String key = parser.getName(); String value = parser.nextText().trim(); profile.addProperty( key, value ); } } else if ( checkFieldWithDuplicate( parser, "repositories", null, parsed ) ) { java.util.List repositories = new java.util.ArrayList(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "repository".equals( parser.getName() ) ) { repositories.add( parseRepository( parser, strict ) ); } else { checkUnknownElement( parser, strict ); } } profile.setRepositories( repositories ); } else if ( checkFieldWithDuplicate( parser, "pluginRepositories", null, parsed ) ) { java.util.List pluginRepositories = new java.util.ArrayList(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "pluginRepository".equals( parser.getName() ) ) { pluginRepositories.add( parseRepository( parser, strict ) ); } else { checkUnknownElement( parser, strict ); } } profile.setPluginRepositories( pluginRepositories ); } else { checkUnknownElement( parser, strict ); } } return profile; } //-- Profile parseProfile( XmlPullParser, boolean ) /** * Method parseProfilesRoot. * * @param parser a parser object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return ProfilesRoot */ private ProfilesRoot parseProfilesRoot( XmlPullParser parser, boolean strict ) throws IOException, XmlPullParserException { String tagName = parser.getName(); ProfilesRoot profilesRoot = new ProfilesRoot(); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else if ( "xmlns".equals( name ) ) { // ignore xmlns attribute in root class, which is a reserved attribute name } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "profiles", null, parsed ) ) { java.util.List profiles = new java.util.ArrayList(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "profile".equals( parser.getName() ) ) { profiles.add( parseProfile( parser, strict ) ); } else { checkUnknownElement( parser, strict ); } } profilesRoot.setProfiles( profiles ); } else if ( checkFieldWithDuplicate( parser, "activeProfiles", null, parsed ) ) { java.util.List activeProfiles = new java.util.ArrayList(); while ( parser.nextTag() == XmlPullParser.START_TAG ) { if ( "activeProfile".equals( parser.getName() ) ) { activeProfiles.add( interpolatedTrimmed( parser.nextText(), "activeProfiles" ) ); } else { checkUnknownElement( parser, strict ); } } profilesRoot.setActiveProfiles( activeProfiles ); } else { checkUnknownElement( parser, strict ); } } return profilesRoot; } //-- ProfilesRoot parseProfilesRoot( XmlPullParser, boolean ) /** * Method parseRepository. * * @param parser a parser object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return Repository */ private Repository parseRepository( XmlPullParser parser, boolean strict ) throws IOException, XmlPullParserException { String tagName = parser.getName(); Repository repository = new Repository(); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "releases", null, parsed ) ) { repository.setReleases( parseRepositoryPolicy( parser, strict ) ); } else if ( checkFieldWithDuplicate( parser, "snapshots", null, parsed ) ) { repository.setSnapshots( parseRepositoryPolicy( parser, strict ) ); } else if ( checkFieldWithDuplicate( parser, "id", null, parsed ) ) { repository.setId( interpolatedTrimmed( parser.nextText(), "id" ) ); } else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) ) { repository.setName( interpolatedTrimmed( parser.nextText(), "name" ) ); } else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) ) { repository.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) ); } else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) ) { repository.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) ); } else { checkUnknownElement( parser, strict ); } } return repository; } //-- Repository parseRepository( XmlPullParser, boolean ) /** * Method parseRepositoryBase. * * @param parser a parser object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return RepositoryBase */ private RepositoryBase parseRepositoryBase( XmlPullParser parser, boolean strict ) throws IOException, XmlPullParserException { String tagName = parser.getName(); RepositoryBase repositoryBase = new RepositoryBase(); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "id", null, parsed ) ) { repositoryBase.setId( interpolatedTrimmed( parser.nextText(), "id" ) ); } else if ( checkFieldWithDuplicate( parser, "name", null, parsed ) ) { repositoryBase.setName( interpolatedTrimmed( parser.nextText(), "name" ) ); } else if ( checkFieldWithDuplicate( parser, "url", null, parsed ) ) { repositoryBase.setUrl( interpolatedTrimmed( parser.nextText(), "url" ) ); } else if ( checkFieldWithDuplicate( parser, "layout", null, parsed ) ) { repositoryBase.setLayout( interpolatedTrimmed( parser.nextText(), "layout" ) ); } else { checkUnknownElement( parser, strict ); } } return repositoryBase; } //-- RepositoryBase parseRepositoryBase( XmlPullParser, boolean ) /** * Method parseRepositoryPolicy. * * @param parser a parser object. * @param strict a strict object. * @throws IOException IOException if any. * @throws XmlPullParserException XmlPullParserException if * any. * @return RepositoryPolicy */ private RepositoryPolicy parseRepositoryPolicy( XmlPullParser parser, boolean strict ) throws IOException, XmlPullParserException { String tagName = parser.getName(); RepositoryPolicy repositoryPolicy = new RepositoryPolicy(); for ( int i = parser.getAttributeCount() - 1; i >= 0; i-- ) { String name = parser.getAttributeName( i ); String value = parser.getAttributeValue( i ); if ( name.indexOf( ':' ) >= 0 ) { // just ignore attributes with non-default namespace (for example: xmlns:xsi) } else { checkUnknownAttribute( parser, name, tagName, strict ); } } java.util.Set parsed = new java.util.HashSet(); while ( ( strict ? parser.nextTag() : nextTag( parser ) ) == XmlPullParser.START_TAG ) { if ( checkFieldWithDuplicate( parser, "enabled", null, parsed ) ) { repositoryPolicy.setEnabled( getBooleanValue( interpolatedTrimmed( parser.nextText(), "enabled" ), "enabled", parser, "true" ) ); } else if ( checkFieldWithDuplicate( parser, "updatePolicy", null, parsed ) ) { repositoryPolicy.setUpdatePolicy( interpolatedTrimmed( parser.nextText(), "updatePolicy" ) ); } else if ( checkFieldWithDuplicate( parser, "checksumPolicy", null, parsed ) ) { repositoryPolicy.setChecksumPolicy( interpolatedTrimmed( parser.nextText(), "checksumPolicy" ) ); } else { checkUnknownElement( parser, strict ); } } return repositoryPolicy; } //-- RepositoryPolicy parseRepositoryPolicy( XmlPullParser, boolean ) /** * Sets the state of the "add default entities" flag. * * @param addDefaultEntities a addDefaultEntities object. */ public void setAddDefaultEntities( boolean addDefaultEntities ) { this.addDefaultEntities = addDefaultEntities; } //-- void setAddDefaultEntities( boolean ) public static interface ContentTransformer { /** * Interpolate the value read from the xpp3 document * @param source The source value * @param fieldName A description of the field being interpolated. The implementation may use this to * log stuff. * @return The interpolated value. */ String transform( String source, String fieldName ); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy