⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waddata.java

📁 一个基于PlaceLab的室内和室外的智能导航系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
					sffe, "");		}		Hashtable mapsSection;		if((mapsSection = indexParser.getSection("Maps")) == null) {			throw new WadDataFormatException(mapsIndexKey,					WadDataFormatException.BAD_RESOURCE_ERROR, 					"No Maps Section");		}		Enumeration e = mapsSection.keys();		while(e.hasMoreElements()) {			String mapName = (String)e.nextElement();			String metaPath = mapsDirKey + (String)mapsSection.get(mapName);			ZipEntry metaEntry = wad.getEntry(metaPath);			if(metaEntry == null || metaEntry.isDirectory()) {				throw new WadDataFormatException(mapsIndexKey, metaPath,						WadDataFormatException.MISSING_RESOURCE_ERROR, metaPath + 						" doesn't exist, yet it was referenced in " +						mapsIndexKey);			}			MapBacking newMap = loadMapFromEntry(metaEntry, mapName);			maps.put(mapName, newMap);		}           	}		private void loadRegions() throws IOException, WadDataFormatException {		ZipEntry regionsIndexEntry = wad.getEntry(regionsIndexKey);		if(regionsIndexEntry == null || regionsIndexEntry.isDirectory()) {			// not an error to not have any regions in a wad			return;		}		InputStream regionsIndexStream = wad.getInputStream(regionsIndexEntry);		SectionedFileParser indexParser = null;		try {			indexParser = new SectionedFileParser(regionsIndexStream);		} catch (SectionedFileFormatException sffe) {			throw new WadDataFormatException(regionsIndexKey, WadDataFormatException.BAD_RESOURCE_ERROR,					sffe, "");		}		Hashtable regionsSection;		if((regionsSection = indexParser.getSection("Regions")) == null) {			throw new WadDataFormatException(regionsIndexKey,					WadDataFormatException.BAD_RESOURCE_ERROR, 					"No Regions Section");		}		Enumeration e = regionsSection.keys();		while(e.hasMoreElements()) {			String regionName = (String)e.nextElement();			String metaPath = regionsDirKey + (String)regionsSection.get(regionName);			ZipEntry metaEntry = wad.getEntry(metaPath);			if(metaEntry == null || metaEntry.isDirectory()) {				throw new WadDataFormatException(regionsIndexKey, metaPath,						WadDataFormatException.MISSING_RESOURCE_ERROR, metaPath + 						" doesn't exist, yet it was referenced in " +						regionsIndexKey);			}			RegionBacking newRegion = loadRegionFromEntry(metaEntry, regionName);			regions.put(regionName, newRegion);		}	}		private RegionBacking loadRegionFromEntry(ZipEntry entry, String name) 		throws IOException, WadDataFormatException {		InputStream in = wad.getInputStream(entry);		SectionedFileParser parser = null;		try {			parser = new SectionedFileParser(in);		} catch (SectionedFileFormatException sffe) {			throw new WadDataFormatException(regionsIndexKey,					entry.getName(),					WadDataFormatException.BAD_RESOURCE_ERROR,					sffe, "");		}		Hashtable regionHash;		if((regionHash = parser.getSection("Region")) == null) {			throw new WadDataFormatException(regionsIndexKey, entry.getName(),					WadDataFormatException.BAD_RESOURCE_ERROR, 					"A Region file must have a \"Region\" section");		}		// suck out the salient details		double originLat = getDoubleOrFail(regionHash, "origin_lat", regionsIndexKey, entry.getName());		double originLon = getDoubleOrFail(regionHash, "origin_lon", regionsIndexKey, entry.getName());		double upperRightLat = getDoubleOrFail(regionHash, "upper_right_lat", regionsIndexKey, entry.getName());		double upperRightLon = getDoubleOrFail(regionHash, "upper_right_lon", regionsIndexKey, entry.getName());		String text = getStringOrFail(regionHash, "text", regionsIndexKey, entry.getName());		return new RegionBacking(name, text, originLat, originLon, upperRightLat, upperRightLon);	}		private MapBacking loadMapFromEntry(ZipEntry entry, String name) 		throws IOException, WadDataFormatException {		// assume that the entry is good, since that should be checked		// before i get here		InputStream in = wad.getInputStream(entry);		SectionedFileParser parser = null;		try {			parser = new SectionedFileParser(in);		} catch (SectionedFileFormatException sffe) {			throw new WadDataFormatException(mapsIndexKey,					entry.getName(),					WadDataFormatException.BAD_RESOURCE_ERROR,					sffe, "");		}		Hashtable mapHash;		if((mapHash = parser.getSection("Map")) == null) {		    if((mapHash = parser.getSection("TigerMap")) == null) {				throw new WadDataFormatException(mapsIndexKey,						entry.getName(), 						WadDataFormatException.BAD_RESOURCE_ERROR,						"You must have either a Map section or a TigerMap section");		    } else {		        // parse as a TigerMap		        String dataPath = getStringOrFail(mapHash, "data", mapsIndexKey, entry.getName());				if(!containsResource(dataPath)) {					throw new WadDataFormatException(entry.getName(),							dataPath, WadDataFormatException.MISSING_RESOURCE_ERROR, "");				}				throw new RuntimeException("Tiger functionality has been temporarily disabled.");		        //ALM return new TigerMapBacking(name, dataPath, this);		    }		}		String imagePath = getStringOrFail(mapHash, "image", mapsIndexKey,				entry.getName());		// test that the image at least exists		if(!containsResource(imagePath)) {			throw new WadDataFormatException(entry.getName(),					imagePath, WadDataFormatException.MISSING_RESOURCE_ERROR, "");		}		String imageName = basename(imagePath);		double originLat = getDoubleOrFail(mapHash, "origin_lat", 				mapsIndexKey, entry.getName());		double originLon = getDoubleOrFail(mapHash, "origin_lon",				mapsIndexKey, entry.getName());		// the two origins scheme is preferable to the pixels_per_lat/lon		// scheme since it is easier for users		if(mapHash.containsKey("upper_right_lat")) {			double upperRightLat = getDoubleOrFail(mapHash, "upper_right_lat",				mapsIndexKey, entry.getName());			double upperRightLon = getDoubleOrFail(mapHash, "upper_right_lon",				mapsIndexKey, entry.getName());			return new BitmapMapBacking(imageName, imagePath, this, name, originLat,				originLon, upperRightLat, upperRightLon);		} else {			double pixelsPerLat = getDoubleOrFail(mapHash, "pixels_per_lat",					mapsIndexKey, entry.getName());			double pixelsPerLon = getDoubleOrFail(mapHash, "pixels_per_lon",					mapsIndexKey, entry.getName());				return new BitmapMapBacking(imageName, imagePath, this, originLat,					originLon, pixelsPerLat, pixelsPerLon, name);		}	}		private void loadPlaces() throws IOException, WadDataFormatException {		ZipEntry  placeIndexEntry = wad.getEntry(placesIndexKey);		if(placeIndexEntry == null || placeIndexEntry.isDirectory()) {			// there is no requirement that any places be defined			return;		}		InputStream indexStream = wad.getInputStream(placeIndexEntry);		SectionedFileParser indexParser = null;		try {			indexParser = new SectionedFileParser(				indexStream);		} catch (SectionedFileFormatException sffe) {			throw new WadDataFormatException(placesIndexKey,					WadDataFormatException.BAD_RESOURCE_ERROR,					sffe, "");		}		Hashtable placeSection;		if((placeSection = indexParser.getSection("Places")) == null) {			throw new WadDataFormatException(placesIndexKey,					WadDataFormatException.BAD_RESOURCE_ERROR, 					"No Places Section");		}		Enumeration e = placeSection.keys();		while(e.hasMoreElements()) {			String placeSetName = (String)e.nextElement();			String setPath = placesDirKey + placeSection.get(placeSetName);			loadPlaceSet(placeSetName, setPath);		}	}		private void loadPlaceSet(String placeSetName, String setPath) 		throws WadDataFormatException, IOException {		Hashtable placeSet = new Hashtable();		String placeFilePath = setPath;		ZipEntry placeFileEntry = wad.getEntry(placeFilePath);		if(placeFileEntry == null) {			throw new WadDataFormatException(placesIndexKey,					placeFilePath,					WadDataFormatException.MISSING_RESOURCE_ERROR, "");		}		InputStream placeFile = wad.getInputStream(placeFileEntry);		SectionedFileParser p = null;		try {			p = new SectionedFileParser(placeFile);		} catch(SectionedFileFormatException sffe) {			throw new WadDataFormatException(placesIndexKey,					placeFilePath,					WadDataFormatException.BAD_RESOURCE_ERROR,					sffe, "");		}		Hashtable setContents = p.allSections();		Enumeration e = setContents.keys();		while(e.hasMoreElements()) {			String placeName = (String)e.nextElement();			Hashtable placeHash = (Hashtable)setContents.get(placeName);			String placeType;			String placeUrl;			String placeText;			double placeLat;			double placeLon;			String placeImageName;			String placeImagePath;			placeImagePath = getStringOrFail(placeHash, "icon_file",					placesIndexKey, placeFilePath);			// test that the image at least exists			if(!containsResource(placeImagePath)) {				throw new WadDataFormatException(setPath,						placeImagePath, 						WadDataFormatException.MISSING_RESOURCE_ERROR, "");			}			placeImageName = basename(placeImagePath);			placeLat = getDoubleOrFail(placeHash, "lat", placesIndexKey,					placeFilePath);			placeLon = getDoubleOrFail(placeHash, "lon", placesIndexKey,					placeFilePath);			placeType = getStringOrBlank(placeHash, "type");			placeText = getStringOrBlank(placeHash, "text");			placeUrl = getStringOrBlank(placeHash, "url");			PlaceBacking place = new PlaceBacking(placeType,					placeName, placeUrl, placeText, placeLat, placeLon,					placeImageName, placeImagePath, this);			placeSet.put(placeName, place);		}		places.put(placeSetName, placeSet);	}		/* helpers for parsing the sectioned files */	private String getStringOrFail(Hashtable inHash, 								   String forKey,								   String referencedFrom,								   String entry) 		throws WadDataFormatException {		if(inHash.containsKey(forKey)) {			return (String)inHash.get(forKey);		} else {			throw new WadDataFormatException(referencedFrom,					entry, WadDataFormatException.BAD_RESOURCE_ERROR, forKey);		}	}	private double getDoubleOrFail(Hashtable inHash,								   String forKey,								   String referencedFrom,								   String entry) 		throws WadDataFormatException {		try {			return Double.parseDouble(getStringOrFail(inHash, forKey,						referencedFrom, entry));		} catch (NumberFormatException nfe) {			throw new WadDataFormatException(referencedFrom, entry,					WadDataFormatException.BAD_RESOURCE_ERROR, forKey);		}	}	private String getStringOrBlank(Hashtable inHash, String forKey) {		String ret;		ret = (String)inHash.get(forKey);		if(ret != null) return ret;		else return "";	}		/**	 * Returns an ImageData for the file at path in the wad	 */	public ImageData getImageData(String path) throws IOException {		ImageData data = (ImageData)imageResources.get(path);		if(data == null) {			ZipEntry e = wad.getEntry(path);			if(e != null) {				data = new ImageData(wad.getInputStream(e));				imageResources.put(path, data);			}		}		return data;	}		/* methods for dealing with the ap cache */		/**	 * Find out whether the map wad contains an ap cache or not 	 */	public boolean containsAPCache() {		return containsResource(myApCacheKey);	}		/**	 * Uses JDBMMapLoader to load the ap cache into the WifiMapper	 */	public JDBMMapper loadAPCacheIntoMapper(String dbPath) 		throws IOException, WadDataFormatException 	{		if(!containsAPCache() || (dbPath == null)) {			return null;		}		MapLoader mapLoader;		mapLoader = new MapLoader(new JDBMMapper(dbPath));		mapLoader.createNewMap();		mapLoader.loadMap(wad.getInputStream(wad.getEntry(myApCacheKey)));		return (JDBMMapper)mapLoader.getMapper();	}		/**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -