/** * WhiteboardObjectTextJabberImpl constructor. * * @param xml the XML string object to parse. */ public WhiteboardObjectTextJabberImpl(String xml) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); InputStream in = new ByteArrayInputStream(xml.getBytes()); Document doc = builder.parse(in); Element e = doc.getDocumentElement(); String elementName = e.getNodeName(); if (elementName.equals("text")) { // we have a text String id = e.getAttribute("id"); double x = Double.parseDouble(e.getAttribute("x")); double y = Double.parseDouble(e.getAttribute("y")); String fill = e.getAttribute("fill"); String fontFamily = e.getAttribute("font-family"); int fontSize = Integer.parseInt(e.getAttribute("font-size")); String text = e.getTextContent(); this.setID(id); this.setWhiteboardPoint(new WhiteboardPoint(x, y)); this.setFontName(fontFamily); this.setFontSize(fontSize); this.setText(text); this.setColor(Color.decode(fill).getRGB()); } } catch (ParserConfigurationException ex) { if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml); } catch (IOException ex) { if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml); } catch (Exception ex) { if (logger.isDebugEnabled()) logger.debug("Problem WhiteboardObject : " + xml); } }
@Override public org.mmbase.bridge.Node getNode(final Cloud userCloud, final Document doc) { String docId = doc.get("number"); if (docId == null) { throw new IllegalArgumentException("No number found in " + doc); } LazyMap m = nodeCache.get(docId); // if (m == null) { Map<String, String> keys = new HashMap<String, String>(); for (String keyWord : keyWords) { keys.put(keyWord, doc.get(keyWord)); } m = new LazyMap(docId, keys); nodeCache.put(docId, m); } org.mmbase.bridge.Node node = new MapNode<String>( m, new MapNodeManager(userCloud, m) { @Override public boolean hasField(String name) { if (JdbcIndexDefinition.this.key.equals(name)) return true; return super.hasField(name); } @Override public org.mmbase.bridge.Field getField(String name) { if (map == null && JdbcIndexDefinition.this.key.equals(name)) { org.mmbase.core.CoreField fd = org.mmbase.core.util.Fields.createField( name, org.mmbase.core.util.Fields.classToType(Object.class), org.mmbase.bridge.Field.TYPE_UNKNOWN, org.mmbase.bridge.Field.STATE_VIRTUAL, null); return new org.mmbase.bridge.implementation.BasicField(fd, this); } else { return super.getField(name); } } }); if (log.isDebugEnabled()) { log.debug("Returning node for " + node); } return node; }
CloseableIterator<JdbcEntry> getSqlCursor(final String sql) { try { long start = System.currentTimeMillis(); final Connection con = getDirectConnection(); log.debug("About to execute " + sql + " (" + directConnections + ")"); final Statement statement = con.createStatement(); final ResultSet results = statement.executeQuery(sql); if (log.isDebugEnabled()) { log.debug("Executed " + sql + " in " + (System.currentTimeMillis() - start) + " ms"); } final ResultSetMetaData meta = results.getMetaData(); return new CloseableIterator<JdbcEntry>() { boolean hasNext = results.isBeforeFirst(); int i = 0; @Override public boolean hasNext() { return hasNext; } @Override public JdbcEntry next() { if (!hasNext) { throw new NoSuchElementException(); } try { results.next(); hasNext = !results.isLast(); } catch (java.sql.SQLException sqe) { log.error(sqe); hasNext = false; } JdbcEntry entry = new JdbcEntry(meta, results, sql); i++; if (log.isServiceEnabled()) { if (i % 100 == 0) { log.service("jdbc cursor " + i + " (now at id=" + entry.getIdentifier() + ")"); } else if (log.isDebugEnabled()) { log.trace("jdbc cursor " + i + " (now at id=" + entry.getIdentifier() + ")"); } } return entry; } @Override public void remove() { throw new UnsupportedOperationException(); } @Override public void close() { log.debug("Closing " + con); try { if (results != null) results.close(); if (statement != null) statement.close(); if (con != null) con.close(); } catch (Exception e) { log.error(e); } } }; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }