Freelancer Martin Zeller

php asp.net java c# .net c++ xml xhtml seo magento zend framework dotnetnuke tomcat iis sql server mysql oracle typo3 coremedia

zf2 – logger problems with the FirePhp/FireBug writer in a console request

Tags: , ,

In my  recent zf2 (zend framework 2.1) project module I defined a logger with a stream writer and a firephp writer. I am using the same module also for some console requests (Zend\Console). The problem I had was that the system complains of the firephp logger when I did a console request:


======================================================================
The application has thrown an exception!
======================================================================
Exception
Headers already sent in C:\...\Zend\Console\Adapter\AbstractAdapter.php
on line 56. Cannot send log data to FirePHP. You must have Output Buffering
enabled via ob_start() or output_buffering ini directive.
----------------------------------------------------------------------

Short: Cannot send log data to FirePHP. 

So I changed my local.php file to differentiate between a HTTP request and a console request.

This is the important part of the service_manager/factories configuration:


'Zend\Log\Logger' => function($sm) {
	$request = $sm->get('Request');
	$logger = new \Zend\Log\Logger();
	if ($request instanceof Zend\Console\Request) {
		$file = new \Zend\Log\Writer\Stream(__DIR__ . '/../../data/dev-console.log');
		$logger->addWriter($file);
	} else {
		$writer_firebug = new \Zend\Log\Writer\FirePhp();
		$writer_stream = new \Zend\Log\Writer\Stream(__DIR__ . '/../../data/dev.log');
		$logger->addWriter($writer_firebug);
		$logger->addWriter($writer_stream);
	}

	return $logger;
}

zf2 – Get the route name in a custom view helper

Tags: , ,

Ever tried to get the route name in your custom view helper in a zf2 (zend framework 2.1) project?
I searched a lot – until I realized that I have to call getServiceLocator on my serviceLocator instance ;-)
This is the solution:


<?php
namespace YouCompany\YourNameSpace;

use Zend\ServiceManager\ServiceLocatorInterface;

use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\View\Helper\AbstractHelper;

class YourViewHelper extends AbstractHelper implements ServiceLocatorAwareInterface {

private $serviceLocator;

 public function __invoke() {
   $routeMatch = $this->serviceLocator->getServiceLocator()->get('Application')->getMvcEvent()->getRouteMatch();
   echo $routeMatch->getMatchedRouteName();
   die;
 }

 /**
 * Set service locator
 *
 * @param ServiceLocatorInterface $serviceLocator
 */
 public function setServiceLocator(ServiceLocatorInterface $serviceLocator) {
   $this->serviceLocator = $serviceLocator;
 }

 /**
 * Get service locator
 *
 * @return ServiceLocatorInterface
 */
 public function getServiceLocator() {
   return $this->serviceLocator;
 }
}

zf2, doctrine module and expressions (like ‘IS NOT NULL’)

Tags: , , ,

Currently I am working on a migration of a zend framework 1 project to zf2 (zend framework 2). Furthermore I want to introduce Doctrine to the project. There are some useful articles about installing and using the zf2 doctrine module. After some hours I found out how to use modules and Doctrine in zf2.
Sometimes you will have code like this:

 // em: \Doctrine\ORM\EntityManager
 $result = $this->em->getRepository('\YourNameSpace\Model\ModelObject')->findBy(array('column1'=>'xyz'), array('orderBy'=>'asc'));
 //

You can find all this stuff with google, BUT what is hard to find out: how to use expressions (like ‘IS NOT NULL’) with Doctrine with the zf2 doctrine module.
What if you want to add to our previous statement “and column2 is not null”?
See the solution:

// em: \Doctrine\ORM\EntityManager
$qb = $this->em->getRepository('\YourNameSpace\Model\ModelObject')->createQueryBuilder('c');
// add first where clause
$qb->where($qb->expr()->eq('c.column1',':ccol1'));
// add the second where clause with our "IS NOT NULL" expression
$qb->andWhere($qb->expr()->isNotNull('c.column2'));
// set the parameters
$qb->setParameter('ccol1', 'xyz');
// get the query
$query = $qb->getQuery();
// fetch the result
$result = $query->getResult();
//

For the other expressions look into the class Doctrine\ORM\Query\Expr .

Automatic resizing of wickets ModalWindow

Tags: , , ,

Today I ran into problems with wickets ModalWindow. I have got a modal dialog with a list and a form in it. The user can add a row to this list with the form. Problem was that the size of the modal window stayed as it was although the list was growing and growing. Nasty scroll bars appeared around my modal dialog. So I’d like to make the dialog to “auto resize” on each post.

My solution was simple. I just added this line of code in the onsubmit handler of the ajax button:

// in the onsubmit handler of the ajax button
target.appendJavaScript("window.parent.Wicket.Window.current.autoSizeWindow();");
//

It’s like magic. Now the modal dialog always has the proper size ;-)
(Tested with wicket version 1.5.5)

GeoServer – create a datastore programmatically

Tags: ,

Currently I am programming an upload module for GeoServer 2.1-RC2. The user should be able to upload a shape file which is automatically installed as datastore in the default workspace. For this intention I didn’t want to use the REST-API of GeoServer, I wanted to create the data store  programmatically.

The following piece of code adds a ShapeFile data store to GeoServer:

private boolean addShapeFileDataStore(String title, String description, String pathToFile)  {
		final Catalog catalog = getCatalog();
        DataStoreInfo dsInfo = catalog.getFactory().createDataStore();
        dsInfo.setName(title);
        dsInfo.setDescription(description);
        dsInfo.setEnabled(true);
        dsInfo.setType("Shapefile");
        dsInfo.getConnectionParameters().put("create spatial index", true);
        dsInfo.getConnectionParameters().put("charset", "ISO-8859-1");
        dsInfo.getConnectionParameters().put("filetype", "shapefile");
        dsInfo.getConnectionParameters().put("cache and reuse memory maps", true);
        dsInfo.getConnectionParameters().put("url", "file:" + pathToFile);
        dsInfo.getConnectionParameters().put("namespace", "http://www.torres.at/");
        try {
            catalog.add(dsInfo);
        } catch (Exception e) {
            LOGGER.log(Level.WARNING, "Error adding data store to catalog", e);
        }
        return true;
}

It’s quite simple. With this code you can add every kind of data store to GeoServer – all you need to know are the connection parameters. If you do not know the parameters of your kind of data store just create such a data store and write the connection parameters to your log file. You could use the following function:

private void LogDataStoreData(String dataStoreName) {
		final Catalog catalog = getCatalog();
        DataStoreInfo ds = catalog.getDataStoreByName(dataStoreName);
        if (ds!=null)
        {
            Map<String,Serializable> conMap = ds.getConnectionParameters();
            LOGGER.finest("Id: " + ds.getId());
            LOGGER.finest("Name: " + ds.getName());
            LOGGER.finest("Description: " + ds.getDescription());
            LOGGER.finest("Type: " + ds.getType());
            LOGGER.finest("Connection parameters:");

            for(String key : conMap.keySet())
            {
                LOGGER.finest("\t" + key + ": " + conMap.get(key));
            }
        }
}

GeoServer modules, extensions, interfaces

Tags:

If want to know how you can write modules, interfaces or extensions for GeoServer, use google and search for “geoserver wicket” – that’s the magic word.
You can find a tutorial / howto in the GeoServer Wicket Development Dokumentation.

C pointers for dummies (like me :)

Tags: ,

Just a little piece of code in C for clearing up pointers… look at the comments in the first part!
(If you need an environment to develop in C on windows, find a solution here: environment for ansi c on windows

void change(short*, short*);

int main(void) {
	short *pointer1 = NULL;
	short *pointer2 = NULL;
	short value1 = 1111;
	short value2 = 2222;

	pointer1 = &value1;
	pointer2 = &value2;

	printf("main - VALUE1:\n");
	printf("main - value of value1: %d\n", value1); // Output the value of value1
	printf("main - value of value1: %d\n", *pointer1); // Output the value at the address
	printf("main - address of value1: %p\n", &value1); // Output the address of value1
	printf("main - address of value1: %p\n", pointer1); // Output the value of pointer1 (it's the address of value1 !)
	printf("main - address of pointer1: %p\n", &pointer1);	// Output the address(!) of the pointer(!)
	printf("\nmain - VALUE2:\n");
	printf("main - value of value2: %d\n", value2);
	printf("main - value of value2: %d\n", *pointer2);
	printf("main - address of value2: %p\n", &value2);
	printf("main - address of value2: %p\n", pointer2);
	printf("main - address of pointer2: %p\n", &pointer2);
	printf("\n*** main - starting change...\n\n");
	change(pointer1, pointer2);
	printf("\n*** main - changing done!\n\n");
	printf("main - VALUE1:\n");
	printf("main - value of value1: %d\n", value1);
	printf("main - value of value1: %d\n", *pointer1);
	printf("main - address of value1: %p\n", &value1);
	printf("main - address of value1: %p\n", pointer1);
	printf("main - address of pointer1: %p\n", &pointer1);
	printf("\nmain - VALUE2:\n");
	printf("main - value of value2: %d\n", value2);
	printf("main - value of value2: %d\n", *pointer2);
	printf("main - address of value2: %p\n", &value2);
	printf("main - address of value2: %p\n", pointer2);
	printf("main - address of pointer2: %p\n", &pointer2);

	return EXIT_SUCCESS;
}

void change(short *valuePointer1, short *valuePointer2) {
	printf("change - value of value1: %d\n", *valuePointer1);
	printf("change - address of value1: %p\n", valuePointer1);
	printf("change - value of value2: %d\n", *valuePointer2);
	printf("change - address of value2: %p\n", valuePointer2);
	printf("change - changing now...\n");
	short h;
	h = *valuePointer1;
	*valuePointer1 = *valuePointer2;
	*valuePointer2 = h;
	printf("change - changing done!\n");
	printf("change - value of value1: %d\n", *valuePointer1);
	printf("change - address of value1: %p\n", valuePointer1);
	printf("change - value of value2: %d\n", *valuePointer2);
	printf("change - address of value2: %p\n", valuePointer2);
}

gcc on windows with eclipse and mingw

Tags: , , , ,

This information will help you:

  • if you want to develop in C with gcc on windows
  • if you want to develop in C with mingw and eclipse with CDT plugin

Forget all the tutorials for installing and configuring eclipse with mingw or cygwin – just download the Wascana Eclipse C/C++ IDE for Windows Developers
You will be surprised!

Wascana is a ready-to-use-eclipse-ide (Helios) with mingw toolchain installed and configured! OUT OF THE BOX! You don’t have to install anything else (neither mingw nor cygwin)!

** Download: Wascana

Het mysterie van Arendarvon Castle

Tags: ,

Gute Neuigkeiten für alle niederländischen Fans des C64-Adventures ‘Das Geheimnis des Schloss Arendarvon’. Dank eines eurer Landsleute konnte (und wird auch weiterhin) die niederländische Version unserer Fanpage nun endlich richtig übersetzt. Seht:

=> Het mysterie van Arendarvon Castle

(Die deutsche Version der Fan-Seite: => Das Geheimnis des Schloss Arendarvon)

Unser Dank geht an H. Zwetsloot

The “IE7 setAttribute class” problem!

Tags: , ,

This does not work with IE7:

elem.setAttribute('class',  cssClass);

Use this instead:

elem.setAttribute((document.all ? 'className' : 'class'), cssClass);

Problem: document.all exists in IE8 too, but IE8 does not work with ‘className’!
My solution in one of my projects was prototype:

Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7;

function SetCssClass(id, cssClass) {
  if (Prototype.Browser.IE6 || Prototype.Browser.IE7)
    $(id).setAttribute((document.all ? 'className' : 'class'), cssClass);
  else $(id).setAttribute('class', cssClass);
}

PS: in IE7 you can set styles to an element this way:

elem.style.setAttribute('cssText', 'border:1px solid red;',0);

© 2009 Freelancer Martin Zeller. All Rights Reserved.

This blog is powered by the Wordpress platform and beach rentals.