Wednesday, October 01, 2014

View centric lazy data loading using Apache Commons LazyMap in JSF with Primefaces.

 Facelets:
   <p:dataTable id="europe" value="#{bean.dataMap.europe}" var="data">
    <p:column>
     <h:outputText value="#{data.displayName}" />
    </p:column>
   </p:dataTable>

   <p:dataTable id="asia" value="#{bean.dataMap.asia}" var="data">
    <p:column>
     <h:outputText value="#{data.displayName}" />
    </p:column>
   </p:dataTable>


 Backed Bean:

 import org.apache.commons.collections.Transformer;
 import org.apache.commons.collections.map.LazyMap;
 import org.primefaces.model.LazyDataModel;
 ...
 private Map dataMap = LazyMap.decorate(new HashMap<String, List>(), new Transformer() {
  public List transform(Object o) {
   if ("asia".equalsIgnoreCase(o.toString())) {
    return Arrays.asList(Locale.TAIWAN, Locale.CHINA, Locale.KOREA);
   } else {
    return Arrays.asList(Locale.GERMAN, Locale.FRENCH, Locale.ENGLISH);
   }
  }
 });

Wednesday, September 10, 2014

A more common key binding for Eclipse


In Eclipse go to Window > Preferences > General > Keys page.

Search in filter text for "Find"

Set Binding property to:


Find and Replace … Ctrl+R

Find Next … F3

Incremental Find … Ctrl+F

Check for some conflicts.

Friday, March 22, 2013

Loading .osm into BaseX

Using Open Street Map .osm Data and BaseX with REST services
  • Copy the BaseX77.war into your prefered WebContainer (e.g. JBoss7)
  • Modify the web.xml
  • Download .osm data and load the the .osm data as parts (e.g. split them with osmosis)
  • Use XPath or XQuery over REST for your information needs
Add the following to the web.xml:

  org.basex.indexsplitsize
  1000000

Add in your command line (or script):
curl -i -X PUT http://admin:admin@127.0.0.1:8080/BaseX77/rest/osmdb

curl -i -X PUT -T "austria.part1.osm" http://admin:admin@127.0.0.1:8080/BaseX77/rest/osmdb/austria.part1.osm
curl -i -X PUT -T "austria.part2.osm" http://admin:admin@127.0.0.1:8080/BaseX77/rest/osmdb/austria.part2.osm

curl -i -X GET http://127.0.0.1:8080/BaseX77/rest/osmdb?command=FLUSH

curl -i -X GET http://127.0.0.1:8080/BaseX77-20130321.085136/rest/osmdb?command=OPTIMIZE
Worked fine with the paramters -Xms512m -Xmx 1024m for the following dabase size:
Database Properties:
 Name: osmdb
 Size: 7407 MB
 Nodes: 355247222
 Documents: 588
...
For testing query your oms-xml database by entering an URL to your browser returning the waypoins of a nice place:
for 
 $way in /osm/way, 
 $node in /osm/node
where 
 $way/tag[@k="name"][@v="Michaelerplatz"] and
 $node/@id=$way/nd/@ref
return $node
This query is back in about 3 minutes, the below optimized query is back in about 8 milisecons.
for 
 $way in /osm/way, 
 $node in /osm/node
where 
 $way/tag/@v="Michaelerplatz" and
 $node/@id=$way/nd/@ref
return $node|$way
This will be optimized by BaseX to
for $way in db:attribute("osmdb", "Michaelerplatz")/self::v/parent::tag/parent::*:way 
for $node in db:attribute("osmdb", $way/nd/@ref)/self::id/parent::*:node 
return (($node union $way))

Sunday, February 27, 2011

Create a graphviz dot file from a gedcom 6 xml file.

Create a graphviz dot file from a gedcom 6 xml file.



 
 
 
digraph G {
 label="My Heritage Tree"; 
 bgcolor="white";
 margin="0,0"; /* default margin is 0.5 inches */
 /* splines=false; */
 ranksep="0.15 equally"; /* vertical distance between each generation, default separation between ranks is 0.75 inches */
 node[fontsize=8, fontname="Helvetica", shape=plaintext];
 edge[arrowsize=0.5, color=black, dir=none];  
  
   
    
   
   
    
   
   
    
   
   
}
 

 
 
  
  
   
       
    
     
    
     ->
    
    
    
     
       
    
     
    
    
       
 
    
 
  
  
  [ label=" 
  
   
   
    
   
   
    
     
   
    \n
    *
    
   
   
    \n
    
    
      
   
    
     
    
    \n
    (
    
     
     
      
     
     
      
       
     
      \n
      *
      
     
     
      \n
      
      
     
     
    )
    
   
  "];
  
  
 

Friday, January 15, 2010

extjs & jquery & Oracle Apex

To get the grid "dynamic" try somthing like (assuming that you use the jQuery adapter) this:

Ext.onReady(function() {
 jQuery("table.standardalternatingrowcolors",this).each(function(){
 var table = this;
 // create the data array
 var myData = new Array();
 jQuery('tr[td]',table).each(function(){
   var tr = new Array();
   jQuery('td', this).each(function(){  
     tr[tr.length] = jQuery(this).html();
   });
   myData[myData.length] = tr;
 });
 // create the metadata array
 var myHeaders = new Array;
 jQuery('tr[th]',table).each(function(){
   jQuery('th', this).each(function(){  
     var header = {};
     header["name"] = jQuery(this).attr('id');
     header["dataIndex"] = jQuery(this).attr('id');
     header["header"] = jQuery(this).html();
     header["sortable"] = true;
     header["width"] = 90;
     myHeaders[myHeaders.length] = header;
   });
 });
 
  var ds = new Ext.data.Store({
   proxy: new Ext.data.MemoryProxy(myData),
   reader: new Ext.data.ArrayReader({id: 0}, myHeaders)
  });
  ds.load();
 
  var colModel = new Ext.grid.ColumnModel(myHeaders);
  jQuery(table).attr(id,'x');
  var grid = new Ext.grid.GridPanel({el: 'grid-example', ds: ds, cm: colModel});
  grid.render();
  grid.getSelectionModel().selectFirstRow();
  jQuery(table).show();
 
 }); // replace each table on the page
 
});

FOP & JBoss & Oracle Apex

Add the missing Oracle XML Parser v2 (you may find them e.g. in JDeveloper/lib) libraries (lib/xmlparserv2.jar, lib/xml.jar) by opening the fop.war with your favorite zip program (e.g. rename fop.war to fop.zip) and saving the libraries WEB-INF/lib. Then copy the fop.war to the e.g. jboss\server\default\deploy directory. Maybe you have to restart your application server (dependent on your settings). Then try http://your-hostname:your-port/fop/apex_fop.jsp (e.g. http://127.0.0.1:8080/fop/apex_fop.jsp) to see if your work was successful.

Manage Service / Instance Settings / Report Printing
Print Server: Standard Support
Print Server Host Address: 127.0.0.1
Print Server Port:8080
Print Server Script: /fop/apex_fop.jsp

<%@ page import='java.io.*'%>
<%@ page import='org.xml.sax.InputSource'%>
<%@ page import='org.apache.fop.apps.Driver'%>
<%@ page import='org.apache.fop.apps.Options'%>
<%@ page import='oracle.xml.parser.v2.XMLDocument'%>
<%@ page import='oracle.xml.parser.v2.XSLProcessor'%>
<%@ page import='oracle.xml.parser.v2.XSLStylesheet'%>
<%@ page import='oracle.xml.parser.v2.DOMParser'%>
<%
// see http://xml.apache.org/fop/output.html for all output types
XMLDocument   v_doc;
XSLStylesheet v_xsl = null;
String        v_fop;
DOMParser     parser = new DOMParser();
XSLProcessor processor = new XSLProcessor();
String        v_encode = "UTF-8";
 
String p_xsl = request.getParameter("template");
String p_xml = request.getParameter("xml");
 
/* transform an XML source to XSLFO using an XSL transformation */
v_xsl = new XSLStylesheet(new java.io.StringReader(p_xsl),null);
parser.parse(new java.io.StringReader(p_xml));
v_doc = parser.getDocument();
ByteArrayOutputStream v_out = new ByteArrayOutputStream();
processor.processXSL(v_xsl, v_doc, v_out);
v_fop = new String(v_out.toByteArray(),v_encode);
 
/* The FOP process */
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
 
driver.setInputSource(new InputSource(new StringReader(v_fop)));
 
ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
driver.setOutputStream(outBuffer);
 
driver.run();
 
OutputStream outStream = response.getOutputStream();
response.setContentType("application/pdf");
response.setContentLength(outBuffer.size());
outStream.write(outBuffer.toByteArray());
outStream.flush();
%>

jQuery autocomplete and Oracle Apex

Here you can find some code if you want to use the jquery.autocomplete.js without modification.
Download the autocomplete jQuery plugin and upload then to your "Shared Components"/"Cascading Style Sheets".
Also upload the basic jquery library there.

Download Links:
http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
http://jquery.com/

Add the following to your Page HTML Header where you want to use the autocomplete list:







This looks complex, but the only thing your have to change is to change the name of the item where you want to have a autocomplete list

Tuesday, January 12, 2010

Paging with SQL mysql: startrow and maxrows
SELECT * FROM person ORDER BY LAST_NAME DESC LIMIT 11, 10
oracle: startrow and endrow
SELECT s.*
FROM (
 SELECT ROWNUM as COUNTER, x.*
 FROM (
  SELECT p.NAME, p.FIRST_NAME, p.LAST_NAME
  FROM person p
  ORDER BY p.LAST_NAME DESC
 ) x
) s
WHERE s.COUNTER BETWEEN 5 AND 8;

Sunday, December 13, 2009

Users created per day in drupal

SELECT 
DATE(FROM_UNIXTIME(created)) INTER, 
count(*) USERS
FROM users 
GROUP BY DATE(FROM_UNIXTIME(created))
ORDER BY DATE(FROM_UNIXTIME(created)) DESC