public void loadConfig(String fileName) throws Exception
	{
		lock();
		configFilename = fileName;
		ndsList = new ArrayList<NagiosDataSource>();
		unlock();

		BufferedReader in;
		try
		{
			in = new BufferedReader(new FileReader(fileName));

			String line;
			int lineNr = 0;
			try
			{
				while((line = in.readLine()) != null)
				{
					lineNr++;
					if (line.trim().length() == 0 || line.substring(0, 1).equals("#"))
						continue;

					int is = line.indexOf("=");
					if (is == -1)
						throw new Exception("Error on line " + lineNr + ": malformed line.");

					String name = line.substring(0, is).trim();
					String data = line.substring(is + 1).trim();

					boolean isTrue = data.equalsIgnoreCase("true") ? true : false;

					if (name.equals("config"))
						loadConfig(data);
					else if (name.equals("allow-all-ssl"))
						setAllowAllSSL(isTrue);
					else if (name.equals("source"))
					{
						String [] parameters = data.split(" ");
						NagiosDataSource nds = null;
						NagiosVersion nv = null;
						String type = parameters[0];
						String versionStr = parameters[1];

						if (versionStr.equals("1"))
							nv = NagiosVersion.V1;
						else if (versionStr.equals("2"))
							nv = NagiosVersion.V2;
						else if (versionStr.equals("3"))
							nv = NagiosVersion.V3;
						else
							throw new Exception("Nagios version '" + versionStr + "' not known.");

						if (type.equalsIgnoreCase("http"))
							nds = new NagiosDataSource(new URL(parameters[2]), nv, getFromArray(parameters, 3));
						else if (type.equalsIgnoreCase("http-auth"))
							nds = new NagiosDataSource(new URL(parameters[2]), parameters[3], parameters[4], nv, getFromArray(parameters, 5));
						else if (type.equalsIgnoreCase("file"))
							nds = new NagiosDataSource(parameters[2], nv, getFromArray(parameters, 3));
						else if (type.equalsIgnoreCase("tcp") || type.equalsIgnoreCase("ztcp"))
						{
							String host = parameters[2];
							int port = Integer.valueOf(parameters[3]);
							nds = new NagiosDataSource(host, port, nv, type.equalsIgnoreCase("ztcp"), getFromArray(parameters, 4));
						}
						else if (type.equalsIgnoreCase("ls"))
						{
							String host = parameters[2];
							int port = Integer.valueOf(parameters[3]);
							nds = new NagiosDataSource(host, port, getFromArray(parameters, 4));
							if (nv != NagiosVersion.V3)
								throw new Exception("LiveStatus source only accepts version 3");
						}
						else
							throw new Exception("Data source-type '" + type + "' not understood.");

						addNagiosDataSource(nds);
					}
					else if (name.equals("predict"))
						setBrainFileName(data);
					else if (name.equals("scroll-splitter") || name.equals("splitter"))
					{
						if (data.equalsIgnoreCase("none") || data.length() < 1)
							setLineScrollSplitter(null);
						else
							setLineScrollSplitter(data);
					}
					else if (name.equals("counter-position"))
						setCounterPosition(data);
					else if (name.equals("logo-position"))
						setLogoPosition(data);
					else if (name.equals("exec"))
						setExec(data);
					else if (name.equals("fullscreen"))
					{
						if (data.equalsIgnoreCase("none") || data.equalsIgnoreCase("false"))
							setFullscreen(FullScreenMode.NONE);
						else if (data.equalsIgnoreCase("undecorated") || data.equalsIgnoreCase("true"))
							setFullscreen(FullScreenMode.UNDECORATED);
						else if (data.equalsIgnoreCase("fullscreen"))
							setFullscreen(FullScreenMode.FULLSCREEN);
						else if (data.equalsIgnoreCase("allmonitors"))
							setFullscreen(FullScreenMode.ALLMONITORS);
						else
							throw new Exception("Fullscreen mode " + data + " not recognized");
					}
					else if (name.equals("use-screen") && data.equals("") == false && data.equals("null") == false)
						setUseScreen(data);
					else if (name.equals("footer"))
						setFooter(data);
					else if (name.equals("double-buffering"))
						setDoubleBuffering(isTrue);
					else if (name.equals("adapt-img"))
						setAdaptImageSize(isTrue);
					else if (name.equals("display-unknown"))
						setDisplayUnknown(isTrue);
					else if (name.equals("display-down"))
						setDisplayDown(isTrue);
					else if (name.equals("random-img"))
						setRandomWebcam(isTrue);
					else if (name.equals("no-gui"))
						setRunGui(!(isTrue));
					else if (name.equals("min-row-height"))
						setMinRowHeight(Integer.valueOf(data));
					else if (name.equals("header"))
						setHeader(data);
					else if (name.equals("host-issue"))
						setHostIssue(data);
					else if (name.equals("max-check-age"))
						setMaxCheckAge(Long.valueOf(data));
					else if (name.equals("sparkline-width"))
						setSparkLineWidth(Integer.valueOf(data));
					else if (name.equals("sparkline-graph-mode"))
					{
						if (data.equals("avg-sd"))
							setSparklineGraphMode(SparklineGraphMode.AVG_SD);
						else if (data.equals("min-max"))
							setSparklineGraphMode(SparklineGraphMode.MIN_MAX);
						else
							throw new Exception("sparkline-graph-mode " + data + " unknown");
					}
					else if (name.equals("service-issue"))
						setServiceIssue(data);
					else if (name.equals("logo"))
						setLogo(data);
					else if (name.equals("counter"))
						setCounter(isTrue);
					else if (name.equals("flexible-n-columns"))
						setFlexibleNColumns(isTrue);
					else if (name.equals("flash"))
						setFlash(isTrue);
					else if (name.equals("verbose"))
						setVerbose(isTrue);
					else if (name.equals("row-border"))
						setRowBorder(isTrue);
					else if (name.equals("anti-alias"))
						setAntiAlias(isTrue);
					else if (name.equals("draw-problems-service-split-line"))
						setDrawProblemServiceSplitLine(isTrue);
					else if (name.equals("no-problems-text-with-bg-color"))
						setNoProblemsTextBg(isTrue);
					else if (name.equals("max-quality-graphics"))
						setMaxQualityGraphics(isTrue);
					else if (name.equals("row-border-color"))
						setRowBorderColor(data);
					else if (name.equals("sound"))
						setProblemSound(data);
					else if (name.equals("proxy-host"))
						setProxyHost(data);
					else if (name.equals("proxy-port"))
						setProxyPort(Integer.valueOf(data));
					else if (name.equals("color-bg-to-state"))
						setSetBgColorToState(isTrue);
					else if (name.equals("problem-columns"))
						setNProblemCols(Integer.valueOf(data));
					else if (name.equals("web-expire-time"))
						setWebSessionExpire(Integer.valueOf(data));
					else if (name.equals("listen-port"))
						setHTTPServerListenPort(Integer.valueOf(data));
					else if (name.equals("upper-row-border-height"))
						setUpperRowBorderHeight(Integer.valueOf(data));
					else if (name.equals("listen-adapter"))
						setHTTPServerListenAdapter(data);
					else if (name.equals("latency-file"))
						setLatencyFile(data);
					else if (name.equals("bgcolor"))
						setBackgroundColor(data);
					else if (name.equals("bgcolor-fade-to"))
						setBackgroundColorFadeTo(data);
					else if (name.equals("problem-row-gradient"))
						setProblemRowGradient(data);
					else if (name.equals("reduce-textwidth"))
						setReduceTextWidth(isTrue);
					else if (name.equals("also-scheduled-downtime"))
						setAlsoScheduledDowntime(isTrue);
					else if (name.equals("header-always-bgcolor"))
						setHeaderAlwaysBGColor(isTrue);
					else if (name.equals("show-flapping"))
						setShowFlapping(isTrue);
					else if (name.equals("show-flapping-icon"))
						setShowFlappingIcon(isTrue);
					else if (name.equals("also-soft-state"))
						setAlsoSoftState(isTrue);
					else if (name.equals("also-disabled-active-checks"))
						setAlsoDisabledActiveChecks(isTrue);
					else if (name.equals("show-services-for-host-with-problems"))
						setShowServicesForHostWithProblems(isTrue);
					else if (name.equals("host-scheduled-downtime-show-services"))
						setHostScheduledDowntimeShowServices(isTrue);
					else if (name.equals("host-acknowledged-show-services"))
						setHostAcknowledgedShowServices(isTrue);
					else if (name.equals("textcolor") || name.equals("text-color"))
						setTextColor(data);
					else if (name.equals("warning-textcolor"))
						setWarningTextColor(data);
					else if (name.equals("critical-textcolor"))
						setCriticalTextColor(data);
					else if (name.equals("graph-color"))
						setGraphColor(data);

					else if (name.equals("hosts-filter-exclude"))
					{
						if (data.trim().equals("") == false)
							setHostsFilterExclude(data);
					}
					else if (name.equals("hosts-filter-include"))
					{
						if (data.trim().equals("") == false)
							setHostsFilterInclude(data);
					}
					else if (name.equals("services-filter-exclude"))
					{
						if (data.trim().equals("") == false)
							setServicesFilterExclude(data);
					}
					else if (name.equals("services-filter-include"))
					{
						if (data.trim().equals("") == false)
							setServicesFilterInclude(data);
					}

					else if (name.equals("bgcolorok"))
						setBackgroundColorOkStatus(data);
					else if (name.equals("nrows"))
						setNRows(Integer.valueOf(data));
					else if (name.equals("interval"))
						setSleepTime(Integer.valueOf(data));
					else if (name.equals("webcam-timeout"))
						setWebcamTimeout(Integer.valueOf(data));
					else if (name.equals("scrolling-header"))
						setScrollingHeader(isTrue);
					else if (name.equals("scrolling-footer"))
						setScrollingFooter(isTrue);
					else if (name.equals("scroll-pixels-per-sec"))
						setScrollingPixelsPerSecond(Integer.valueOf(data));
					else if (name.equals("transparency"))
						setTransparency(Float.valueOf(data));
					else if (name.equals("header-transparency"))
						setHeaderTransparency(Float.valueOf(data));
					else if (name.equals("image"))
						addImageUrl(data);
					else if (name.equals("cam-rows"))
						setCamRows(Integer.valueOf(data));
					else if (name.equals("cam-cols"))
						setCamCols(Integer.valueOf(data));
					else if (name.equals("prefer"))
						setPrefers(data);
					else if (name.equals("ignore-aspect-ratio"))
						setKeepAspectRatio(!(isTrue));
					else if (name.equals("sort-order"))
					{
						String field = null;
						boolean numeric = false, reverse = false;
						String [] fields = data.split(" ");
						for(int index=0; index<fields.length; index++)
						{
							if (fields[index].equals("numeric"))
								numeric = true;
							else if (fields[index].equals("reverse"))
								reverse = true;
							else
								field = fields[index];
						}
						setSortOrder(field, numeric, reverse);
					}
					else if (name.equals("always-notify"))
						setAlwaysNotify(isTrue);
					else if (name.equals("also-acknowledged"))
						setAlsoAcknowledged(isTrue);
					else if (name.equals("show-header"))
						setShowHeader(isTrue);
					else if (name.equals("scroll-if-not-fitting"))
						setScrollIfNotFit(isTrue);
					else if (name.equals("font"))
						setFontName(data);
					else if (name.equals("critical-font"))
						setCriticalFontName(data);
					else if (name.equals("warning-font"))
						setWarningFontName(data);
					else if (name.equals("warning-bg-color"))
						setWarningBgColor(data);
					else if (name.equals("critical-bg-color"))
						setCriticalBgColor(data);
					else if (name.equals("warning-bg-color-soft"))
						setWarningBgColorSoft(data);
					else if (name.equals("critical-bg-color-soft"))
						setCriticalBgColorSoft(data);
					else if (name.equals("nagios-unknown-bg-color"))
						setNagiosUnknownBgColor(data);
					else if (name.equals("disable-http-compression"))
						setAllowHTTPCompression(isTrue ? false : true);
					else if (name.equals("performance-data-filename"))
						setPerformanceDataFileName(data);
					else if (name.equals("no-problems-text"))
						setNoProblemsText(data);
					else if (name.equals("state-problems-text"))
						setStateProblemsText(data);
					else if (name.equals("host-scheduled-downtime-or-ack-show-services"))
						setHostSDOrAckShowServices(isTrue);
					else if (name.equals("no-problems-text-position"))
						setNoProblemsTextPosition(data);
					else if (name.equals("web-username"))
						setWebUsername(data);
					else if (name.equals("web-password"))
						setWebPassword(data);
					else if (name.equals("ldap-base-dn"))
						setLDAPBaseDN(data);
					else if (name.equals("ldap-url"))
						setLDAPUrl(data);
					else
						throw new Exception("Unknown parameter on line " + lineNr);
				}
			}
			catch(ArrayIndexOutOfBoundsException aioobe)
			{
				System.err.println("Please check line " + lineNr + " of configuration-file " + fileName + ": a parameter may be missing");
				System.exit(127);
			}
			catch(NumberFormatException nfeGlobal)
			{
				System.err.println("Please check line " + lineNr + " of configuration-file " + fileName + ": one of the parameters ought to be a number");
				System.exit(127);
			}

			in.close();
		}
		catch(FileNotFoundException e)
		{
			System.err.println("File " + fileName + " not found. Please use --create-config to create a new configuration file.");
			System.exit(127);
		}
	}