* @param xmlStreamReader
*/
private Model parseModel(String tagName, XMLStreamReader xmlStreamReader, boolean strict, String encoding)
throws IOException, XMLStreamException
{
Model model = new Model();
model.setModelEncoding( encoding );
java.util.Set parsed = new java.util.HashSet();
boolean foundRoot = false;
while ( xmlStreamReader.hasNext() )
{
int eventType = xmlStreamReader.next();
if ( eventType == XMLStreamConstants.START_ELEMENT )
{
if ( xmlStreamReader.getLocalName().equals( tagName ) )
{
foundRoot = true;
}
else if ( xmlStreamReader.getLocalName().equals( "extend" ) )
{
if ( parsed.contains( "extend" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "extend" );
model.setExtend( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "pomVersion" ) )
{
if ( parsed.contains( "pomVersion" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "pomVersion" );
model.setPomVersion( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "groupId" ) )
{
if ( parsed.contains( "groupId" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "groupId" );
model.setGroupId( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "artifactId" ) )
{
if ( parsed.contains( "artifactId" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "artifactId" );
model.setArtifactId( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "id" ) )
{
if ( parsed.contains( "id" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "id" );
model.setId( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "name" ) )
{
if ( parsed.contains( "name" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "name" );
model.setName( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "currentVersion" ) )
{
if ( parsed.contains( "currentVersion" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "currentVersion" );
model.setCurrentVersion( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "shortDescription" ) )
{
if ( parsed.contains( "shortDescription" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "shortDescription" );
model.setShortDescription( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "description" ) )
{
if ( parsed.contains( "description" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "description" );
model.setDescription( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "url" ) )
{
if ( parsed.contains( "url" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "url" );
model.setUrl( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "logo" ) )
{
if ( parsed.contains( "logo" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "logo" );
model.setLogo( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "issueTrackingUrl" ) )
{
if ( parsed.contains( "issueTrackingUrl" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "issueTrackingUrl" );
model.setIssueTrackingUrl( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "inceptionYear" ) )
{
if ( parsed.contains( "inceptionYear" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "inceptionYear" );
model.setInceptionYear( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "gumpRepositoryId" ) )
{
if ( parsed.contains( "gumpRepositoryId" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "gumpRepositoryId" );
model.setGumpRepositoryId( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "siteAddress" ) )
{
if ( parsed.contains( "siteAddress" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "siteAddress" );
model.setSiteAddress( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "siteDirectory" ) )
{
if ( parsed.contains( "siteDirectory" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "siteDirectory" );
model.setSiteDirectory( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "distributionSite" ) )
{
if ( parsed.contains( "distributionSite" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "distributionSite" );
model.setDistributionSite( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "distributionDirectory" ) )
{
if ( parsed.contains( "distributionDirectory" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "distributionDirectory" );
model.setDistributionDirectory( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "mailingLists" ) )
{
if ( parsed.contains( "mailingLists" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "mailingLists" );
java.util.List mailingLists = new java.util.ArrayList();
model.setMailingLists( mailingLists );
while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )
{
if ( xmlStreamReader.getLocalName().equals( "mailingList" ) )
{
model.addMailingList( parseMailingList( "mailingList", xmlStreamReader, strict, encoding ) );
}
else
{
throw new XMLStreamException( "Unrecognised tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
}
}
else if ( xmlStreamReader.getLocalName().equals( "developers" ) )
{
if ( parsed.contains( "developers" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "developers" );
java.util.List developers = new java.util.ArrayList();
model.setDevelopers( developers );
while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )
{
if ( xmlStreamReader.getLocalName().equals( "developer" ) )
{
model.addDeveloper( parseDeveloper( "developer", xmlStreamReader, strict, encoding ) );
}
else
{
throw new XMLStreamException( "Unrecognised tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
}
}
else if ( xmlStreamReader.getLocalName().equals( "contributors" ) )
{
if ( parsed.contains( "contributors" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "contributors" );
java.util.List contributors = new java.util.ArrayList();
model.setContributors( contributors );
while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )
{
if ( xmlStreamReader.getLocalName().equals( "contributor" ) )
{
model.addContributor( parseContributor( "contributor", xmlStreamReader, strict, encoding ) );
}
else
{
throw new XMLStreamException( "Unrecognised tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
}
}
else if ( xmlStreamReader.getLocalName().equals( "licenses" ) )
{
if ( parsed.contains( "licenses" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "licenses" );
java.util.List licenses = new java.util.ArrayList();
model.setLicenses( licenses );
while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )
{
if ( xmlStreamReader.getLocalName().equals( "license" ) )
{
model.addLicense( parseLicense( "license", xmlStreamReader, strict, encoding ) );
}
else
{
throw new XMLStreamException( "Unrecognised tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
}
}
else if ( xmlStreamReader.getLocalName().equals( "versions" ) )
{
if ( parsed.contains( "versions" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "versions" );
java.util.List versions = new java.util.ArrayList();
model.setVersions( versions );
while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )
{
if ( xmlStreamReader.getLocalName().equals( "version" ) )
{
model.addVersion( parseVersion( "version", xmlStreamReader, strict, encoding ) );
}
else
{
throw new XMLStreamException( "Unrecognised tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
}
}
else if ( xmlStreamReader.getLocalName().equals( "branches" ) )
{
if ( parsed.contains( "branches" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "branches" );
java.util.List branches = new java.util.ArrayList();
model.setBranches( branches );
while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )
{
if ( xmlStreamReader.getLocalName().equals( "branch" ) )
{
model.addBranch( parseBranch( "branch", xmlStreamReader, strict, encoding ) );
}
else
{
throw new XMLStreamException( "Unrecognised tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
}
}
else if ( xmlStreamReader.getLocalName().equals( "packageGroups" ) )
{
if ( parsed.contains( "packageGroups" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "packageGroups" );
java.util.List packageGroups = new java.util.ArrayList();
model.setPackageGroups( packageGroups );
while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )
{
if ( xmlStreamReader.getLocalName().equals( "packageGroup" ) )
{
model.addPackageGroup( parsePackageGroup( "packageGroup", xmlStreamReader, strict, encoding ) );
}
else
{
throw new XMLStreamException( "Unrecognised tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
}
}
else if ( xmlStreamReader.getLocalName().equals( "reports" ) )
{
if ( parsed.contains( "reports" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "reports" );
java.util.List reports = new java.util.ArrayList();
model.setReports( reports );
while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )
{
if ( xmlStreamReader.getLocalName().equals( "report" ) )
{
reports.add( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else
{
throw new XMLStreamException( "Unrecognised tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
}
}
else if ( xmlStreamReader.getLocalName().equals( "repository" ) )
{
if ( parsed.contains( "repository" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "repository" );
model.setRepository( parseRepository( "repository", xmlStreamReader, strict, encoding ) );
}
else if ( xmlStreamReader.getLocalName().equals( "organization" ) || xmlStreamReader.getLocalName().equals( "organisation" ) )
{
if ( parsed.contains( "organization" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "organization" );
model.setOrganization( parseOrganization( "organization", xmlStreamReader, strict, encoding ) );
}
else if ( xmlStreamReader.getLocalName().equals( "properties" ) )
{
if ( parsed.contains( "properties" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "properties" );
while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )
{
String key = xmlStreamReader.getLocalName();
String value = xmlStreamReader.getElementText()
.trim()
;
model.addProperty( key, value );
}
}
else if ( xmlStreamReader.getLocalName().equals( "package" ) )
{
if ( parsed.contains( "package" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "package" );
model.setPackageName( getTrimmedValue( xmlStreamReader.getElementText()) );
}
else if ( xmlStreamReader.getLocalName().equals( "build" ) )
{
if ( parsed.contains( "build" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "build" );
model.setBuild( parseBuild( "build", xmlStreamReader, strict, encoding ) );
}
else if ( xmlStreamReader.getLocalName().equals( "dependencies" ) )
{
if ( parsed.contains( "dependencies" ) )
{
throw new XMLStreamException( "Duplicated tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}
parsed.add( "dependencies" );
java.util.List dependencies = new java.util.ArrayList();
model.setDependencies( dependencies );
while ( xmlStreamReader.nextTag() == XMLStreamConstants.START_ELEMENT )
{
if ( xmlStreamReader.getLocalName().equals( "dependency" ) )
{
model.addDependency( parseDependency( "dependency", xmlStreamReader, strict, encoding ) );
}
else
{
throw new XMLStreamException( "Unrecognised tag: '" + xmlStreamReader.getLocalName() + "'", xmlStreamReader.getLocation() );
}