Browse Source

更多的API

pull/1/head
richie 5 years ago
parent
commit
9a2383421b
  1. 41
      src/main/java/com/fanruan/api/conf/ConfigurationKit.java
  2. 11
      src/main/java/com/fanruan/api/conf/Runner.java
  3. 26
      src/main/java/com/fanruan/api/conf/xml/XmlHolderKit.java
  4. 11
      src/main/java/com/fanruan/api/data/ConnectionKit.java
  5. 4
      src/main/java/com/fanruan/api/data/connection/NameDatabaseConnection.java
  6. 4
      src/main/java/com/fanruan/api/design/ui/component/UIPlaceholderTextField.java
  7. 2
      src/main/java/com/fanruan/api/design/ui/component/UIToolbar.java
  8. 36
      src/main/java/com/fanruan/api/design/ui/toolbar/ToolBarDef.java
  9. 4
      src/main/java/com/fanruan/api/net/CloudKit.java
  10. 16
      src/main/java/com/fanruan/api/util/IOKit.java
  11. 3
      src/test/java/com/fanruan/api/net/http/HttpKitTest.java

41
src/main/java/com/fanruan/api/conf/ConfigurationKit.java

@ -0,0 +1,41 @@
package com.fanruan.api.conf;
import com.fr.config.Configuration;
import com.fr.config.holder.ConfigChangeListener;
import com.fr.transaction.Configurations;
import com.fr.transaction.ValidateProxy;
import com.fr.transaction.WorkerFacade;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
* 配置监听管理器
*/
public class ConfigurationKit {
/**
* 注册监听配置变化的监听器
*
* @param listener 监听器
*/
public static void registerListener(ConfigChangeListener listener) {
ValidateProxy.getInstance().getValidateManager().registerListener(listener);
}
/**
* 保存配置
*
* @param type 配置的类型
* @param action 保存动作
*/
public static void modify(Class<? extends Configuration> type, Runner action) {
Configurations.modify(new WorkerFacade(type) {
@Override
public void run() {
action.run();
}
});
}
}

11
src/main/java/com/fanruan/api/conf/Runner.java

@ -0,0 +1,11 @@
package com.fanruan.api.conf;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
*/
public interface Runner {
void run();
}

26
src/main/java/com/fanruan/api/conf/xml/XmlHolderKit.java

@ -0,0 +1,26 @@
package com.fanruan.api.conf.xml;
import com.fr.config.holder.Conf;
import com.fr.config.holder.impl.xml.XmlConf;
import com.fr.stable.xml.XMLable;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
* 将xml文件写入fine_conf_entity的帮助类不建议使用
*/
public class XmlHolderKit {
/**
* 创建一个要写入配置的xml多项
* @param t 配置对象
* @param clazz 类型
* @param xmlTag xml标签
* @param <T> 类型
* @return 配置对象
*/
public static <T extends XMLable> Conf<T> obj(T t, Class<T> clazz, String xmlTag) {
return new XmlConf(t, clazz, xmlTag);
}
}

11
src/main/java/com/fanruan/api/data/ConnectionKit.java

@ -2,6 +2,7 @@ package com.fanruan.api.data;
import com.fanruan.api.util.TypeKit; import com.fanruan.api.util.TypeKit;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.data.impl.NameDatabaseConnection;
import com.fr.file.ConnectionConfig; import com.fr.file.ConnectionConfig;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -35,4 +36,14 @@ public class ConnectionKit {
} }
return null; return null;
} }
/**
* 生成一个使用名字来引用的数据连接对象
*
* @param name 数据连接的名字
* @return 数据连接
*/
public static Connection createNameConnection(String name) {
return new NameDatabaseConnection(name);
}
} }

4
src/main/java/com/fanruan/api/data/connection/NameDatabaseConnection.java

@ -1,4 +0,0 @@
package com.fanruan.api.data.connection;
public class NameDatabaseConnection extends com.fr.data.impl.NameDatabaseConnection{
}

4
src/main/java/com/fanruan/api/design/ui/component/UIPlaceholderTextField.java

@ -14,6 +14,10 @@ public class UIPlaceholderTextField extends PlaceholderTextField {
super(); super();
} }
public UIPlaceholderTextField(int columns) {
super(columns);
}
public UIPlaceholderTextField(String placeHolder) { public UIPlaceholderTextField(String placeHolder) {
super(); super();
setPlaceholder(placeHolder); setPlaceholder(placeHolder);

2
src/main/java/com/fanruan/api/design/ui/component/UIToolbar.java

@ -1,7 +1,5 @@
package com.fanruan.api.design.ui.component; package com.fanruan.api.design.ui.component;
import com.fr.design.gui.itoolbar.UIToolBarUI;
public class UIToolbar extends com.fr.design.gui.itoolbar.UIToolbar { public class UIToolbar extends com.fr.design.gui.itoolbar.UIToolbar {
public UIToolbar() { public UIToolbar() {

36
src/main/java/com/fanruan/api/design/ui/toolbar/ToolBarDef.java

@ -0,0 +1,36 @@
package com.fanruan.api.design.ui.toolbar;
import com.fanruan.api.design.ui.component.UIToolbar;
import com.fr.design.gui.itoolbar.UIToolBarUI;
import javax.swing.*;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-30
*/
public class ToolBarDef extends com.fr.design.menu.ToolBarDef {
public static UIToolbar createJToolBar(final Color background) {
UIToolbar toolbar = new UIToolbar(FlowLayout.LEFT);
toolbar.setUI(new UIToolBarUI() {
@Override
public void paint(Graphics g, JComponent c) {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(background);
g2.fillRect(0, 0, c.getWidth(), c.getHeight());
}
});
toolbar.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
return toolbar;
}
public static UIToolbar createJToolBar() {
UIToolbar toolbar = new UIToolbar(FlowLayout.LEFT);
toolbar.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
return toolbar;
}
}

4
src/main/java/com/fanruan/api/net/CloudKit.java

@ -20,7 +20,7 @@ public class CloudKit {
* @param defaultSiteUrl 默认值 * @param defaultSiteUrl 默认值
* @return 键对应的值如果没有值则返回默认值 * @return 键对应的值如果没有值则返回默认值
*/ */
public @Nullable String acquireUrlByKind(@NotNull String kind, @NotNull String defaultSiteUrl) { public static @Nullable String acquireUrlByKind(@NotNull String kind, @NotNull String defaultSiteUrl) {
return CloudCenter.getInstance().acquireUrlByKind(kind, defaultSiteUrl); return CloudCenter.getInstance().acquireUrlByKind(kind, defaultSiteUrl);
} }
@ -30,7 +30,7 @@ public class CloudKit {
* @param kind * @param kind
* @return 键对应的值如果没有值则返回空 * @return 键对应的值如果没有值则返回空
*/ */
public @Nullable String acquireUrlByKind(@NotNull String kind) { public static @Nullable String acquireUrlByKind(@NotNull String kind) {
return CloudCenter.getInstance().acquireUrlByKind(kind); return CloudCenter.getInstance().acquireUrlByKind(kind);
} }
} }

16
src/main/java/com/fanruan/api/util/IOKit.java

@ -125,6 +125,19 @@ public class IOKit {
return CommonIOUtils.inputStream2String(is, charset.toString()); return CommonIOUtils.inputStream2String(is, charset.toString());
} }
/**
* 从输入流中按指定的编码读取字符串
*
* @param is 输入流
* @param charset 读取字符串的编码方式
* @return 读取出来的字符串
* @throws UnsupportedEncodingException 编码类型不支持则抛出此异常
*/
public static String inputStream2String(InputStream is, String charset)
throws UnsupportedEncodingException {
return CommonIOUtils.inputStream2String(is, charset);
}
/** /**
* 将输入流转为byte数组 * 将输入流转为byte数组
* <p/> * <p/>
@ -214,6 +227,7 @@ public class IOKit {
/** /**
* 关闭通道 * 关闭通道
*
* @param device 通道 * @param device 通道
*/ */
public static void close(Channel device) { public static void close(Channel device) {
@ -222,6 +236,7 @@ public class IOKit {
/** /**
* 关闭输出流 * 关闭输出流
*
* @param stream 输出流 * @param stream 输出流
*/ */
public static void close(OutputStream stream) { public static void close(OutputStream stream) {
@ -230,6 +245,7 @@ public class IOKit {
/** /**
* 关闭输入流 * 关闭输入流
*
* @param stream 输入流 * @param stream 输入流
*/ */
public static void close(InputStream stream) { public static void close(InputStream stream) {

3
src/test/java/com/fanruan/api/net/http/HttpKitTest.java

@ -1,6 +1,7 @@
package com.fanruan.api.net.http; package com.fanruan.api.net.http;
import com.fanruan.api.Prepare; import com.fanruan.api.Prepare;
import com.fanruan.api.macro.EncodeConstants;
import com.fanruan.api.net.http.rs.HttpRequest; import com.fanruan.api.net.http.rs.HttpRequest;
import com.fanruan.api.net.http.rs.HttpResponseType; import com.fanruan.api.net.http.rs.HttpResponseType;
import com.fanruan.api.net.http.rs.StreamResponseHandle; import com.fanruan.api.net.http.rs.StreamResponseHandle;
@ -72,6 +73,8 @@ public class HttpKitTest extends Prepare {
InputStream in = HttpKit.post("https://cloud.fanruan.com/site", map, HttpResponseType.STREAM); InputStream in = HttpKit.post("https://cloud.fanruan.com/site", map, HttpResponseType.STREAM);
String text = IOKit.inputStream2String(in, StandardCharsets.UTF_8); String text = IOKit.inputStream2String(in, StandardCharsets.UTF_8);
assertEquals("{\"value\":\"http://bbs.fanruan.com/\"}", text); assertEquals("{\"value\":\"http://bbs.fanruan.com/\"}", text);
String text2 = IOKit.inputStream2String(in, EncodeConstants.ENCODING_UTF_8);
assertEquals("{\"value\":\"http://bbs.fanruan.com/\"}", text2);
} catch (SocketTimeoutException ignore) { } catch (SocketTimeoutException ignore) {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

Loading…
Cancel
Save