Skip to content

Commit

Permalink
Merge pull request #30 from support-project/develop
Browse files Browse the repository at this point in the history
Release v1.9.0
  • Loading branch information
koda-masaru authored May 20, 2017
2 parents a04d0b3 + 685cc21 commit 5dfbd74
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.support-project</groupId>
<artifactId>common</artifactId>
<version>1.8.0</version>
<version>1.9.0</version>
<packaging>jar</packaging>

<name>common</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/support/project/common/classanalysis/impl/ClassSearchImpl.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public List<Class<?>> findClasses(String rootPackageName) throws Exception {

String protocol = url.getProtocol();
if ("file".equals(protocol)) {
return findClassesWithFile(rootPackageName, new File(url.getFile()));
return findClassesWithFile(rootPackageName, new File(url.toURI().getPath()));
} else if ("jar".equals(protocol)) {
return findClassesWithJarFile(rootPackageName, url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,11 @@ public static void writeObject(final Object obj, final Writer writer) throws Ser
}

/**
* 入力をオブジェクトに変換する
*
* @param <T>
* クラスの型
* @param content
* バイト配列
* シリアライズに使うSerializerを取得(デフォルトはJSONから)
* @param type
* Class
* @return オブジェクト
* @throws SerializeException
* XmlException
* @return
*/
public static <T> T bytesToObject(final byte[] content, final Class<? extends T> type) throws SerializeException {
private static Serializer getSerializer(final Class<?> type) {
Serializer serializer = null;
if (type.isAnnotationPresent(Serialize.class)) {
Serialize xmlSerializer = type.getAnnotation(Serialize.class);
Expand Down Expand Up @@ -322,8 +314,44 @@ public static <T> T bytesToObject(final byte[] content, final Class<? extends T>
if (serializer == null) {
serializer = getSerializerInstanse(SerializerForJSONOnJSONICImpl.class);
}
return serializer;
}

/**
* 入力をオブジェクトに変換する
*
* @param <T>
* クラスの型
* @param content
* バイト配列
* @param type
* Class
* @return オブジェクト
* @throws SerializeException
* XmlException
*/
public static <T> T bytesToObject(final byte[] content, final Class<? extends T> type) throws SerializeException {
Serializer serializer = getSerializer(type);
return bytesToObject(content, type, serializer);
}

/**
* 入力をオブジェクトに変換する
*
* @param <T>
* クラスの型
* @param content
* バイト配列
* @param type
* Class
* @param serializer
* Serializer
* @return オブジェクト
* @throws SerializeException
* XmlException
*/
public static <T> T bytesToObject(final byte[] content, final Class<? extends T> type, Serializer serializer) throws SerializeException {
return serializer.bytesToObject(content, type);

}

/**
Expand All @@ -335,13 +363,15 @@ public static <T> T bytesToObject(final byte[] content, final Class<? extends T>
* InputStream
* @param type
* Class
* @param serializer
* Serializer
* @return オブジェクト
* @throws SerializeException
* XmlException
* @throws IOException
* IOException
*/
public static <T> T bytesToObject(final InputStream inputStream, final Class<? extends T> type) throws SerializeException, IOException {
public static <T> T bytesToObject(final InputStream inputStream, final Class<? extends T> type, Serializer serializer) throws SerializeException, IOException {
byte[] buf = new byte[256];
ByteArrayOutputStream outputStream = null;
try {
Expand All @@ -350,14 +380,34 @@ public static <T> T bytesToObject(final InputStream inputStream, final Class<? e
while ((n = inputStream.read(buf, 0, buf.length)) != -1) {
outputStream.write(buf, 0, n);
}
return bytesToObject(outputStream.toByteArray(), type);
return bytesToObject(outputStream.toByteArray(), type, serializer);
} finally {
if (outputStream != null) {
outputStream.close();
}
}

}
/**
* 入力(XMLのストリーム)からオブジェクトに変換する
*
* @param <T>
* クラスの型
* @param inputStream
* InputStream
* @param type
* Class
* @return オブジェクト
* @throws SerializeException
* XmlException
* @throws IOException
* IOException
*/
public static <T> T bytesToObject(final InputStream inputStream, final Class<? extends T> type) throws SerializeException, IOException {
Serializer serializer = getSerializer(type);
return bytesToObject(inputStream, type, serializer);
}



/**
* 入力をオブジェクトに変換する
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/org/support/project/common/util/HtmlUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.support.project.common.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.support.project.common.exception.ParseException;

/**
* Utility for HTML.
*
Expand Down Expand Up @@ -76,4 +81,26 @@ public static String escapeHTML(String str) {
return escapeStr.toString();
}

/**
* 指定の文字列を URL に含められるようにエンコードします。
*
* @param str エンコード対象の文字列
* @return エンコード後の文字列
* @throws ParseException UTF-8 がサポートされていない場合
*/
public static String escapeURL(String str) throws ParseException {
if (str == null) {
return null;
}

String encoded;
try {
encoded = URLEncoder.encode(str, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new ParseException(e);
}

return encoded;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ public List<String> getSelectOnSqlFileNames() {
return list;
}
for (ColumnDefinition primary : primaryKeys) {
if (!primary.getColumn_name().toLowerCase().equals("key")) {
list.add(config.getDaoClassName() + "_select_on_" + primary.getColumn_name().toLowerCase() + ".sql");
String col = primary.getColumn_name().toLowerCase();
if (col.equals("key")) {
col = "col_key";
}
list.add(config.getDaoClassName() + "_select_on_" + col + ".sql");
}
return list;
}
Expand All @@ -110,7 +112,11 @@ public List<String> getPhysicalSelectOnSqlFileNames() {
return list;
}
for (ColumnDefinition primary : primaryKeys) {
list.add(config.getDaoClassName() + "_physical_select_on_" + primary.getColumn_name().toLowerCase() + ".sql");
String col = primary.getColumn_name().toLowerCase();
if (col.equals("key")) {
col = "col_key";
}
list.add(config.getDaoClassName() + "_physical_select_on_" + col + ".sql");
}
return list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
import java.util.Collection;
import java.util.List;

import org.support.project.common.config.INT_FLAG;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.common.util.StringUtils;
import org.support.project.ormapping.common.NameConvertor;
import org.support.project.ormapping.entity.ColumnDefinition;
import org.support.project.ormapping.entity.TableDefinition;
import org.support.project.ormapping.tool.DaoGenConfig;

public class DefaultTableSelectMethodCreator {
Expand Down Expand Up @@ -140,10 +137,8 @@ private void writeSelectOn(PrintWriter pw) {
List<String> fileNames = sqlCreator.getSelectOnSqlFileNames();
int idx = 0;
for (ColumnDefinition primary : primaryKeys) {
if (!primary.getColumn_name().toLowerCase().equals("key")) {
String fileName = fileNames.get(idx++);
writeSelectOn(pw, primary, fileName);
}
String fileName = fileNames.get(idx++);
writeSelectOn(pw, primary, fileName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.support.project.common.exception.ParseException;

public class HtmlUtilsTest {

Expand Down Expand Up @@ -36,5 +37,9 @@ public void test2() {
String str = HtmlUtils.escapeHTML("<div style=\"aaa\">aaa</div>");
assertEquals("&lt;div style=&quot;aaa&quot;&gt;aaa&lt;/div&gt;", str);
}

@Test
public void test3() throws ParseException {
String str = HtmlUtils.escapeURL("/&:; あ");
assertEquals("%2F%26%3A%3B+%E3%81%82", str);
}
}

0 comments on commit 5dfbd74

Please sign in to comment.