12 September 2011

OpenJPA as an OSGi bundle

http://hwellmann.blogspot.com/2010/09/openjpa-and-osgi.html

06 September 2011

Create bundles for non-OSGi components

This is in German but looks helpful. http://oli.blogger.de/stories/1864695/

I'll do a write-up in English when I've tried it out.

15 June 2011

Mixing Linq-to-SQL and Linq-to-XMl

I have been trying to select a column containing XML text from a database and then selecting nodes from the XML using Linq. It didn't work. My guess is that deferred execution causes the queries to be mixed and taken as Linq-to-SQL. As a result the XML stuff causes problems.

My solution was to force an intermediate result so that there is a break between SQL and XML queries. My code for LinqPad is as follows.

var all = from bm in mytable
          select new { name=bm.SPP_USER_ID, xml=(string)bm.SPP_BOOKMARKS_XML};

var docs = from x in all
           select XDocument.Parse(x.xml);
var docs2 = docs.ToList(); // FORCE RESULT

XNamespace ns = "http://acme/bookmarks";
var href = from h in docs2.Descendants(ns + "href")
           select h.Value;  

15 April 2011

Strange and annoying problem with {NOBR}

I wrote a web app about 10 years ago which used Javascript to pop up a hidden table when an input field gets focus. Each cell in the table contains a checkbox and text which are surrounded by a NOBR to keep them together.

Recently users with IE8 complained that the first cell is not visible when the table pops up. After MUCH trial and error I narrowed it down to the NOBR tag. I replaced it with a SPAN with style set to white-space : nowrap and this seems to solve the problem :-/

05 April 2011

Using 3rd party libraries in Silverlight

I downloaded a 3rd party library for a Silverlight app I am writing. When I ran the app I got an error message telling me to add

<loadFromRemoteSources enabled="true"/>

to 'devenv.exe.config' (Usually in 'C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE').

It seems you also need to edit the 'Blocked' property of the DLL.

See How to: Use an Assembly from the Web in Visual Studio for full details.

10 March 2011

RAP + BIRT on Websphere

I used the blog from Tim Pietrusky to get started: http://blog.tim-pietrusky.de/2009/rich-ajax-platform-rap/integrating-birt-into-rap-applications/

Perhaps I did something wrong but all the image links in the resulting HTML were broken. The URL to my dynamically-generated images was invalid. Even the examples from the RAP wiki showed the same problem.

In the end I decided to store my images under /rwt-resources/birt as I noticed that all the images from RWT are loaded from this address. I also changed the URL to use a context-relative address and not a fully-defined URL with host and port. On Websphere the result was an IP address and the port of the AppServer which was not accessible directly from the client.

I set the resources extension point as follows:

<extension point="org.eclipse.equinox.http.registry.resources">
  <resource
    alias="/resources/birt"
    base-name="/rwt-resources/birt">
  </resource>
</extension>


The modified View part looks like this (sorry about the formatting):


public class ChartView extends ViewPart {
public static final String ID = "com.acme.fair.views.ChartView";

private static final String reportName = "simplechart.rptdesign";
private static final String reportDirLocal = "/resources/birt/";
private static final String reportDirServer = "/rwt-resources/birt/";

private Browser browser;
private String reportDesign; // Full path to the local BIRT report file
private String URL;

private IReportEngine engine = null;
private EngineConfig config = null;
private IReportRunnable design = null;
private IRunAndRenderTask task;

@SuppressWarnings("restriction")
public void createPartControl(Composite parent) {
this.setPartName("BIRT in RAP");
browser = new Browser(parent, SWT.NONE);
configureURL();

try {
config = new EngineConfig();
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);

InputStream fs = null;
try {
URL url = Activator.getDefault().getBundle().getResource("/resources/birt/simplechart.rptdesign");
fs = url.openStream();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}

design = engine.openReportDesign(fs);

// Create task to run and render the report
task = engine.createRunAndRenderTask(design);

// Set the dataset for the chart as report parameter
task.setParameterValue("CHART_DATASET", MesseSql.getFairsPerYear());

// Render the report to HTML
HTMLRenderOption renderOptions = new HTMLRenderOption();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
renderOptions.setOutputFormat(HTMLRenderOption.HTML);
renderOptions.setOutputStream(outputStream);

// Get the path to the local context directory to save the rendered
// chart image
String webAppBase = (ContextProvider.getWebAppBase()).replaceAll("\\\\", "/");
String path = webAppBase + reportDirServer + RWT.getSessionStore().getId();

// Handle the image path
renderOptions.setImageHandler(new HTMLServerImageHandler());
renderOptions.setImageDirectory(path);
renderOptions.setBaseImageURL(RWT.getRequest().getContextPath() + reportDirServer + RWT.getSessionStore().getId());

task.setRenderOption(renderOptions);
task.run();
task.close();

// Set the HTML output to the Browser widget
browser.setText(outputStream.toString());

engine.destroy();

} catch (Exception ex) {
ex.printStackTrace();
}
}

// Set the URL for the BIRT report for different environments.
private void configureURL() {

// Protocol, ip & port
ServletContext sc = RWT.getRequest().getSession().getServletContext();
String realPath = sc.getRealPath("/");
HttpServletRequest request = RWT.getRequest();
String protocol = "http://";
String ip = request.getLocalAddr();
int port = request.getLocalPort();
URL = protocol + ip + ":" + port;
String webAppName = "";

if (realPath == null) { // Start application locally within Eclipse
// (Windows)
reportDesign = URL + reportDirLocal + reportName;
} else { // Start application on a server (Apache Tomcat or so)
webAppName = sc.getContextPath();
reportDesign = URL + webAppName + reportDirLocal + reportName;
URL = URL + webAppName;
}
}

public void setFocus() {
}

/**
* Execute the given script, for example to print the

* content of the Browser
*
* @param script
* String to be executed
*/
public void executeScript(String script) {
browser.execute(script);
}
}