📄 xmlstreamparser.java
字号:
// Are we in the middle of parsing an Entity? if ( this.entity != null ) { this.warning.append ( "Found a unit while parsing an Entity.\n" ); } // Are there *multiple* units? else if ( !this.entities.isEmpty() ) { this.warning.append ( "Found a second unit. Clearing first unit.\n" ); // Restart the unit list. this.entities.removeAllElements(); } } else if ( name.equals( TEMPLATE ) ) { // Do nothing. } else if ( name.equals( ENTITY ) ) { // Are we in the middle of parsing an Entity? if ( this.entity != null ) { this.warning.append ( "Found another Entity while parsing an Entity.\n" ); } // Are we in the middle of parsing an Entity's location? else if ( this.loc != Entity.LOC_NONE ) { this.warning.append ( "Found another Entity while parsing a location.\n" ); } // Start a new entity. else { // Look for the element's attributes. String chassis = (String) attr.get( CHASSIS ); String model = (String) attr.get( MODEL ); // Did we find required attributes? if ( chassis == null || chassis.length() == 0 ) { this.warning.append ( "Could not find chassis for Entity.\n" ); } else { // Try to find the entity. MechSummary ms = null; StringBuffer key = new StringBuffer( chassis ); ms = MechSummaryCache.getInstance() .getMech( key.toString() ); if ( model != null && model.length() > 0 ) { key.append( " " ).append( model ); ms = MechSummaryCache.getInstance() .getMech( key.toString() ); // That didn't work. Try swaping model and chassis. if ( ms == null ) { key = new StringBuffer( model ); key.append( " " ).append( chassis ); ms = MechSummaryCache.getInstance() .getMech( key.toString() ); } } // We should have found the mech. if ( ms == null ) { this.warning.append ( "Could not find Entity with chassis: " ); this.warning.append( chassis ); if ( model != null && model.length() > 0 ) { this.warning.append( ", and model: " ); this.warning.append( model ); } this.warning.append( ".\n" ); } else { // Try to load the new mech. try { this.entity = new MechFileParser ( ms.getSourceFile(), ms.getEntryName() ) .getEntity(); } catch (EntityLoadingException excep) { excep.printStackTrace( System.err ); this.warning.append( "Unable to load mech: " ) .append( ms.getSourceFile() ) .append( ": " ) .append( ms.getEntryName() ) .append( ": " ) .append( excep.getMessage()); } } // End found-MechSummary } // End have-chassis } // End ready-for-new-Entity } else if ( name.equals( FLUFF ) ) { // Do nothing. } else if ( name.equals( PILOT ) ) { // Are we in the outside of an Entity? if ( this.entity == null ) { this.warning.append ( "Found a pilot outside of an Entity.\n" ); } // Are we in the middle of parsing an Entity's location? else if ( this.loc != Entity.LOC_NONE ) { this.warning.append ( "Found a pilot while parsing a location.\n" ); } // Handle the pilot. else { // Look for the element's attributes. String pilotName = (String) attr.get( NAME ); String gunnery = (String) attr.get( GUNNERY ); String piloting = (String) attr.get( PILOTING ); String hits = (String) attr.get( HITS ); String advantages = (String) attr.get( ADVS ); String autoeject = (String) attr.get ( AUTOEJECT ); // Did we find required attributes? if ( gunnery == null || gunnery.length() == 0 ) { this.warning.append ( "Could not find gunnery for pilot.\n" ); } else if ( piloting == null || piloting.length() == 0 ) { this.warning.append ( "Could not find piloting for pilot.\n" ); } else { // Try to get a good gunnery value. int gunVal = -1; try { gunVal = Integer.parseInt( gunnery ); } catch ( NumberFormatException excep ) { // Handled by the next if test. } if ( gunVal < 0 || gunVal > 7 ) { this.warning.append( "Found invalid gunnery value: " ) .append( gunnery ) .append( ".\n" ); return; } // Try to get a good piloting value. int pilotVal = -1; try { pilotVal = Integer.parseInt( piloting ); } catch ( NumberFormatException excep ) { // Handled by the next if test. } if ( pilotVal < 0 || pilotVal > 7 ) { this.warning.append( "Found invalid piloting value: " ) .append( piloting ) .append( ".\n" ); return; } // Update the entity's crew. Pilot crew = entity.getCrew(); if ( null == pilotName || pilotName.length() == 0 ) { pilotName = crew.getName(); } crew = new Pilot( pilotName, gunVal, pilotVal ); if ( (null != advantages) && (advantages.trim().length() > 0) ) { StringTokenizer st = new StringTokenizer(advantages, "::"); while (st.hasMoreTokens()) { String adv = st.nextToken(); String advName = Pilot.parseAdvantageName(adv); Object value = Pilot.parseAdvantageValue(adv); try { crew.getOptions().getOption(advName).setValue(value); } catch ( Exception e ) { this.warning.append("Error restoring advantage: ") .append( adv ) .append( ".\n" ); } } } // Was the crew wounded? if ( hits != null ) { // Try to get a good hits value. int hitVal = -1; try { hitVal = Integer.parseInt( hits ); } catch ( NumberFormatException excep ) { // Handled by the next if test. } if ( hits.equals( DEAD ) ) { crew.setDead( true ); this.warning.append( "The pilot, " ) .append( pilotName ) .append( ", is dead.\n" ); } else if ( hitVal < 0 || hitVal > 5 ) { this.warning.append( "Found invalid hits value: " ) .append( hits ) .append( ".\n" ); } else { crew.setHits( hitVal ); } } // End have-hits // Set the crew for this entity. this.entity.setCrew( crew ); if (autoeject != null) { if (autoeject.equals("true")) { ((Mech)this.entity).setAutoEject(true); } else { ((Mech)this.entity).setAutoEject(false); } } } // End have-required-fields } // End ready-for-pilot } else if ( name.equals( LOCATION ) ) { // Are we in the outside of an Entity? if ( this.entity == null ) { this.warning.append ( "Found a location outside of an Entity.\n" ); } // Are we in the middle of parsing an Entity's location? else if ( this.loc != Entity.LOC_NONE ) { this.warning.append ( "Found a location while parsing a location.\n" ); } // Handle the location. else { // Look for the element's attributes. String index = (String) attr.get( INDEX ); String destroyed = (String) attr.get( IS_DESTROYED ); // Did we find required attributes? if ( index == null || index.length() == 0 ) { this.warning.append ( "Could not find index for location.\n" ); } else { // Try to get a good index value. int indexVal = -1; try { indexVal = Integer.parseInt( index ); } catch ( NumberFormatException excep ) { // Handled by the next if test. } if ( indexVal < 0 || indexVal > 7 ) { this.warning.append( "Found invalid index value for location: " ) .append( index ) .append( ".\n" ); return; } else if ( indexVal >= entity.locations() ) { this.warning.append( "The entity, " ) .append( entity.getShortName() ) .append( " does not have a location at index: " ) .append( indexVal ) .append( ".\n" ); return; } else { // We're now parsing the indexed location. this.loc = indexVal; // Reset the ammo count. this.locAmmoCount = 0; // Is the location destroyed? this.locDestroyed = false; try { if ( destroyed != null ) { this.locDestroyed = destroyed.equals( "true" ); } } catch ( Throwable excep ) { this.warning.append( "Found invalid isDestroyed value: " ) .append( destroyed ) .append( ".\n" ); } } // End have-valid-index } // End have-required-fields
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -