Browse Source

REPORT-7790 设计器 配置工作目录界面 调整与兼容

master
yaoh.wu 7 years ago
parent
commit
9cdf77e9a5
  1. 34
      designer-base/src/com/fr/design/border/UITitledBorder.java
  2. 15
      designer-base/src/com/fr/design/scrollruler/ModLineBorder.java
  3. 516
      designer-base/src/com/fr/env/EnvListPane.java
  4. 93
      designer-base/src/com/fr/env/LocalEnvPane.java
  5. 555
      designer-base/src/com/fr/env/RemoteEnvPane.java
  6. 228
      designer-base/src/com/fr/env/RemoteEnvURL.java
  7. 199
      designer-base/test/com/fr/env/RemoteEnvURLTest.java

34
designer-base/src/com/fr/design/border/UITitledBorder.java

@ -2,11 +2,13 @@ package com.fr.design.border;
import com.fr.design.constants.UIConstants;
import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import java.awt.Color;
/**
* @author yaohwu
*/
public class UITitledBorder extends TitledBorder {
private static final long serialVersionUID = 1L;
@ -16,15 +18,23 @@ public class UITitledBorder extends TitledBorder {
}
private UITitledBorder(String title) {
super(null, title, 4, 2, null, new Color(1, 159, 222));
init(title);
super(
BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(
0,
0,
5,
0),
new UIRoundedBorder(
UIConstants.TITLED_BORDER_COLOR,
1,
10)
),
title,
TitledBorder.LEADING,
TitledBorder.TOP,
null,
new Color(1, 159, 222)
);
}
private void init(String title){
UIRoundedBorder roundedborder = new UIRoundedBorder(UIConstants.TITLED_BORDER_COLOR, 1, 10);
this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0), roundedborder));
this.setTitle(title);
}
}

15
designer-base/src/com/fr/design/scrollruler/ModLineBorder.java

@ -1,19 +1,15 @@
package com.fr.design.scrollruler;
import com.fr.design.constants.UIConstants;
import javax.swing.border.AbstractBorder;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.border.AbstractBorder;
import com.fr.design.constants.UIConstants;
import com.fr.design.utils.gui.GUICoreUtils;
/**
* ModLineBorder, 显示某几个边框
* august写这个类的人还是对swing的api不熟悉不是已经有一个
* BorderFactory.createMatteBorder(top, left, bottom, right, color)方法了吗
* @author null
*/
public class ModLineBorder extends AbstractBorder {
public static final int TOP = 0x00000001;
@ -71,6 +67,7 @@ public class ModLineBorder extends AbstractBorder {
* @param width the width of the painted border
* @param height the height of the painted border
*/
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Color oldColor = g.getColor();
@ -98,6 +95,7 @@ public class ModLineBorder extends AbstractBorder {
*
* @param c the component for which this border insets value applies
*/
@Override
public Insets getBorderInsets(Component c) {
return getBorderInsets(c, new Insets(
thickness, thickness, thickness, thickness));
@ -109,6 +107,7 @@ public class ModLineBorder extends AbstractBorder {
* @param c the component for which this border insets value applies
* @param insets the object to be reinitialized
*/
@Override
public Insets getBorderInsets(Component c, Insets insets) {
insets.left = insets.top = insets.right = insets.bottom = thickness;

516
designer-base/src/com/fr/env/EnvListPane.java vendored

@ -1,72 +1,33 @@
package com.fr.env;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.*;
import javax.swing.BorderFactory;
import com.fr.design.gui.ilable.UILabel;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import com.fr.base.BaseUtils;
import com.fr.base.Env;
import com.fr.base.FRContext;
import com.fr.general.NameObject;
import com.fr.dav.LocalEnv;
import com.fr.design.DesignerEnvManager;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.dialog.InformationWarnPane;
import com.fr.design.gui.controlpane.JListControlPane;
import com.fr.design.gui.controlpane.NameObjectCreator;
import com.fr.design.gui.controlpane.NameableCreator;
import com.fr.design.gui.ipasswordfield.UIPassWordField;
import com.fr.design.gui.itree.filetree.JFileTree;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.itextarea.UITextArea;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.scrollruler.ModLineBorder;
import com.fr.file.filter.OnlyShowDirectoryFileFilter;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.general.NameObject;
import com.fr.stable.Nameable;
import com.fr.stable.ProductConstants;
import com.fr.stable.StringUtils;
import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
/**
* @author yaohwu
*/
public class EnvListPane extends JListControlPane {
public EnvListPane() {
super();
addEditingListner(new PropertyChangeAdapter() {
@Override
public void propertyChange() {
String tempName = getEditingName();
String[] allListNames = nameableList.getAllNames();
@ -85,7 +46,6 @@ public class EnvListPane extends JListControlPane {
nameableList.stopEditing();
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(EnvListPane.this), Inter.getLocText(waning, sign));
setWarnigText(editingIndex);
return;
}
}
});
@ -96,6 +56,7 @@ public class EnvListPane extends JListControlPane {
*
* @return 返回添加按钮的NameableCreator
*/
@Override
public NameableCreator[] createNameableCreators() {
NameableCreator local = new NameObjectCreator(Inter.getLocText("Env-Local_Directory"), "com/fr/design/images/data/bind/localconnect.png",
LocalEnv.class, LocalEnvPane.class);
@ -117,14 +78,13 @@ public class EnvListPane extends JListControlPane {
public void populateEnvManager(String selectedEnv) {
DesignerEnvManager mgr = DesignerEnvManager.getEnvManager();
Iterator<String> nameIt = mgr.getEnvNameIterator();
List<NameObject> nameObjectList = new ArrayList<NameObject>();
nameIt.hasNext();
List<NameObject> nameObjectList = new ArrayList<>();
while (nameIt.hasNext()) {
String name = nameIt.next();
nameObjectList.add(new NameObject(name, mgr.getEnv(name)));
}
this.populate(nameObjectList.toArray(new NameObject[nameObjectList.size()]));
this.populate(nameObjectList.toArray(new NameObject[0]));
if (StringUtils.isBlank(selectedEnv)) {
selectedEnv = mgr.getCurEnvName();
@ -142,452 +102,10 @@ public class EnvListPane extends JListControlPane {
DesignerEnvManager mgr = DesignerEnvManager.getEnvManager();
mgr.clearAllEnv();
Nameable[] res = this.update();
NameObject[] envNameObjectArray = new NameObject[res.length];
java.util.Arrays.asList(res).toArray(envNameObjectArray);
for (int i = 0; i < envNameObjectArray.length; i++) {
NameObject nameObject = envNameObjectArray[i];
for (Nameable re : res) {
NameObject nameObject = (NameObject) re;
mgr.putEnv(nameObject.getName(), (Env) nameObject.getObject());
}
return this.getSelectedName();
}
public static class LocalEnvPane extends BasicBeanPane<LocalEnv> {
private UITextField pathTextField;
private JFileTree localEnvTree;
public LocalEnvPane() {
this.setLayout(FRGUIPaneFactory.createM_BorderLayout());
// northPane
JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
this.add(northPane, BorderLayout.NORTH);
northPane.add(new UILabel(Inter.getLocText("Location") + ":"), BorderLayout.WEST);
northPane.add(pathTextField = new UITextField(), BorderLayout.CENTER);
// 删除选择文件按钮 添加JFileTree
// centerPane
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
this.add(centerPane, BorderLayout.CENTER);
// 添加JFileTree
localEnvTree = new JFileTree();
JScrollPane localEnvPane = new JScrollPane(localEnvTree);
centerPane.add(localEnvPane, BorderLayout.CENTER);
// 设置根路径File 和 文件过滤类型
localEnvTree.setFileFilter(new OnlyShowDirectoryFileFilter());
localEnvTree.setRootFiles(File.listRoots());
localEnvTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
pathTextField.setText(localEnvTree.getSelectedFile().getPath());
}
});
UITextArea description = new UITextArea();
centerPane.add(description, BorderLayout.SOUTH);
description.setText(Inter.getLocText("Env-Des1"));
description.setEditable(false);
}
@Override
protected String title4PopupWindow() {
return Inter.getLocText("Location");
}
@Override
public LocalEnv updateBean() {
String path = pathTextField.getText();
return LocalEnv.createEnv(path);
}
public String getPath() {
return pathTextField.getText();
}
@Override
public void populateBean(LocalEnv ob) {
if (StringUtils.isBlank(ob.getPath())) {
return;
}
pathTextField.setText(ob.getPath());
final File tmpFile = new File(ob.getPath());
localEnvTree.selectFile(tmpFile);
localEnvTree.setEnabled(true);
}
}
public static class RemoteEnvPane extends BasicBeanPane<RemoteEnv> {
public static final int HTTPS_HOST_INDEX = 8;
public static final int HTTP_HOST_INDEX = 7;
private UICheckBox httpsCheckBox = new UICheckBox(Inter.getLocText("FR-Designer_Https_Enable"));
private UITextField servletPathField = new UITextField();
private UITextField hostNameField = new UITextField();
private UITextField portNameField = new UITextField();
private UITextField webApplyField = new UITextField();
private UITextField servletField = new UITextField();
private UITextField userTextField = new UITextField();
private UIPassWordField passwordTextField = new UIPassWordField();
private UITextField certificatePath = new UITextField();
private UIPassWordField certificatePass = new UIPassWordField();
private UIButton chooseDirBtn = new UIButton("...");
private String envPath;
private String hint;
// 各种参数面板
private JPanel northPane;
// 提示面板
private JPanel previewPane;
// 面板的所有组件
private Component[][] coms;
DocumentListener docListener = new DocumentListener() {
@Override
public void changedUpdate(DocumentEvent e) {
showServletPathField(httpsCheckBox.isSelected());
}
@Override
public void insertUpdate(DocumentEvent e) {
showServletPathField(httpsCheckBox.isSelected());
}
@Override
public void removeUpdate(DocumentEvent e) {
showServletPathField(httpsCheckBox.isSelected());
}
};
private void setHttpsState(boolean enable){
chooseDirBtn.setEnabled(enable);
DesignerEnvManager.getEnvManager().setHttps(enable);
}
public RemoteEnvPane() {
this.setBorder(BorderFactory.createTitledBorder(new ModLineBorder(ModLineBorder.TOP), Inter.getLocText("Config_Servlet")));
this.setLayout(FRGUIPaneFactory.createM_BorderLayout());
// 位置
JPanel servletPathPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
servletPathPane.add(new UILabel(Inter.getLocText("Server_Path") + ":"));
servletPathField.setEditable(false);
hostNameField.getDocument().addDocumentListener(docListener);
portNameField.getDocument().addDocumentListener(docListener);
webApplyField.getDocument().addDocumentListener(docListener);
servletField.getDocument().addDocumentListener(docListener);
// 主机名
JPanel servletNamePane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
servletNamePane.add(new UILabel(Inter.getLocText("Host_Name") + "/IP" + ":"));
// 端口
JPanel portNamePane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
portNamePane.add(new UILabel(Inter.getLocText("Port") + ":"));
// web应用
JPanel webApplyPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
webApplyPane.add(new UILabel(Inter.getLocText("Web_Apply") + ":"));
// servlet
JPanel servletPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
servletPane.add(new UILabel("Servlet" + ":"));
// 用户名
JPanel userNamePane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
userNamePane.add(new UILabel(Inter.getLocText("Username") + ":"));
// 密码
JPanel passWordPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
passWordPane.add(new UILabel(Inter.getLocText("Password") + ":"));
// https证书路径
JPanel certificatePathPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
certificatePathPane.add(new UILabel(Inter.getLocText("FR-Designer_Certificate_Path")+ ":"));
// https秘钥
JPanel certificatePassPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
certificatePassPane.add(new UILabel(Inter.getLocText("FR-Designer_Certificate_Pass") + ":"));
//输入密码的时候检测下大写锁定
passwordTextField.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
if (java.awt.Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK)) {
hint = Inter.getLocText("CapsLock");
} else {
hint = null;
}
ToolTipManager.sharedInstance().setInitialDelay(100);
passwordTextField.setToolTipText(hint);
}
});
coms = new Component[][]{
new Component[]{initHttpsCheckBoxPane(),new UILabel()},
new Component[]{servletPathPane, initServletNameToolBar()},
new Component[]{servletNamePane, hostNameField},
new Component[]{portNamePane, portNameField},
new Component[]{webApplyPane, webApplyField},
new Component[]{servletPane, servletField},
new Component[]{userNamePane, userTextField},
new Component[]{passWordPane, passwordTextField},
new Component[]{certificatePathPane,initHttpsPane()},
new Component[]{certificatePassPane,certificatePass}
};
setHttpsState(httpsCheckBox.isSelected());
initNorthPane(true);
initCenterPane();
this.add(northPane, BorderLayout.NORTH);
this.add(previewPane, BorderLayout.CENTER);
}
private JToolBar initServletNameToolBar(){
JToolBar servletNameToolBar = new JToolBar();
servletNameToolBar.setFloatable(false);
servletNameToolBar.setLayout(FRGUIPaneFactory.createBorderLayout());
servletNameToolBar.add(this.servletPathField);
UIButton testConnctionButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/m_web/cache.png"));
testConnctionButton.setToolTipText(Inter.getLocText("Datasource-Test_Connection"));
servletNameToolBar.add(testConnctionButton, BorderLayout.EAST);
testConnctionButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
if (testConnection()) {
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(RemoteEnvPane.this), Inter.getLocText("Datasource-Connection_successfully"));
}
}
});
return servletNameToolBar;
}
private void initCenterPane(){
// centerPane
previewPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
previewPane.setBorder(BorderFactory.createTitledBorder(new ModLineBorder(ModLineBorder.TOP), Inter.getLocText("Note")));
JTextPane previewTextArea = new JTextPane();
// e:当行的长度大于所分配的宽度时,将换行.
// previewTextArea.setLineWrap(true);
previewTextArea.setEditable(false);
previewTextArea.setText(Inter.getLocText("Env-Des2"));
try {
previewTextArea.getDocument().insertString(previewTextArea.getText().length(), Inter.getLocText("Env_Des"), this.getRedSytleAttribute());
previewTextArea.getDocument().insertString(previewTextArea.getText().length(), "\n" + Inter.getLocText("FR-Designer_Env_Des_Https"), this.getRedSytleAttribute());
} catch (BadLocationException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
previewPane.add(new JScrollPane(previewTextArea), BorderLayout.CENTER);
}
@Override
protected String title4PopupWindow() {
return "Remote";
}
private JPanel initHttpsPane(){
JPanel httpsPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
httpsPane.setLayout(FRGUIPaneFactory.createBorderLayout());
httpsPane.add(certificatePath,BorderLayout.CENTER);
httpsPane.add(chooseDirBtn, BorderLayout.EAST);
chooseDirBtn.setPreferredSize(new Dimension(25, 25));
chooseDirBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int saveValue = fileChooser.showOpenDialog(DesignerContext.getDesignerFrame());
if (saveValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
certificatePath.setText(selectedFile.getAbsolutePath());
}
}
});
return httpsPane;
}
private JPanel initHttpsCheckBoxPane(){
JPanel checkBoxPane = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
checkBoxPane.add(httpsCheckBox);
httpsCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
boolean isHttps = httpsCheckBox.isSelected();
DesignerEnvManager manager = DesignerEnvManager.getEnvManager();
manager.setHttps(isHttps);
setHttpsState(isHttps);
updateNorthPane(isHttps);
}
});
return checkBoxPane;
}
private void setHttpsParas(){
System.setProperty("javax.net.ssl.trustStore", this.certificatePath.getText());
System.setProperty("javax.net.ssl.trustStorePassword", new String(this.certificatePass.getPassword()));
DesignerEnvManager manager = DesignerEnvManager.getEnvManager();
manager.setCertificatePath(this.certificatePath.getText());
manager.setCertificatePass(new String(this.certificatePass.getPassword()));
manager.setHttps(this.httpsCheckBox.isSelected());
}
private boolean testConnection() {
RemoteEnv env = new RemoteEnv();
String url = servletPathField.getText();
env.setPath(url);
env.setUser(userTextField.getText());
env.setPassword(new String(passwordTextField.getPassword()));
boolean connect = false;
try {
if (!StringUtils.isBlank(servletPathField.getText().trim())) {
if(url.startsWith("https:") && !this.httpsCheckBox.isSelected()){
JOptionPane.showMessageDialog(this, Inter.getLocText("Datasource-Connection_failed"));
return false;
}
if(url.startsWith("https:")){
setHttpsParas();
}
connect = env.testConnectionWithOutRegisteServer(this);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, Inter.getLocText("Datasource-Connection_failed"));
FRContext.getLogger().error(e.getMessage(), e);
}
if (connect) {
try {
String remoteVersion = env.getDesignerVersion();
if (StringUtils.isBlank(remoteVersion) || ComparatorUtils.compare(remoteVersion, ProductConstants.DESIGNER_VERSION) < 0) {
String infor = Inter.getLocText("Server-version-tip") + "。";
String moreInfo = Inter.getLocText("Server-version-tip-moreInfo") + "。";
new InformationWarnPane(infor, moreInfo, Inter.getLocText("Tooltips")).show();
return false;
}
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
return connect;
}
private AttributeSet getRedSytleAttribute() {
SimpleAttributeSet ds = new SimpleAttributeSet();
StyleConstants.setForeground(ds, Color.red);
return ds;
}
/**
* 显示show the content of serverPathFiled
* @param isHttps 是否启用https
*/
public void showServletPathField(boolean isHttps) {
String s = StringUtils.isBlank(webApplyField.getText()) ? "" : "/", t = StringUtils.isBlank(servletField.getText()) ? "" : "/", colon = StringUtils.isBlank(portNameField.getText()) ? ""
: ":";
String prefix = isHttps ? "https://" : "http://";
servletPathField.setText(prefix + hostNameField.getText() + colon + portNameField.getText() + s + webApplyField.getText() + t + servletField.getText());
}
@Override
public void populateBean(RemoteEnv ob) {
envPath = ob.getPath();
boolean isHttps = false;
if(envPath != null){
isHttps = envPath.startsWith("https");
httpsCheckBox.setSelected(isHttps);
setHttpsState(isHttps);
}
updateNorthPane(isHttps);
if (envPath == null || ComparatorUtils.equals(envPath, StringUtils.EMPTY)) {
this.hostNameField.setText(StringUtils.EMPTY);
this.portNameField.setText(StringUtils.EMPTY);
this.webApplyField.setText(StringUtils.EMPTY);
this.servletField.setText(StringUtils.EMPTY);
this.servletPathField.setText(StringUtils.EMPTY);
this.httpsCheckBox.setSelected(false);
} else {
DesignerEnvManager manager = DesignerEnvManager.getEnvManager();
this.certificatePath.setText(manager.getCertificatePath());
this.certificatePass.setText(manager.getCertificatePass());
// 第二次出现":"的地方,port位置起始点
int secondTime = envPath.indexOf(":", envPath.indexOf(":") + 1);
// 第三次出现"/"的地方
int thirdTime = envPath.indexOf("/", secondTime + 1);
// 最后出现"/"的地方
int lastTime = envPath.lastIndexOf("/");
String hostName = isHttps ? envPath.substring(HTTPS_HOST_INDEX, secondTime) : envPath.substring(HTTP_HOST_INDEX, secondTime);
this.hostNameField.setText(hostName);
if (thirdTime < 0) {
this.portNameField.setText(envPath.substring(secondTime + 1));
this.webApplyField.setText(StringUtils.EMPTY);
} else {
this.portNameField.setText(envPath.substring(secondTime + 1, thirdTime));
if (thirdTime == lastTime) {
this.webApplyField.setText(StringUtils.EMPTY);
} else {
this.webApplyField.setText(envPath.substring(thirdTime + 1, lastTime));
}
this.servletField.setText(envPath.substring(lastTime + 1));
}
this.servletPathField.setText(envPath);
}
this.userTextField.setText(ob.getUser() == null ? StringUtils.EMPTY : ob.getUser());
this.passwordTextField.setText(ob.getPassword() == null ? StringUtils.EMPTY : ob.getPassword());
}
private void initNorthPane(boolean isHttps){
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double[] rowSize;
double[] size = {p,p,p,p,p,p,p,p};
double[] httpsSize = {p,p,p,p,p,p,p,p,p,p};
if(isHttps){
rowSize = httpsSize;
}else{
rowSize = size;
}
double[] columnSize = {p, f};
northPane = TableLayoutHelper.createTableLayoutPane(coms, rowSize, columnSize);
}
private void updateNorthPane(boolean isHttps){
this.removeAll();
initNorthPane(isHttps);
this.add(northPane, BorderLayout.NORTH);
this.add(previewPane,BorderLayout.CENTER);
this.revalidate();
this.doLayout();
this.repaint();
}
@Override
public RemoteEnv updateBean() {
String hostName = this.hostNameField.getText();
// String port = this.portNameField.getText();
String webApply = this.webApplyField.getText();
String servlet = this.servletField.getText();
String path = this.servletPathField.getText();
String user = this.userTextField.getText();
String password = new String(this.passwordTextField.getPassword());
if (isAllEmpty(new String[]{hostName, webApply, servlet})) {
path = StringUtils.EMPTY;
}
return new RemoteEnv(path, user, password);
}
private boolean isAllEmpty(String[] strs) {
for (int i = 0; i < strs.length; i++) {
if (StringUtils.isNotEmpty(strs[i])) {
return false;
}
}
return true;
}
}
}

93
designer-base/src/com/fr/env/LocalEnvPane.java vendored

@ -0,0 +1,93 @@
package com.fr.env;
import com.fr.dav.LocalEnv;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextarea.UITextArea;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.gui.itree.filetree.JFileTree;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.file.filter.OnlyShowDirectoryFileFilter;
import com.fr.general.Inter;
import com.fr.stable.StringUtils;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import java.awt.BorderLayout;
import java.io.File;
/**
* @author yaohwu
*/
public class LocalEnvPane extends BasicBeanPane<LocalEnv> {
private UITextField pathTextField;
private JFileTree localEnvTree;
public LocalEnvPane() {
this.setLayout(FRGUIPaneFactory.createM_BorderLayout());
// northPane
JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
this.add(northPane, BorderLayout.NORTH);
northPane.add(new UILabel(Inter.getLocText("Location") + ":"), BorderLayout.WEST);
northPane.add(pathTextField = new UITextField(), BorderLayout.CENTER);
// 删除选择文件按钮 添加JFileTree
// centerPane
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
this.add(centerPane, BorderLayout.CENTER);
// 添加JFileTree
localEnvTree = new JFileTree();
JScrollPane localEnvPane = new JScrollPane(localEnvTree);
centerPane.add(localEnvPane, BorderLayout.CENTER);
// 设置根路径File 和 文件过滤类型
localEnvTree.setFileFilter(new OnlyShowDirectoryFileFilter());
localEnvTree.setRootFiles(File.listRoots());
localEnvTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
pathTextField.setText(localEnvTree.getSelectedFile().getPath());
}
});
UITextArea description = new UITextArea();
centerPane.add(description, BorderLayout.SOUTH);
description.setText(Inter.getLocText("Env-Des1"));
description.setEditable(false);
}
@Override
protected String title4PopupWindow() {
return Inter.getLocText("Location");
}
@Override
public LocalEnv updateBean() {
String path = pathTextField.getText();
return LocalEnv.createEnv(path);
}
public String getPath() {
return pathTextField.getText();
}
@Override
public void populateBean(LocalEnv ob) {
if (StringUtils.isBlank(ob.getPath())) {
return;
}
pathTextField.setText(ob.getPath());
final File tmpFile = new File(ob.getPath());
localEnvTree.selectFile(tmpFile);
localEnvTree.setEnabled(true);
}
}

555
designer-base/src/com/fr/env/RemoteEnvPane.java vendored

@ -0,0 +1,555 @@
package com.fr.env;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.border.UITitledBorder;
import com.fr.design.dialog.InformationWarnPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ipasswordfield.UIPassWordField;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.scrollruler.ModLineBorder;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.stable.ProductConstants;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import static com.fr.design.layout.TableLayout.FILL;
import static com.fr.design.layout.TableLayout.PREFERRED;
/**
* @author yaohwu
*/
public class RemoteEnvPane extends BasicBeanPane<RemoteEnv> {
private static final Color TIPS_FONT_COLOR = new Color(0x8f8f92);
/**
* 是否启用 https 勾选框
*/
private UICheckBox httpsCheckbox = new UICheckBox(Inter.getLocText("FR-Designer_RemoteEnv_Enable_Https"));
/**
* 主机位置输入框
*/
private UITextField remoteEnvURLInput = new UITextField();
/**
* 主机名输入框
*/
private UITextField hostNameInput = new UITextField();
/**
* 端口输入框
*/
private UITextField portInput = new UITextField();
/**
* Web 应用名输入框
*/
private UITextField webAppNameInput = new UITextField();
/**
* Servlet 名称输入框
*/
private UITextField servletNameInput = new UITextField();
/**
* 用户名
*/
private UITextField usernameInput = new UITextField();
/**
* 密码
*/
private UIPassWordField passwordInput = new UIPassWordField();
/**
* https证书路径
*/
private UITextField certPathInput = new UITextField();
/**
* https密钥
*/
private UIPassWordField certSecretKeyInput = new UIPassWordField();
/**
* 选择证书文件按钮
*/
private UIButton fileChooserButton = new UIButton("...");
/**
* 主机位置
*/
private RemoteEnvURL remoteEnvURL;
/**
* https 配置面板
*/
private JPanel httpsConfigPanel;
/**
* https 密钥标签
*/
private UILabel certSecretKeyLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Https_Secret_Key"));
/**
* https证书路径标签
*/
private UILabel certPathLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Https_Cert_Path"));
/**
* https 证书路径输入框
*/
private JPanel httpsCertFileInputPanel;
/**
* 主机名web应用Servlet端口监听器
*/
private DocumentListener individualDocListener = new DocumentListener() {
@Override
public void changedUpdate(DocumentEvent e) {
updateRemoteURL();
fillRemoteEnvURLField();
}
@Override
public void insertUpdate(DocumentEvent e) {
updateRemoteURL();
fillRemoteEnvURLField();
}
@Override
public void removeUpdate(DocumentEvent e) {
updateRemoteURL();
fillRemoteEnvURLField();
}
};
/**
* 路径输入框监听器
*/
private DocumentListener overallDocListener = new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
actionURLInputChange();
}
@Override
public void removeUpdate(DocumentEvent e) {
actionURLInputChange();
}
@Override
public void changedUpdate(DocumentEvent e) {
actionURLInputChange();
}
};
/**
* https checkbox listener
*/
private ActionListener httpsCheckboxListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
boolean isHttps = httpsCheckbox.isSelected();
DesignerEnvManager.getEnvManager().setHttps(isHttps);
fileChooserButton.setEnabled(isHttps);
updateHttpsConfigPanel();
remoteEnvURL.setHttps(isHttps);
fillRemoteEnvURLField();
fillIndividualField();
}
};
public RemoteEnvPane() {
// 配置内容面板
JPanel contentPanel = new JPanel(new BorderLayout());
contentPanel.setBorder(
BorderFactory.createCompoundBorder(
new EmptyBorder(6, 0, 0, 0),
UITitledBorder.createBorderWithTitle(Inter.getLocText("FR-Designer_RemoteEnv_Config")))
);
// 服务器地址地址
JPanel configPanel = new JPanel(new BorderLayout());
configPanel.setBorder(
BorderFactory.createCompoundBorder(
new EmptyBorder(15, 0, 0, 0),
BorderFactory.createTitledBorder(
new ModLineBorder(ModLineBorder.TOP),
Inter.getLocText("FR-Designer_RemoteEnv_Server")
)
)
);
certPathLabel.setHorizontalAlignment(SwingConstants.RIGHT);
certSecretKeyLabel.setHorizontalAlignment(SwingConstants.RIGHT);
packConfigPanel(configPanel);
// 服务器账号配置
JPanel accountPanel = new JPanel(new BorderLayout());
accountPanel.setBorder(BorderFactory.createCompoundBorder(
new EmptyBorder(15, 0, 0, 0),
BorderFactory.createTitledBorder(
new ModLineBorder(ModLineBorder.TOP),
Inter.getLocText("FR-Designer_RemoteEnv_Platform_Account")
)
));
packAccountPanel(accountPanel);
// 测试链接按钮
JPanel testPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
testPanel.setBorder(BorderFactory.createEmptyBorder());
testPanel.setPreferredSize(new Dimension(437, 20));
UIButton testConnectionButton = new UIButton(Inter.getLocText("FR-Designer_RemoteEnv_Test_Connection"));
testConnectionButton.setToolTipText(Inter.getLocText("Datasource-Test_Connection"));
testConnectionButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
if (testConnection()) {
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(RemoteEnvPane.this), Inter.getLocText("Datasource-Connection_successfully"));
}
}
});
testPanel.add(testConnectionButton);
contentPanel.add(configPanel, BorderLayout.NORTH);
contentPanel.add(accountPanel, BorderLayout.CENTER);
this.setLayout(new BorderLayout());
this.add(contentPanel, BorderLayout.NORTH);
this.add(testPanel, BorderLayout.CENTER);
}
@Override
public void populateBean(RemoteEnv ob) {
if (StringUtils.isEmpty(ob.getPath())) {
remoteEnvURL = RemoteEnvURL.createDefaultURL();
} else {
remoteEnvURL = new RemoteEnvURL(ob.getPath());
}
fillRemoteEnvURLField();
fillIndividualField();
httpsCheckbox.setSelected(remoteEnvURL.getHttps());
DesignerEnvManager.getEnvManager().setHttps(remoteEnvURL.getHttps());
fileChooserButton.setEnabled(remoteEnvURL.getHttps());
updateHttpsConfigPanel();
this.usernameInput.setText(ob.getUser() == null ? StringUtils.EMPTY : ob.getUser());
this.passwordInput.setText(ob.getPassword() == null ? StringUtils.EMPTY : ob.getPassword());
}
@Override
public RemoteEnv updateBean() {
String path = remoteEnvURL.getURL();
String user = this.usernameInput.getText();
String password = new String(this.passwordInput.getPassword());
return new RemoteEnv(path, user, password);
}
@Override
protected String title4PopupWindow() {
return "Remote";
}
private void packConfigPanel(JPanel configPanel) {
// 主机名
UILabel hostNameLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Host_IP"));
hostNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
// 端口
UILabel portLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Port"));
portLabel.setHorizontalAlignment(SwingConstants.RIGHT);
// web应用
UILabel webAppNameLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Web_Name"));
webAppNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
// servlet
UILabel servletNameLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Servlet_Name"));
servletNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
// 主机位置
UILabel remoteEnvURLLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_URL"));
remoteEnvURLLabel.setHorizontalAlignment(SwingConstants.RIGHT);
enableSubDocListener();
JPanel urlPanel = TableLayoutHelper.createGapTableLayoutPane(
new Component[][]{
new Component[]{hostNameLabel, hostNameInput},
new Component[]{portLabel, portInput},
new Component[]{webAppNameLabel, webAppNameInput},
new Component[]{servletNameLabel, servletNameInput},
new Component[]{remoteEnvURLLabel, remoteEnvURLInput}
},
new double[]{PREFERRED, PREFERRED, PREFERRED, PREFERRED, PREFERRED},
new double[]{PREFERRED, FILL},
5,
10
);
TableLayoutHelper.modifyTableLayoutIndexVGap(urlPanel, 0, 10);
JTextPane urlTipsPane = new JTextPane();
urlTipsPane.setEditable(false);
urlTipsPane.setText(Inter.getLocText("FR-Designer_RemoteEnv_Server_Config_Tips"));
urlTipsPane.setBackground(urlPanel.getBackground());
urlTipsPane.setForeground(TIPS_FONT_COLOR);
httpsCheckbox.addActionListener(httpsCheckboxListener);
// 初始化 https 可被刷新展示的面板
httpsConfigPanel = new JPanel(new BorderLayout());
// 初始化 https 证书文件输入框
httpsCertFileInputPanel = createHttpsCertFileInputPanel();
packHttpsConfigPanel();
JTextPane httpsTipsPane = new JTextPane();
httpsTipsPane.setEditable(false);
httpsTipsPane.setText(Inter.getLocText("FR-Designer_RemoteEnv_Https_Tips"));
httpsTipsPane.setBackground(configPanel.getBackground());
httpsTipsPane.setForeground(TIPS_FONT_COLOR);
configPanel.add(TableLayoutHelper.createTableLayoutPane(
new Component[][]{
new Component[]{urlPanel},
new Component[]{urlTipsPane},
new Component[]{httpsConfigPanel},
new Component[]{httpsTipsPane}
},
new double[]{PREFERRED, PREFERRED, PREFERRED, PREFERRED},
new double[]{FILL}
));
}
private void enableSubDocListener() {
hostNameInput.getDocument().addDocumentListener(individualDocListener);
portInput.getDocument().addDocumentListener(individualDocListener);
webAppNameInput.getDocument().addDocumentListener(individualDocListener);
servletNameInput.getDocument().addDocumentListener(individualDocListener);
}
private void disableSubDocListener() {
hostNameInput.getDocument().removeDocumentListener(individualDocListener);
portInput.getDocument().removeDocumentListener(individualDocListener);
webAppNameInput.getDocument().removeDocumentListener(individualDocListener);
servletNameInput.getDocument().removeDocumentListener(individualDocListener);
}
private void packHttpsConfigPanel() {
double[] rows = new double[]{PREFERRED};
boolean httpsEnabled = httpsCheckbox.isSelected();
if (httpsEnabled) {
rows = new double[]{PREFERRED, PREFERRED, PREFERRED};
}
JPanel content = TableLayoutHelper.createGapTableLayoutPane(
new Component[][]{
new Component[]{httpsCheckbox, new JPanel()},
new Component[]{certPathLabel, httpsCertFileInputPanel},
new Component[]{certSecretKeyLabel, certSecretKeyInput}
},
rows,
new double[]{PREFERRED, FILL},
5,
10
);
httpsConfigPanel.add(content, BorderLayout.CENTER);
}
private void packAccountPanel(JPanel accountPanel) {
// 用户名
UILabel userNameLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Account_Username"));
userNameLabel.setHorizontalAlignment(SwingConstants.RIGHT);
// 密码
UILabel passwordLabel = new UILabel(Inter.getLocText("FR-Designer_RemoteEnv_Account_Password"));
passwordLabel.setHorizontalAlignment(SwingConstants.RIGHT);
//输入密码的时候检测下大写锁定
passwordInput.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
if (Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK)) {
passwordInput.setToolTipText(Inter.getLocText("CapsLock"));
} else {
passwordInput.setToolTipText(null);
}
ToolTipManager.sharedInstance().setInitialDelay(100);
}
});
Component[][] accountComponents = new Component[][]{
new Component[]{userNameLabel, usernameInput},
new Component[]{passwordLabel, passwordInput}
};
JPanel content = TableLayoutHelper.createGapTableLayoutPane(accountComponents,
new double[]{PREFERRED, PREFERRED},
new double[]{PREFERRED, FILL},
5,
10
);
TableLayoutHelper.modifyTableLayoutIndexVGap(content, 0, 10);
accountPanel.add(content, BorderLayout.CENTER);
}
private JPanel createHttpsCertFileInputPanel() {
JPanel inputPanel = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane();
inputPanel.setLayout(FRGUIPaneFactory.createBorderLayout());
inputPanel.add(certPathInput, BorderLayout.CENTER);
inputPanel.add(fileChooserButton, BorderLayout.EAST);
fileChooserButton.setPreferredSize(new Dimension(20, 20));
fileChooserButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int saveValue = fileChooser.showOpenDialog(SwingUtilities.getWindowAncestor(RemoteEnvPane.this));
if (saveValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
certPathInput.setText(selectedFile.getAbsolutePath());
}
}
});
return inputPanel;
}
private void setHttpsParas() {
System.setProperty("javax.net.ssl.trustStore", this.certPathInput.getText());
System.setProperty("javax.net.ssl.trustStorePassword", new String(this.certSecretKeyInput.getPassword()));
DesignerEnvManager manager = DesignerEnvManager.getEnvManager();
manager.setCertificatePath(this.certPathInput.getText());
manager.setCertificatePass(new String(this.certSecretKeyInput.getPassword()));
manager.setHttps(this.httpsCheckbox.isSelected());
}
private boolean testConnection() {
RemoteEnv env = new RemoteEnv();
String url = remoteEnvURL.getURL();
env.setPath(url);
env.setUser(usernameInput.getText());
env.setPassword(new String(passwordInput.getPassword()));
boolean connect = false;
try {
if (StringUtils.isNotEmpty(url)) {
if (remoteEnvURL.getHttps()) {
setHttpsParas();
}
connect = env.testConnectionWithOutRegisteServer(this);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, Inter.getLocText("Datasource-Connection_failed"));
FRContext.getLogger().error(e.getMessage(), e);
}
if (connect) {
try {
String remoteVersion = env.getDesignerVersion();
if (StringUtils.isBlank(remoteVersion) || ComparatorUtils.compare(remoteVersion, ProductConstants.DESIGNER_VERSION) < 0) {
String info = Inter.getLocText("Server-version-tip") + "。";
String moreInfo = Inter.getLocText("Server-version-tip-moreInfo") + "。";
new InformationWarnPane(info, moreInfo, Inter.getLocText("Tooltips")).show();
return false;
}
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
return connect;
}
/**
* 自动填充主机位置输入框
*/
private void fillRemoteEnvURLField() {
remoteEnvURLInput.getDocument().removeDocumentListener(overallDocListener);
remoteEnvURLInput.setText(remoteEnvURL.getURL());
remoteEnvURLInput.getDocument().addDocumentListener(overallDocListener);
}
/**
* 自动填充子条目输入框
*/
private void fillIndividualField() {
if (remoteEnvURL == null) {
return;
}
disableSubDocListener();
hostNameInput.setText(remoteEnvURL.hasDefaultHostName() ? StringUtils.EMPTY : remoteEnvURL.getHost());
portInput.setText(remoteEnvURL.getPort());
webAppNameInput.setText(remoteEnvURL.getWeb());
servletNameInput.setText(remoteEnvURL.getServlet());
enableSubDocListener();
}
private void updateRemoteURL() {
boolean isHttps = httpsCheckbox.isSelected();
String host = hostNameInput.getText();
String port = portInput.getText();
String web = webAppNameInput.getText();
String servlet = servletNameInput.getText();
remoteEnvURL.setHttps(isHttps);
remoteEnvURL.setHost(host);
remoteEnvURL.setPort(port);
remoteEnvURL.setWeb(web);
remoteEnvURL.setServlet(servlet);
}
private void updateHttpsConfigPanel() {
httpsConfigPanel.removeAll();
packHttpsConfigPanel();
httpsConfigPanel.revalidate();
httpsConfigPanel.repaint();
}
private void actionURLInputChange() {
remoteEnvURL = new RemoteEnvURL(remoteEnvURLInput.getText());
fillIndividualField();
httpsCheckbox.setSelected(remoteEnvURL.getHttps());
boolean isHttps = httpsCheckbox.isSelected();
DesignerEnvManager.getEnvManager().setHttps(isHttps);
fileChooserButton.setEnabled(isHttps);
updateHttpsConfigPanel();
}
}

228
designer-base/src/com/fr/env/RemoteEnvURL.java vendored

@ -0,0 +1,228 @@
package com.fr.env;
import com.fr.stable.FCloneable;
import com.fr.stable.StringUtils;
import java.util.Objects;
/**
* @author yaohwu
*/
public class RemoteEnvURL implements FCloneable {
/**
* 默认 hostname
*/
private static final String DEFAULT_HOST_NAME = "${IP}";
/**
* 默认 web app name
*/
private static final String DEFAULT_WEB_APP_NAME = "WebReport";
/**
* 默认 servlet name
*/
private static final String DEFAULT_SERVLET_NAME = "ReportServer";
/**
* 默认端口
*/
private static final String DEFAULT_PORT = "8080";
private static final String HTTPS = "https://";
private static final String HTTP = "http://";
public static final RemoteEnvURL DEFAULT_URL =
new RemoteEnvURL(
false,
DEFAULT_HOST_NAME,
DEFAULT_PORT,
DEFAULT_WEB_APP_NAME,
DEFAULT_SERVLET_NAME);
private boolean isHttps;
private String host;
private String port;
private String web;
private String servlet;
/**
* 解析 url 字符串 生成 RemoteEnvURL 对象
* url 字符串格式 (http(s)://)host(:port)/+web/+servlet/+(others)
*
* @param url x:x/x/x/x
*/
public RemoteEnvURL(String url) {
// 没有写协议名称 默认 使用 http 协议
if (!url.startsWith(HTTPS) && !url.startsWith(HTTP)) {
url = HTTP + url;
}
// 第二次出现":"的地方,port位置起始点
int portIndex = url.indexOf(":", url.indexOf(":") + 1);
// 第三次出现"/"的地方
int webIndex = url.indexOf("/", url.indexOf("://") + 3);
isHttps = url.startsWith(HTTPS);
if (portIndex > webIndex && webIndex != -1) {
portIndex = -1;
}
if (portIndex == -1) {
if (webIndex == -1) {
host = isHttps ? url.substring(HTTPS.length()) : url.substring(HTTP.length());
port = StringUtils.EMPTY;
web = StringUtils.EMPTY;
servlet = StringUtils.EMPTY;
} else {
host = isHttps ? url.substring(HTTPS.length(), webIndex) : url.substring(HTTP.length(), webIndex);
port = StringUtils.EMPTY;
web = StringUtils.EMPTY;
servlet = StringUtils.EMPTY;
String[] lefts = url.substring(webIndex + 1).split("/+");
parserWebAndServlet(lefts);
}
} else {
if (webIndex == -1) {
host = isHttps ? url.substring(HTTPS.length(), portIndex) : url.substring(HTTP.length(), portIndex);
port = url.substring(portIndex + 1);
web = StringUtils.EMPTY;
servlet = StringUtils.EMPTY;
} else {
host = isHttps ? url.substring(HTTPS.length(), portIndex) : url.substring(HTTP.length(), portIndex);
port = url.substring(portIndex + 1, webIndex);
web = StringUtils.EMPTY;
servlet = StringUtils.EMPTY;
String[] lefts = url.substring(webIndex + 1).split("/+");
parserWebAndServlet(lefts);
}
}
}
public boolean hasDefaultHostName() {
return DEFAULT_HOST_NAME.equals(host);
}
public static RemoteEnvURL createDefaultURL() {
return DEFAULT_URL.clone();
}
public RemoteEnvURL(boolean isHttps, String host, String port, String web, String servlet) {
this.isHttps = isHttps;
this.host = host != null ? host.trim() : StringUtils.EMPTY;
this.port = port != null ? port.trim() : StringUtils.EMPTY;
this.web = web != null ? web.trim() : StringUtils.EMPTY;
this.servlet = servlet != null ? servlet.trim() : StringUtils.EMPTY;
}
public String getURL() {
String prefix = isHttps ? HTTPS : HTTP;
String portColon = StringUtils.isNotEmpty(port) ? ":" : StringUtils.EMPTY;
String webAppNameSlash = StringUtils.isNotEmpty(web) ? "/" : StringUtils.EMPTY;
String servletNameSlash = StringUtils.isNotEmpty(servlet) ? "/" : StringUtils.EMPTY;
return prefix + host + portColon + port + webAppNameSlash + web + servletNameSlash + servlet;
}
public void setHttps(boolean https) {
isHttps = https;
}
public void setHost(String host) {
this.host = host != null ? host.trim() : StringUtils.EMPTY;
}
public void setPort(String port) {
this.port = port != null ? port.trim() : StringUtils.EMPTY;
}
public void setWeb(String web) {
this.web = web != null ? web.trim() : StringUtils.EMPTY;
}
public void setServlet(String servlet) {
this.servlet = servlet != null ? servlet.trim() : StringUtils.EMPTY;
}
public boolean getHttps() {
return isHttps;
}
public String getHost() {
return host;
}
public String getPort() {
return port;
}
public String getWeb() {
return web;
}
public String getServlet() {
return servlet;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
RemoteEnvURL that = (RemoteEnvURL) o;
return isHttps == that.isHttps &&
Objects.equals(host, that.host) &&
Objects.equals(port, that.port) &&
Objects.equals(web, that.web) &&
Objects.equals(servlet, that.servlet);
}
@Override
public int hashCode() {
return Objects.hash(isHttps, host, port, web, servlet);
}
@Override
public String toString() {
return "RemoteEnvURL{" +
"isHttps=" + isHttps +
", host='" + host + '\'' +
", port='" + port + '\'' +
", web='" + web + '\'' +
", servlet='" + servlet + '\'' +
'}';
}
@Override
public RemoteEnvURL clone() {
RemoteEnvURL cloned;
try {
cloned = (RemoteEnvURL) super.clone();
return cloned;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError(e);
}
}
private void parserWebAndServlet(String[] lefts) {
int index;
for (index = 0; index < lefts.length; index++) {
if (StringUtils.isNotEmpty(lefts[index])) {
web = lefts[index];
index++;
break;
}
}
for (int servletIndex = index; servletIndex < lefts.length; servletIndex++) {
if (StringUtils.isNotEmpty(lefts[servletIndex])) {
servlet = lefts[servletIndex];
break;
}
}
}
}

199
designer-base/test/com/fr/env/RemoteEnvURLTest.java vendored

@ -0,0 +1,199 @@
package com.fr.env;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author yaohwu
*/
public class RemoteEnvURLTest {
@Test
public void testURLParser() {
String a;
RemoteEnvURL b;
// https or http begin
a = "www.baidu.com:9090/web/servlet/a";
b = new RemoteEnvURL(a);
Assert.assertFalse(b.getHttps());
a = "http://www.baidu.com:9090/web/servlet/a";
b = new RemoteEnvURL(a);
Assert.assertFalse(b.getHttps());
a = "https://www.baidu.com:9090/web/servlet/a";
b = new RemoteEnvURL(a);
Assert.assertTrue(b.getHttps());
// https or http end
// host begin
a = "https://www.baidu.com/web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("www.baidu.com", b.getHost());
a = "https://baidu.com/web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("baidu.com", b.getHost());
a = "https://192.168.1/web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("192.168.1", b.getHost());
a = "https://中文·o((⊙﹏⊙))o囖/web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("中文·o((⊙﹏⊙))o囖", b.getHost());
a = "https://a.b.c.d.e.f/web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("a.b.c.d.e.f", b.getHost());
// host end
//port begin
a = "https://www.baidu.com:9090/web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("9090", b.getPort());
a = "https://www.baidu.com:/web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("", b.getPort());
a = "https://www.baidu.com/web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("", b.getPort());
a = "https://www.baidu.com:kk/web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("kk", b.getPort());
a = "https://www.baidu.com:中文·o((⊙﹏⊙))o囖/web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("中文·o((⊙﹏⊙))o囖", b.getPort());
a = "https://www.baidu.com:中文·o((⊙﹏⊙))o囖";
b = new RemoteEnvURL(a);
assertEquals("中文·o((⊙﹏⊙))o囖", b.getPort());
a = "https://www.baidu.com:中文·o((⊙﹏⊙))o囖///////";
b = new RemoteEnvURL(a);
assertEquals("中文·o((⊙﹏⊙))o囖", b.getPort());
//port end
//web begin
a = "https://www.baidu.com:9090///";
b = new RemoteEnvURL(a);
assertEquals("", b.getWeb());
a = "https://www.baidu.com:9090";
b = new RemoteEnvURL(a);
assertEquals("", b.getWeb());
a = "https://www.baidu.com:9090/";
b = new RemoteEnvURL(a);
assertEquals("", b.getWeb());
a = "https://www.baidu.com:9090///web///servlet/a";
b = new RemoteEnvURL(a);
assertEquals("web", b.getWeb());
a = "https://www.baidu.com:9090/web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("web", b.getWeb());
a = "https://www.baidu.com:9090/中文·o((⊙﹏⊙))o囖/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("中文·o((⊙﹏⊙))o囖", b.getWeb());
a = "https://www.baidu.com:9090/web///servlet/a";
b = new RemoteEnvURL(a);
assertEquals("web", b.getWeb());
a = "https://www.baidu.com:9090///web/servlet/a";
b = new RemoteEnvURL(a);
assertEquals("web", b.getWeb());
//web end
//servlet begin
a = "https://www.baidu.com:9090///web////servlet/a";
b = new RemoteEnvURL(a);
assertEquals("servlet", b.getServlet());
a = "https://www.baidu.com:9090";
b = new RemoteEnvURL(a);
assertEquals("", b.getServlet());
a = "https://www.baidu.com:9090/";
b = new RemoteEnvURL(a);
assertEquals("", b.getServlet());
a = "https://www.baidu.com:9090//";
b = new RemoteEnvURL(a);
assertEquals("", b.getServlet());
a = "https://www.baidu.com:9090//web";
b = new RemoteEnvURL(a);
assertEquals("", b.getServlet());
a = "https://www.baidu.com:9090//web//";
b = new RemoteEnvURL(a);
assertEquals("", b.getServlet());
a = "https://www.baidu.com:9090//web/";
b = new RemoteEnvURL(a);
assertEquals("", b.getServlet());
a = "https://www.baidu.com:9090//web//";
b = new RemoteEnvURL(a);
assertEquals("", b.getServlet());
a = "https://www.baidu.com:9090//web/a/";
b = new RemoteEnvURL(a);
assertEquals("a", b.getServlet());
a = "https://www.baidu.com:9090//web/a";
b = new RemoteEnvURL(a);
assertEquals("a", b.getServlet());
a = "https://www.baidu.com:9090//web/a//";
b = new RemoteEnvURL(a);
assertEquals("a", b.getServlet());
a = "https://www.baidu.com:9090//web/中文·o((⊙﹏⊙))o囖//";
b = new RemoteEnvURL(a);
assertEquals("中文·o((⊙﹏⊙))o囖", b.getServlet());
a = "https://www.baidu.com//web//";
b = new RemoteEnvURL(a);
assertEquals("", b.getServlet());
a = "https://www.baidu.com//web/a/";
b = new RemoteEnvURL(a);
assertEquals("a", b.getServlet());
a = "https://www.baidu.com//web/a";
b = new RemoteEnvURL(a);
assertEquals("a", b.getServlet());
a = "https://www.baidu.com//web/a//";
b = new RemoteEnvURL(a);
assertEquals("a", b.getServlet());
// servlet end
//others begin
a = "https://www.baidu.com/web/servlet/ahttps://www.baidu.com/web/servlet/a";
b = new RemoteEnvURL(a);
Assert.assertTrue(b.getHttps());
assertEquals("www.baidu.com", b.getHost());
assertEquals("", b.getPort());
assertEquals("web", b.getWeb());
assertEquals("servlet", b.getServlet());
//others begin
}
}
Loading…
Cancel
Save