RCP 嵌入Google map(rcp执行JavaScrit方法,解决打包后路径问题)

@Override
	protected void createViewPartControl(final Composite parent) {
		MozillaHelper.definedContributedXulRunner(null);
		browser = new Browser(parent, SWT.NONE | SWT.MOZILLA);
		String locFile = writeMapFile();
		if (locFile == null) return;
		url = locFile.replaceAll("/", "\\\\");
		browser.addProgressListener(new ProgressListener(){
			@Override
			public void changed(ProgressEvent event) {
				
			}

			@Override
			public void completed(ProgressEvent event) {
				
				if(getCompanyAddress() != null || !"".equals(getCompanyAddress())){
					String address = formatAddress(getCompanyAddress());
					boolean result = browser.execute("createAddressMarker('" + address + "')");

					if (!result) {
						//Script may fail or may not be supported on certain platforms.
						System.out.println("Script was not executed.");
					}
				}
			}
		});
		browser.setUrl(url);
	}

private String writeMapFile() {
		try {
			Properties props = System.getProperties();
			String tmpPath = props.getProperty(TMP_FILE);
			File tempFile = new File(tmpPath + "/map.html");
			String tempFilePath = tempFile.getAbsolutePath();
			if (! tempFile.exists()) {
				BufferedReader reader = new BufferedReader(
						new InputStreamReader(Activator.getURL(MAP_FILE).openStream()));
				BufferedWriter writer = new BufferedWriter(new FileWriter(tempFilePath));
				String data = null;
				while((data = reader.readLine())!=null)
				{
					writer.write(data);
					writer.write("\n");
				}
				reader.close();
				writer.close();
			}
			return tempFilePath;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

你可能感兴趣的:(html,Google)