分类目录归档:程序开发

Sablog-X 2.0 20100301 ->WordPress 3.5.1数据转移程序

代码基于maker同学写的Sablog-X 1.6 => WordPress 2.2.3 转换程序 – 080422 测试版。

程序功能:

1.支持导入sablog-x 2.0 20100301的数据包括:附件、分类、标签、文章、评论。

2.友情链接数据由于wordpress3.5.1已默认关闭了友情链接,所以就没转,手工通过菜单功能实现了。

3.其它功能参见Sablog-X 1.6 => WordPress 2.2.3 转换程序 – 080422 测试版

4.下载链接:sablog-to-wordpress

Java动态调用Groovy

 

package com.neeao.groovy;

import groovy.lang.Binding;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyShell;
import groovy.util.GroovyScriptEngine;

public class helloGroovy {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		fun1();
		fun2();
		fun3();
		System.out.print(System.currentTimeMillis() - time);
		System.out.println(" ms");
	}

	private static void fun3() {
		try {
			GroovyScriptEngine engine = new GroovyScriptEngine("");
			Binding binding = new Binding();
			binding.setVariable("language", "Groovy");
			Object value = engine.run("SimpleScript.groovy", binding);
			assert value.equals("The End");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static void fun2() {
		Binding binding = new Binding();
		binding.setVariable("x", 10);
		binding.setVariable("language", "Groovy");
		GroovyShell shell = new GroovyShell(binding);
		Object value = shell.evaluate("println \"Welcome to $language\"; y = x * 2; z = x * 3; println x ");
		assert value.equals(10);
		assert binding.getVariable("y").equals(20);
		assert binding.getVariable("z").equals(30);
	}

	private static void fun1() {
		GroovyClassLoader loader = new GroovyClassLoader();
		try {
			String scriptText = "class Foo {\n"
					+ "  int add(int x, int y) { x + y }}";
			Class<?> newClazz = loader.parseClass(scriptText);
			Object obj = newClazz.newInstance();
			Object i = obj.getClass().getMethod("add", int.class, int.class)
					.invoke(obj, 23, 3);
			System.out.println(i);
		} catch (Exception e) {

		}
	}

}

参考:

http://zjx158.iteye.com/blog/770763

http://tglnn.iteye.com/blog/376978

 

Talend中mysql数据库中文乱码解决

 

添加数据链接的时候,在Additional parameters默认设置noDatetimeStringSync=true后面增加编码设置:

&characterEncoding=UTF-8

最后设置为:

“noDatetimeStringSync=true&characterEncoding=UTF-8”


祥见:http://www.talendforge.org/forum/viewtopic.php?id=16201

 

检查Maven项目中ibatis的SQL注入的maven插件

记录下:

CheckMojo.java

package com.neeao.security.ibatis_sql_injection_check;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

/**
 * @author Neeao
 * @goal check
 * @phase prepare-package
 */
public class CheckMojo extends AbstractMojo {
	/**
	 * Web资源文件目录
	 * 
	 * @parameter expression="${basedir}/src/main/resources"
	 */
	private File resourcesDirectory;

	public void execute() throws MojoExecutionException {
		getLog().info("start sql injection check...");

		File resourcesDir = resourcesDirectory;
		if (resourcesDir.exists()) {
			getLog().info("Find ibatis xml file...");
			findFiles(resourcesDir);

		}
	}
	/**
	 * 查找文件
	 * @param dir
	 */
	private void findFiles(File dir) {
		File[] files = dir.listFiles();
		for (File f : files) {
			if (f.isFile()&&f.getName().toLowerCase().endsWith(".xml")) {
				getLog().info("find xml file:" + f.getAbsolutePath());
				checkFile(f.getAbsolutePath());
			} else if (f.isDirectory()) {
				findFiles(f);
			}
		}
	}
	/**
	 * 检查文件
	 * @param filename
	 */
	private void checkFile(String filename) {
		ArrayList<String> content = new ArrayList<String>();
		try {
			content = (ArrayList<String>) FileUtils.readLines(new File(filename));
			int i=1;
			for (String line : content) {
				if (line.contains("$")) {
					getLog().error(filename+",line:"+i+","+line);
				}
				i++;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public File getResourcesDirectory() {
		return resourcesDirectory;
	}

	public void setResourcesDirectory(File resourcesDirectory) {
		this.resourcesDirectory = resourcesDirectory;
	}
}
pom.xml文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.neeao.security</groupId>
	<artifactId>sql--injection-check</artifactId>
	<packaging>maven-plugin</packaging>
	<version>1.0</version>
	<name>sql-injection-check Maven Mojo</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<dependency>
			<groupId>org.apache.maven</groupId>
			<artifactId>maven-plugin-api</artifactId>
			<version>2.0</version>
		</dependency>
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version>
		</dependency>
	</dependencies>
</project>

 

test方法:

 

mvn clear

mvn packape

mvn install

 

D:\workspace\ibatis-sql-injection-check>mvn com.neeao.security:sql--injection-ch
eck:1.0:check
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building sql-injection-check Maven Mojo 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- sql--injection-check:1.0:check (default-cli) @ sql--injection-check -
--
[INFO] start sql injection check...
[INFO] Find ibatis xml file...
[INFO] find xml file:D:\workspace\ibatis-sql-injection-check\src\main\resources\
NewFile.xml
[ERROR] D:\workspace\ibatis-sql-injection-check\src\main\resources\NewFile.xml,l
ine:3,      name like '%$name$%'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.196s
[INFO] Finished at: Tue Nov 27 23:59:25 CST 2012
[INFO] Final Memory: 2M/15M
[INFO] ------------------------------------------------------------------------

 

php生成psd缩略图

1.psd文件为Photoshop的文件格式,浏览器不能直接显示,有个需求要将生成psd文件的预览图,Google了几天未找到可用的代码,遂自己研究了下,最终找到了解决方法,先将psd导出为jpg文件,然后再对其生成缩略图,这样就容易多了。

2.需使用到php的一个开源库:imagemagick,安装方法:Google中搜索“ImageMagick php windows 安装”,当然如果你是Linux的话,将Windows替换为Linux即可。

3.安装好了,关键是如何使用,经过几个小时的折腾,最终实现了转换,非常简单:

$mw= NewMagickWand();
MagickReadImage($mw, '123.psd');
MagickResetIterator($mw);
MagickWriteImage($mw,"123.jpg");