Never been to DZone Snippets 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

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Copy all svn:* properties from one file to another

The following script can be used to copy all SVN properties from one file (presumably a file that's already under SVN control) to another file (which you presumably want to put under SVN control, and which you want to check in with the same SVN properties).

#!/bin/sh

ORIG=$1 ; shift ;
[ -e "$ORIG" ] || exit ;

for PROP in `svn pl "$ORIG" | sed -n '2,$p'` ; do
        VALUE=`svn pg $PROP "$ORIG"` ;
        for FILE ; do
                [ -e "$FILE" ] && svn ps $PROP "$VALUE" "$FILE" ;
        done
done

# That's it, Folks!


If you put the above code in a shell script called...

svnprops.sh


... then you can run it as follows if you want to copy all svn:* properties FROM original.file TO blegga:

pvdb@localhost ~ $ ./svnprops.sh original.file blegga 
property 'svn:mime-type' set on 'blegga'
property 'svn:eol-style' set on 'blegga'
pvdb@localhost ~ $ _


... or as follows for multiple target files:

pvdb@localhost ~ $ ./svnprops.sh another.original.file blegga foo bar 
property 'svn:mime-type' set on 'blegga'
property 'svn:mime-type' set on 'foo'
property 'svn:mime-type' set on 'bar'
pvdb@localhost ~ $ _ 

Loading a property file from the classpath

Loads a property file located anywhere in the classpath

    private Properties getPropertiesFromClasspath(String propFileName) throws IOException {
        // loading xmlProfileGen.properties from the classpath
        Properties props = new Properties();
        InputStream inputStream = this.getClass().getClassLoader()
            .getResourceAsStream(propFileName);

        if (inputStream == null) {
            throw new FileNotFoundException("property file '" + propFileName
                + "' not found in the classpath");
        }

        props.load(inputStream);

        return props;
    }

Loading an xml properties file

// simple example of loading an xml file into Properties.

Properties properties = new Properties();
try {
    InputStream xmlStream = getClass().getResourceAsStream("properties.xml");
    if( xmlStream == null ) {
         //throw some error
    }            
    properties.loadFromXML(xmlStream);
} catch (IOException exception) {
    // throw exception
}


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
    <entry key="plugin.TestPlugin">com.plugin.test.TestPluginModule</entry>
    <entry key="messages.TestPlugin">TestPluginMessages.properties</entry>
</properties>

Change Text Properties on Mouseover

This only works with the IE browsers. Add this code within your <head> tags. To keep the underline on your links, replace "none" with "underline" Change "YourColor" with the hexidecimal number of color required.
Find this and other snippets on my site, if you wish, by clicking here

<style
type="text/css"> <!-- A:link { text-decoration: none; color:#YourColor
} A:visited { text-decoration: none; color:#YourColor } A:hover { text-decoration:
none; color:#YourColor } --> </style>

J2ME - System Properties

// System Properties J2ME

package System;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class SystemProperties extends MIDlet implements CommandListener
{
	private Command esci;
	
	private Display display;
	
	private Form form;
	
	protected void startApp() throws MIDletStateChangeException
	{
		display = Display.getDisplay(this);
		
		form = new Form("System Propiertis");
		form.setCommandListener(this);
		
		esci = new Command("Esci", Command.EXIT, 0);
		form.addCommand(esci);
		
		Runtime rt = Runtime.getRuntime();
		rt.gc(); // Garbage Collection
		
		form.append("Free Memory: " + rt.freeMemory() + "\n");
		form.append("Total Memory: " + rt.totalMemory() + "\n");
		form.append(showProp("microedition.configuration"));
		form.append(showProp("microedition.platform"));
		form.append(showProp("microedition.locale"));
		form.append(showProp("microedition.encoding"));
		form.append(showProp("microedition.encodingClass"));
		form.append(showProp("microedition.http_proxy"));
		
		display.setCurrent(form);
	}

	protected void pauseApp()
	{

	}

	protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
	{
		notifyDestroyed();
	}

	public String showProp(String str)
	{
		String value = System.getProperty(str);
		StringBuffer stringbuffer = new StringBuffer(50);
		
		stringbuffer.setLength(0);
		stringbuffer.append(str);
		stringbuffer.append(" = ");
		
		if(value == null)
			stringbuffer.append("<undefined>");
		else
		{
			stringbuffer.append("\"");
			stringbuffer.append(value);
			stringbuffer.append("\"");
		}
		
		stringbuffer.append("\n");
		
		return stringbuffer.toString();
	}
	
	public void commandAction(Command c, Displayable d)
	{
		if(c == esci)
		{
			try
			{
				destroyApp(true);
			}
			catch(MIDletStateChangeException e)
			{
				showException(e);
			}
		}
	}
	
	public void showException(Exception e)
	{
		Alert alert = new Alert("Errore !!!");
		alert.setString(e.getMessage());
		alert.setType(AlertType.ERROR);
		alert.setTimeout(Alert.FOREVER);
		
		display.setCurrent(alert);
	}
}
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS