Categories
discuss

Capture xsl:message output in java

I’m trying to capture xsl:message in java when calling my transform. Below is a snippet of my code.

        final ArrayList<TransformerException> errorList = new ArrayList<TransformerException>();
        ErrorListener errorListener = new ErrorListener() {
          @Override
          public void warning(TransformerException e) throws TransformerException {
            //To change body of implemented methods use File | Settings | File Templates.
            log.error(e.getMessage());
            errorList.add(e);
          }

          @Override
          public void error(TransformerException e) throws TransformerException {
            //To change body of implemented methods use File | Settings | File Templates.
            log.error(e.getMessage());
            errorList.add(e);
          }

          @Override
          public void fatalError(TransformerException e) throws TransformerException {
            //To change body of implemented methods use File | Settings | File Templates.
            errorList.add(e);
            throw e;
          }
      };
      ...
      try
      {
        transformer.setErrorListener(errorListener);
        newDoc = transform(transformer, oldDoc);
      }
      catch (TransformerException e) {
        log.error("Problem transforming normalized document into PUBS-XML", e);
        throw e;
      }

Unfortunately this is not working.

Is there a better way?

Thanks in advance!

Answer

If you are using Saxon, then you may need to set the message emitter using setMessageEmitter().

https://www.saxonica.com/html/documentation10/javadoc/net/sf/saxon/trans/XsltController.html#setMessageEmitter-net.sf.saxon.event.Receiver-

public void setMessageEmitter(Receiver receiver)

Set the Receiver to be used for xsl:message output.

Recent versions of the JAXP interface specify that by default the output of xsl:message is sent to the registered ErrorListener. Saxon does not implement this convention. Instead, the output is sent to a default message emitter, which is a slightly customised implementation of the standard Saxon Emitter interface.

This interface can be used to change the way in which Saxon outputs xsl:message output.

Michael Kay has explained why Saxon doesn’t output xsl:message according to the JAXP interface, and has suggested two options for obtaining the output:

ErrorListener was something that was introduced to JAXP at a rather late stage (one of many regrettable occasions where the spec was changed unilaterally to match the Xalan implementation), and I decided not to implement this change as a default behaviour, because it would have been disruptive to existing applications.

In Saxon, xsl:message output is directed to a Receiver, which you can nominate to the Transformer:

((net.sf.saxon.Controller)transformer).setMessageEmitter(....)

If you want to follow the JAXP model of sending the output to the ErrorListener, you can nominate a Receiver that does this:

((net.sf.saxon.Controller)transformer).setMessageEmitter(new net.sf.saxon.event.MessageWarner())

Categories
discuss

Javascript comma syntax

Why do so many developers write commas this way?

var npm = module.exports = new EventEmitter
  , config = require("./lib/config")
  , set = require("./lib/utils/set");

Not this way?

var npm = module.exports = new EventEmitter,
    config = require("./lib/config"),
    set = require("./lib/utils/set");

Answer

They write them with the “,” at the beginning of the line to make it easier to maintain the code (add lines or remove/comment out lines).

Given this:

var npm = module.exports = new EventEmitter
  , config = require("./lib/config")
  , set = require("./lib/utils/set");

It’s much cleaner and easier to do this:

var npm = module.exports = new EventEmitter
//  , config = require("./lib/config")
  , set = require("./lib/utils/set");

as well as add new lines like this:

var npm = module.exports = new EventEmitter
  , config = require("./lib/config")
  , anothervalue = require("./lib/aval")
  , anothervalue2 = require("./lib/aval2")
  , set = require("./lib/utils/set");
Categories
discuss

best method for background uploader in Android

Problem:

I want to write a process that will allow a user to take photos with the device and for those photos to then be uploaded to some listener in the cloud. The user should not have to do anything to initiate the upload, a background listener would just watch the folder and as long as it finds files in it it would upload them and delete them.

Two problems:
1) how to keep the program running in the background even after the user is no longer taking pictures (and if they reboot the device for it to wake up and finish the uploads, if any remain)

2) assuming the connection is spotty (as it always is) how to verify that a given image has completed its upload, and if not, to resubmit it.

I don’t need any code examples, I just would like opinions on the best strategy to get this implemented.

I was going to use Apache commons and just do an upload to a PHP, but am not sure what sort of error checking exists to take into account a connection drop mid file.

TIA.

Answer

Having essentially written this application several times on several platforms, I can tell you that it’s not a trivial endeavor. To tackle the first problem, you can create a Service that sits in the background and performs your uploads. In order for it to start up automatically, you can declare that it receives the intent android.intent.action.BOOT_COMPLETED in your manifest (you’ll need the permission android.permission.RECEIVE_BOOT_COMPLETED in order to make use of that). If you’re going to listen for stuff written out by the standard camera app, you can use registerContentObserver to listen for new stuff – beware, phones can have more than one place they stash photos!

For the second problem, have your webservice return information regarding the completion of the upload which your client can use to decide on retries.

Categories
discuss

How can I force Selenium to run tests only after $(document).ready() has completed?

Our site does a lot of JavaScript/jQuery work in the $(document).ready() function, setting up buttons, loading content via ajax, etc. Selenium waits until the DOM is loaded, but then proceeds to test before .ready() has completed.

A partial solution seems to be using a check to see if the browser has pending ajax requests:

selenium.browserbot.getCurrentWindow().jQuery.active == 0

However that doesn’t ensure that we aren’t still setting up bindings for buttons and things.

Any help will be greatly appreciated. The current ‘best’ suggestion is adding an element to the page at the end of the .ready() method, which Selenium can catch as a signal to start working, but the idea of adding code like this for testing purposes seems sketchy at best.

Answer

I believe you can use the window load check. Try this:

$(window).load(function(){  
  selenium.browserbot.getCurrentWindow().jQuery.active == 0 
});  
Categories
discuss

Draw a Image on FullScreen mode Android

I already know how to get my Activity as fullscreen on Android, now I need to draw a Image in this screen.

This is my XML layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/image01" android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
</LinearLayout>

This image is dynamic generated and drawed in the ImageView.

This is my code on my Activity.

public void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.main);
}

But when running, the Activity is FullScreen, but the ImageView is adjusted in the center.

What’s wrong?

I added the following code to see the components dimensions.

    View view = getWindow().getDecorView();
    Log.i("RMSDK:J:IbaReader(decor)",
            "[w=" + view.getWidth() + ":h=" + view.getHeight() + "]");
    Log.i("RMSDK:J:IbaReader(img)",
            "[w=" + img.getWidth() + ":h=" + img.getHeight() + "]");

This results in [w=320:h=480] in both cases.

This is my draw method.

private void draw() {
    byte[] image = services.getImageBuffer(600, 1024);
    Bitmap bmp = Bitmap.createBitmap(600, 1024, Bitmap.Config.RGB_565);
    int row = 0, col = 0;
    for (int i = 0; i < image.length; i += 3) {
        bmp.setPixel(col++, row, image[i + 2] & image[i + 1] & image[i]);
        if (col == 600) {
            col = 0;
            row++;
        }
    }
    img.setImageBitmap(bmp);
}

Answer

Add android:scaleType="fitXY" to you imageview

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..