List of usage examples for javax.xml.parsers DocumentBuilder setErrorHandler
public abstract void setErrorHandler(ErrorHandler eh);
From source file:net.sourceforge.eclipsetrader.core.internal.XMLRepository.java
public IntradayHistory loadIntradayHistory(Integer id) { IntradayHistory barData = new IntradayHistory(id); File file = new File(Platform.getLocation().toFile(), "intraday/" + String.valueOf(id) + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ if (file.exists() == true) { try {// ww w .j a v a 2 s. c om DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.parse(file); barData.addAll(decodeBarData(document.getFirstChild().getChildNodes())); } catch (Exception e) { log.error(e.toString(), e); } } barData.clearChanged(); return barData; }
From source file:net.sourceforge.eclipsetrader.core.internal.XMLRepository.java
private void saveHistory(History list) { try {//from w w w .j a v a2 s . c om DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.getDOMImplementation().createDocument(null, "history", null); //$NON-NLS-1$ Element root = document.getDocumentElement(); encodeBarData(list.getList(), root, document); if (list instanceof IntradayHistory) saveDocument(document, "intraday", String.valueOf(list.getId()) + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ else saveDocument(document, "history", String.valueOf(list.getId()) + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (Exception e) { log.error(e.toString(), e); } }
From source file:net.sourceforge.eclipsetrader.core.internal.XMLRepository.java
private void saveCharts() { try {/* ww w . j av a 2 s. com*/ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.getDOMImplementation().createDocument(null, "data", null); //$NON-NLS-1$ Element root = document.getDocumentElement(); root.setAttribute("nextId", String.valueOf(chartsNextId)); //$NON-NLS-1$ for (Iterator iter = chartsMap.values().iterator(); iter.hasNext();) { Chart chart = (Chart) iter.next(); saveChart(chart, root, document); } saveDocument(document, "", "charts.xml"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (Exception e) { log.error(e.toString(), e); } }
From source file:net.sourceforge.eclipsetrader.core.internal.XMLRepository.java
private void saveSecurities() { try {/* ww w . j a v a2 s . c o m*/ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.getDOMImplementation().createDocument(null, "data", null); //$NON-NLS-1$ Element root = document.getDocumentElement(); root.setAttribute("nextId", String.valueOf(securitiesNextId)); //$NON-NLS-1$ root.setAttribute("nextGroupId", String.valueOf(securitiesGroupNextId)); //$NON-NLS-1$ for (Iterator iter = allSecurityGroups().iterator(); iter.hasNext();) { SecurityGroup group = (SecurityGroup) iter.next(); if (group.getParentGroup() == null) saveSecurityGroup(group, document, root); } for (Iterator iter = allSecurities().iterator(); iter.hasNext();) { Security security = (Security) iter.next(); if (security.getGroup() == null) saveSecurity(security, document, root); } saveDocument(document, "", "securities.xml"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (Exception e) { log.error(e.toString(), e); } }
From source file:net.sourceforge.eclipsetrader.core.internal.XMLRepository.java
private void saveAccounts() { try {//from w ww . ja v a2s .c o m DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.getDOMImplementation().createDocument(null, "data", null); //$NON-NLS-1$ Element root = document.getDocumentElement(); root.setAttribute("nextId", String.valueOf(accountNextId)); //$NON-NLS-1$ root.setAttribute("nextGroupId", String.valueOf(accountGroupNextId)); //$NON-NLS-1$ for (Iterator iter = accountGroupMap.values().iterator(); iter.hasNext();) { AccountGroup group = (AccountGroup) iter.next(); if (group.getParent() != null) continue; saveGroup(group, document, root); } for (Iterator iter = accountMap.values().iterator(); iter.hasNext();) { Account account = (Account) iter.next(); if (account.getGroup() != null) continue; saveAccount(account, document, root); } saveDocument(document, "", "accounts.xml"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (Exception e) { log.error(e.toString(), e); } }
From source file:net.sourceforge.eclipsetrader.core.internal.XMLRepository.java
private void saveEvents() { try {// w w w .ja v a2 s.c om DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.getDOMImplementation().createDocument(null, "data", null); //$NON-NLS-1$ Element root = document.getDocumentElement(); for (Iterator iter = allEvents().iterator(); iter.hasNext();) { Event event = (Event) iter.next(); Element element = document.createElement("event"); //$NON-NLS-1$ if (event.getSecurity() != null) element.setAttribute("security", String.valueOf(event.getSecurity().getId())); //$NON-NLS-1$ root.appendChild(element); Element node = document.createElement("date"); //$NON-NLS-1$ node.appendChild(document.createTextNode(dateTimeFormat.format(event.getDate()))); element.appendChild(node); node = document.createElement("message"); //$NON-NLS-1$ node.appendChild(document.createTextNode(event.getMessage())); element.appendChild(node); node = document.createElement("longMessage"); //$NON-NLS-1$ node.appendChild(document.createTextNode(event.getLongMessage())); element.appendChild(node); } saveDocument(document, "", "events.xml"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (Exception e) { log.error(e.toString(), e); } }
From source file:net.sourceforge.eclipsetrader.core.internal.XMLRepository.java
private void saveNews() { try {// www . ja v a 2s. co m DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.getDOMImplementation().createDocument(null, "data", null); //$NON-NLS-1$ Element root = document.getDocumentElement(); for (Iterator iter = allNews().iterator(); iter.hasNext();) { NewsItem news = (NewsItem) iter.next(); Element element = document.createElement("news"); //$NON-NLS-1$ element.setAttribute("readed", String.valueOf(news.isReaded())); //$NON-NLS-1$ root.appendChild(element); Element node = document.createElement("date"); //$NON-NLS-1$ node.appendChild(document.createTextNode(dateTimeFormat.format(news.getDate()))); element.appendChild(node); node = document.createElement("description"); //$NON-NLS-1$ node.appendChild(document.createTextNode(news.getTitle())); element.appendChild(node); node = document.createElement("source"); //$NON-NLS-1$ node.appendChild(document.createTextNode(news.getSource())); element.appendChild(node); node = document.createElement("url"); //$NON-NLS-1$ node.appendChild(document.createTextNode(news.getUrl())); element.appendChild(node); Object[] o = news.getSecurities().toArray(); for (int i = 0; i < o.length; i++) { node = document.createElement("security"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(((Security) o[i]).getId()))); element.appendChild(node); } } saveDocument(document, "", "news.xml"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (Exception e) { log.error(e.toString(), e); } }
From source file:net.sourceforge.eclipsetrader.core.internal.XMLRepository.java
private void saveOrders() { try {/* w ww .j a va 2 s . com*/ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.getDOMImplementation().createDocument(null, "data", null); //$NON-NLS-1$ Element root = document.getDocumentElement(); root.setAttribute("nextId", String.valueOf(orderNextId)); //$NON-NLS-1$ for (Iterator iter = allOrders().iterator(); iter.hasNext();) { Order order = (Order) iter.next(); Element element = document.createElement("order"); //$NON-NLS-1$ element.setAttribute("id", String.valueOf(order.getId())); //$NON-NLS-1$ element.setAttribute("pluginId", order.getPluginId()); //$NON-NLS-1$ element.setAttribute("security", String.valueOf(order.getSecurity().getId())); //$NON-NLS-1$ root.appendChild(element); Element node = document.createElement("date"); //$NON-NLS-1$ node.appendChild(document.createTextNode(dateTimeFormat.format(order.getDate()))); element.appendChild(node); if (order.getExchange() != null) { node = document.createElement("exchange"); //$NON-NLS-1$ node.setAttribute("id", order.getExchange().getId()); //$NON-NLS-1$ node.appendChild(document.createTextNode(order.getExchange().toString())); element.appendChild(node); } node = document.createElement("orderId"); //$NON-NLS-1$ node.appendChild(document.createTextNode(order.getOrderId())); element.appendChild(node); node = document.createElement("side"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(order.getSide()))); element.appendChild(node); node = document.createElement("type"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(order.getType()))); element.appendChild(node); node = document.createElement("quantity"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(order.getQuantity()))); element.appendChild(node); node = document.createElement("price"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(order.getPrice()))); element.appendChild(node); node = document.createElement("stopPrice"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(order.getStopPrice()))); element.appendChild(node); node = document.createElement("filledQuantity"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(order.getFilledQuantity()))); element.appendChild(node); node = document.createElement("averagePrice"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(order.getAveragePrice()))); element.appendChild(node); if (order.getValidity() != null) { node = document.createElement("validity"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(order.getValidity()))); element.appendChild(node); } node = document.createElement("status"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(order.getStatus()))); element.appendChild(node); if (order.getAccount() != null) { node = document.createElement("account"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(order.getAccount().getId()))); element.appendChild(node); } if (order.getText() != null) { node = document.createElement("text"); //$NON-NLS-1$ node.appendChild(document.createTextNode(order.getText())); element.appendChild(node); } if (order.getMessage() != null) { node = document.createElement("message"); //$NON-NLS-1$ node.appendChild(document.createTextNode(order.getMessage())); element.appendChild(node); } for (Iterator paramIter = order.getParams().keySet().iterator(); paramIter.hasNext();) { String key = (String) paramIter.next(); node = document.createElement("param"); //$NON-NLS-1$ node.setAttribute("key", key); //$NON-NLS-1$ node.setAttribute("value", (String) order.getParams().get(key)); //$NON-NLS-1$ element.appendChild(node); } } saveDocument(document, "", "orders.xml"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (Exception e) { log.error(e.toString(), e); } }
From source file:net.sourceforge.eclipsetrader.core.internal.XMLRepository.java
private void saveWatchlists() { try {// w w w . ja va 2s . c om DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.getDOMImplementation().createDocument(null, "data", null); //$NON-NLS-1$ Element root = document.getDocumentElement(); root.setAttribute("nextId", String.valueOf(watchlistsNextId)); //$NON-NLS-1$ for (Iterator iter = watchlistsMap.values().iterator(); iter.hasNext();) { Watchlist watchlist = (Watchlist) iter.next(); Element element = document.createElement("watchlist"); //$NON-NLS-1$ element.setAttribute("id", String.valueOf(watchlist.getId())); //$NON-NLS-1$ root.appendChild(element); Element node = document.createElement("title"); //$NON-NLS-1$ node.appendChild(document.createTextNode(watchlist.getDescription())); element.appendChild(node); node = document.createElement("style"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(watchlist.getStyle()))); element.appendChild(node); if (watchlist.getCurrency() != null) { node = document.createElement("currency"); //$NON-NLS-1$ node.appendChild(document.createTextNode(watchlist.getCurrency().getCurrencyCode())); element.appendChild(node); } if (watchlist.getDefaultFeed() != null) { node = document.createElement("feed"); //$NON-NLS-1$ node.appendChild(document.createTextNode(watchlist.getDefaultFeed())); element.appendChild(node); } Element columnsNode = document.createElement("columns"); //$NON-NLS-1$ element.appendChild(columnsNode); for (Iterator iter2 = watchlist.getColumns().iterator(); iter2.hasNext();) { WatchlistColumn column = (WatchlistColumn) iter2.next(); Element columnNode = document.createElement("column"); //$NON-NLS-1$ columnNode.setAttribute("id", column.getId()); //$NON-NLS-1$ columnsNode.appendChild(columnNode); } Element itemsNode = document.createElement("items"); //$NON-NLS-1$ element.appendChild(itemsNode); int itemIndex = 1; for (Iterator itemIter = watchlist.getItems().iterator(); itemIter.hasNext();) { WatchlistItem item = (WatchlistItem) itemIter.next(); item.setId(new Integer(itemIndex++)); item.setParent(watchlist); item.setRepository(this); Element itemNode = document.createElement("security"); //$NON-NLS-1$ itemNode.setAttribute("id", String.valueOf(item.getSecurity().getId())); //$NON-NLS-1$ itemsNode.appendChild(itemNode); if (item.getPosition() != null && item.getPosition().intValue() != 0) { node = document.createElement("position"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(item.getPosition()))); itemNode.appendChild(node); } if (item.getPaidPrice() != null && item.getPaidPrice().doubleValue() != 0) { node = document.createElement("paid"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(item.getPaidPrice()))); itemNode.appendChild(node); } int alertIndex = 1; for (Iterator alertIter = item.getAlerts().iterator(); alertIter.hasNext();) { Alert alert = (Alert) alertIter.next(); alert.setId(new Integer(alertIndex++)); Element alertNode = document.createElement("alert"); //$NON-NLS-1$ alertNode.setAttribute("pluginId", alert.getPluginId()); //$NON-NLS-1$ if (alert.getLastSeen() != null) alertNode.setAttribute("lastSeen", dateTimeFormat.format(alert.getLastSeen())); //$NON-NLS-1$ alertNode.setAttribute("popup", String.valueOf(alert.isPopup())); //$NON-NLS-1$ alertNode.setAttribute("hilight", String.valueOf(alert.isHilight())); //$NON-NLS-1$ itemNode.appendChild(alertNode); for (Iterator paramIter = alert.getParameters().keySet().iterator(); paramIter.hasNext();) { String key = (String) paramIter.next(); node = document.createElement("param"); //$NON-NLS-1$ node.setAttribute("key", key); //$NON-NLS-1$ node.appendChild(document.createTextNode((String) alert.getParameters().get(key))); alertNode.appendChild(node); } } } } saveDocument(document, "", "watchlists.xml"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (Exception e) { log.error(e.toString(), e); } }
From source file:net.sourceforge.eclipsetrader.core.internal.XMLRepository.java
private Chart loadChart(Integer id) { Chart chart = new Chart(id); chart.setRepository(this); chart.setSecurity((Security) load(Security.class, id)); File file = new File(Platform.getLocation().toFile(), "charts/" + String.valueOf(id) + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ if (file.exists() == false) file = new File(Platform.getLocation().toFile(), "charts/default.xml"); //$NON-NLS-1$ if (file.exists() == true) { try {//from w w w. j a v a 2 s.co m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(errorHandler); Document document = builder.parse(file); NodeList firstNode = document.getFirstChild().getChildNodes(); for (int r = 0; r < firstNode.getLength(); r++) { Node item = firstNode.item(r); Node valueNode = item.getFirstChild(); String nodeName = item.getNodeName(); if (valueNode != null) { if (nodeName.equalsIgnoreCase("compression") == true) //$NON-NLS-1$ chart.setCompression(Integer.parseInt(valueNode.getNodeValue())); else if (nodeName.equalsIgnoreCase("period") == true) //$NON-NLS-1$ chart.setPeriod(Integer.parseInt(valueNode.getNodeValue())); else if (nodeName.equalsIgnoreCase("autoScale") == true) //$NON-NLS-1$ chart.setAutoScale(new Boolean(valueNode.getNodeValue()).booleanValue()); else if (nodeName.equalsIgnoreCase("begin") == true) //$NON-NLS-1$ { try { chart.setBeginDate(dateTimeFormat.parse(valueNode.getNodeValue())); } catch (Exception e) { log.warn(e.toString()); } } else if (nodeName.equalsIgnoreCase("end") == true) //$NON-NLS-1$ { try { chart.setEndDate(dateTimeFormat.parse(valueNode.getNodeValue())); } catch (Exception e) { log.warn(e.toString()); } } } if (nodeName.equalsIgnoreCase("row")) //$NON-NLS-1$ { ChartRow row = new ChartRow(new Integer(r)); row.setRepository(this); row.setParent(chart); NodeList tabList = item.getChildNodes(); for (int t = 0; t < tabList.getLength(); t++) { item = tabList.item(t); nodeName = item.getNodeName(); if (nodeName.equalsIgnoreCase("tab")) //$NON-NLS-1$ { ChartTab tab = new ChartTab(new Integer(t)); tab.setRepository(this); tab.setParent(row); tab.setLabel(((Node) item).getAttributes().getNamedItem("label").getNodeValue()); //$NON-NLS-1$ NodeList indicatorList = item.getChildNodes(); for (int i = 0; i < indicatorList.getLength(); i++) { item = indicatorList.item(i); nodeName = item.getNodeName(); if (nodeName.equalsIgnoreCase("indicator")) //$NON-NLS-1$ { ChartIndicator indicator = new ChartIndicator(new Integer(i)); indicator.setRepository(this); indicator.setParent(tab); indicator.setPluginId(((Node) item).getAttributes().getNamedItem("pluginId") //$NON-NLS-1$ .getNodeValue()); NodeList parametersList = item.getChildNodes(); for (int p = 0; p < parametersList.getLength(); p++) { item = parametersList.item(p); nodeName = item.getNodeName(); if (nodeName.equalsIgnoreCase("param")) //$NON-NLS-1$ { String key = ((Node) item).getAttributes().getNamedItem("key") //$NON-NLS-1$ .getNodeValue(); String value = ((Node) item).getAttributes().getNamedItem("value") //$NON-NLS-1$ .getNodeValue(); indicator.getParameters().put(key, value); } } tab.getIndicators().add(indicator); } else if (nodeName.equalsIgnoreCase("object")) //$NON-NLS-1$ { ChartObject object = new ChartObject(new Integer(i)); object.setRepository(this); object.setParent(tab); object.setPluginId(((Node) item).getAttributes().getNamedItem("pluginId") //$NON-NLS-1$ .getNodeValue()); NodeList parametersList = item.getChildNodes(); for (int p = 0; p < parametersList.getLength(); p++) { item = parametersList.item(p); nodeName = item.getNodeName(); if (nodeName.equalsIgnoreCase("param")) //$NON-NLS-1$ { String key = ((Node) item).getAttributes().getNamedItem("key") //$NON-NLS-1$ .getNodeValue(); String value = ((Node) item).getAttributes().getNamedItem("value") //$NON-NLS-1$ .getNodeValue(); object.getParameters().put(key, value); } } tab.getObjects().add(object); } } row.getTabs().add(tab); } } chart.getRows().add(row); } } } catch (Exception e) { log.error(e.toString(), e); } } if (chart.getTitle().length() == 0) chart.setTitle(chart.getSecurity().getDescription()); chart.clearChanged(); return chart; }