Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Main class

//
class clases.Main
{
public static var mcMain : MovieClip = new MovieClip ();
//
//
// Constructor que activa la clase
//
public function Main (mainMC : MovieClip)
{
mcMain = mainMC;
}
//
//
// Capturar el XML de los productos
//
public function getXML () : Void
{

}

}

Ubuntu and writing Java servlets

Kind of a strange, and I'm sure this wouldn't have happened on any other distribution of Linux, but I spent forever looking through blogs, message boards, and all manner of other places looking for an answer to this question.

The problem was with this little itty bitty smidge of code:
/**
 * hello.java
 */
import javax.servlet.*;

class HelloWorld
{
        public static void main(String[] args)
        {
                System.out.println("Hello World!");
        }
}


Everytime I wanted to compile this, I got something like "Could not find javax.servlet. blah blah" So, eventually, I just pulled an apt-cache search j2 (for j2ee) and saw an entry for libservlet2.4-java. Hmmmmm, what the heck is that I wondered. I installed it and went to the Ubuntu site to look at what files were installed and sure enough:

/usr/share/java/jsp-api-2.0.jar
/usr/share/java/jsp-api.jar
/usr/share/java/servlet-api-2.4.jar
/usr/share/java/servlet-api.jar


Perfect! I added these paths to my CLASSPATH variable in my .bashrc and whamo, I'm in business and flaunting my little HelloWorld.class file all around town.

I hope this helps someone else!

Super simple XML and PHP

This is a super simple implementation of a concept found here:
http://xtech06.usefulinc.com/schedule/paper/19

This xml class provides a very simple way to open an XML file, get information from the XML file, modify information from the XML file and save the XML file. It also supports automatic creation of new XML files based on an automatically incrementing ID senerio (similar to auto incrementing primary keys in databases).

The creation of new XML files is done by looking for a "template" xml file named 0.xml in the directory passed to the create function. If the template file is found, then it is loaded into the xml class and saved to a new file whose name is one more than the highest filename (of course the xml extension is added on). Eventually, I will try and add some validation code and whatever else, but for now I'm trying to keep things simple.

This requires the DOM module to be built into PHP.
I am using PHP 5.

If anyone has any ideas on how to improve this, feel free to post comments.

<?php

class xml
{
	var $dom;
	var $uri;

	function xml($uri)
	{
		$this->dom = new DOMDocument();

		if(preg_match('/\.xml$/', $uri))
		{
			$this->uri = $uri;
		}
		else
		{
			$this->uri = $this->create($uri);
		}
		$this->dom->load($this->uri);
	}

	function set($query, $value)
	{
		$path = new DOMXPath($this->dom);
		$nodes = $path->query($query);
		$nodes->item(0)->nodeValue = $value;
	}

	function get($query)
	{
		$path = new DOMXPath($this->dom);
		$nodes = $path->query($query);
		return $nodes->item(0)->nodeValue;
	}

	function save()
	{
		$this->dom->save($this->uri);
	}

	function create($uri)
	{
		// Build the URI of the template file.
		$template = sprintf('%s/0.xml', $uri);

		// If the directory doesn't exist, we can't really
		// do anything.
		if(!is_dir($uri))
		{
			exit('No directory');
		}

		// If the template file doesn't exist, we cannot
		// create a new file automatically.
		if(!file_exists($template))
		{
			exit('No template');
		}

		// Load the template XML into our DOMDocument.
		$this->dom->load($template);

		// Scan the directory into an array.
		$dir = scandir($uri);

		// Pull out the highest ID
		$id = str_replace('.xml', '', array_pop($dir));

		// Add one to it
		$id++;

		// Construct the new path with the new ID
		$uri = sprintf('%s/%s.xml', $uri, $id);

		// Save the new file
		$this->dom->save($uri);

		// Return the URI of the new XML file.
		return $uri;
	}
}

// The following code will create a new XML file
// under the directory /var/www/data/users.
$x = new xml('/var/www/data/users');
$x->set('//user/name', 'John Doe');
$x->save();

?>