diff --git a/designer-base/src/com/fr/design/DesignerEnvManager.java b/designer-base/src/com/fr/design/DesignerEnvManager.java index f372c9ef7c..c4266cf159 100644 --- a/designer-base/src/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/com/fr/design/DesignerEnvManager.java @@ -4,13 +4,14 @@ package com.fr.design; import com.fr.base.BaseXMLUtils; -import com.fr.base.Env; import com.fr.base.FRContext; import com.fr.base.Utils; -import com.fr.dav.LocalEnv; +import com.fr.base.env.resource.EnvConfigUtils; +import com.fr.base.env.resource.LocalEnvConfig; +import com.fr.base.env.resource.RemoteEnvConfig; +import com.fr.core.env.EnvConfig; import com.fr.design.actions.help.alphafine.AlphaFineConfigManager; import com.fr.design.constants.UIConstants; -import com.fr.env.RemoteEnv; import com.fr.env.SignIn; import com.fr.file.FILEFactory; import com.fr.general.ComparatorUtils; @@ -72,7 +73,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { private boolean showPaintToolBar = true; private int maxNumberOrPreviewRow = 200; // name和Env的键值对 - private Map nameEnvMap = new ListMap(); + private Map nameEnvMap = new ListMap(); // marks: 当前报表服务器名字 private String curEnvName = null; private boolean showProjectPane = true; @@ -191,7 +192,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { if (installHome != null) { String name = Inter.getLocText("FR-Engine_DEFAULT"); String envPath = StableUtils.pathJoin(new String[]{installHome, ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBINF_NAME}); - designerEnvManager.putEnv(name, LocalEnv.createEnv(envPath)); + designerEnvManager.putEnv(name, new LocalEnvConfig(envPath)); designerEnvManager.setCurEnvName(name); } } @@ -323,7 +324,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { FRContext.getLogger().error(e.getMessage(), e); } // 清空前一个版本中的工作目录和最近打开 - nameEnvMap = new ListMap(); + nameEnvMap = new ListMap(); recentOpenedFilePathList = new ArrayList(); curEnvName = null; designerEnvManager.saveXMLFile(); @@ -470,7 +471,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { * @return 是默认则返回true */ public boolean isCurrentEnvDefault() { - Env currentEnv = this.getEnv(curEnvName); + EnvConfig currentEnv = this.getEnv(curEnvName); String defaultEnvPath = StableUtils.pathJoin(new String[]{StableUtils.getInstallHome(), ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBINF_NAME}); return ComparatorUtils.equals(new File(defaultEnvPath).getPath(), currentEnv.getPath()); } @@ -478,21 +479,19 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { /** * 返回默认环境 */ - public Env getDefaultEnv() { + public EnvConfig getDefaultEnv() { String installHome = StableUtils.getInstallHome(); - String defaultenvPath = StableUtils.pathJoin(new String[]{installHome, ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBINF_NAME}); + String defaultenvPath = StableUtils.pathJoin(installHome, ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBINF_NAME); defaultenvPath = new File(defaultenvPath).getPath(); - if (nameEnvMap.size() >= 0) { - Iterator> entryIt = nameEnvMap.entrySet().iterator(); - while (entryIt.hasNext()) { - Entry entry = entryIt.next(); - Env env = entry.getValue(); - if (ComparatorUtils.equals(defaultenvPath, env.getPath())) { - return env; - } + Iterator> entryIt = nameEnvMap.entrySet().iterator(); + while (entryIt.hasNext()) { + Entry entry = entryIt.next(); + EnvConfig env = entry.getValue(); + if (ComparatorUtils.equals(defaultenvPath, env.getPath())) { + return env; } } - Env newDefaultEnv = LocalEnv.createEnv(defaultenvPath); + EnvConfig newDefaultEnv = new LocalEnvConfig(defaultenvPath); this.putEnv(Inter.getLocText(new String[]{"Default", "Utils-Report_Runtime_Env"}), newDefaultEnv); return newDefaultEnv; } @@ -505,10 +504,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { String defaultenvPath = StableUtils.pathJoin(new String[]{installHome, ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBINF_NAME}); defaultenvPath = new File(defaultenvPath).getPath(); if (nameEnvMap.size() >= 0) { - Iterator> entryIt = nameEnvMap.entrySet().iterator(); + Iterator> entryIt = nameEnvMap.entrySet().iterator(); while (entryIt.hasNext()) { - Entry entry = entryIt.next(); - Env env = entry.getValue(); + Entry entry = entryIt.next(); + EnvConfig env = entry.getValue(); if (ComparatorUtils.equals(defaultenvPath, env.getPath())) { return entry.getKey(); } @@ -680,7 +679,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { /** * 根据名称返回环境 */ - public Env getEnv(String name) { + public EnvConfig getEnv(String name) { return this.nameEnvMap.get(name); } @@ -690,7 +689,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { * @param name 名称 * @param env 对应的环境 */ - public void putEnv(String name, Env env) { + public void putEnv(String name, EnvConfig env) { this.nameEnvMap.put(name, env); } @@ -1401,7 +1400,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { if ((tmpVal = reader.getAttrAsString("webinfLocation", null)) != null) { // marks:兼容6.1的 // marks:设置默认的目录. - Env reportServer = LocalEnv.createEnv(tmpVal); + EnvConfig reportServer = new LocalEnvConfig(tmpVal); String curReportServerName = Inter.getLocText("Server-Embedded_Server"); this.putEnv(curReportServerName, reportServer); @@ -1454,11 +1453,11 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } if (reader.isChildNode()) { - if (reader.getTagName().equals("Env")) { // description. + if (reader.getTagName().contains("Env")) { // description. // marks:获取名字 String reportServerName = reader.getAttrAsString("name", null); - Env env = readEnv(reader); + EnvConfig env = readEnv(reader); if (env == null) { return; } @@ -1584,7 +1583,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { Iterator nameIt = this.getEnvNameIterator(); while (nameIt.hasNext()) { String envName = nameIt.next(); - Env env = this.getEnv(envName); + EnvConfig env = this.getEnv(envName); writeEnv(writer, envName, env); } @@ -1743,44 +1742,44 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } /* - * 写Env为xml - */ - private static void writeEnv(XMLPrintWriter writer, String name, Env env) { + * 写Env为xml + */ + private static void writeEnv(XMLPrintWriter writer, String name, EnvConfig env) { if (env == null) { return; } - writer.startTAG("Env"); + writer.startTAG("EnvConfig"); writer.classAttr(env.getClass()); writer.attr("name", name); - env.writeXML(writer); - + EnvConfigXMLAdapter xmlAdapter = env instanceof RemoteEnvConfig + ? new RemoteEnvConfigXMLAdapter() + : new LocalEnvConfigXMLAdapter(); + xmlAdapter.fromEnvConfig(env).writeXML(writer); writer.end(); } /* - * 从xml读Env - */ - private static Env readEnv(XMLableReader reader) { - Env env = null; - + * 从xml读Env + */ + private static EnvConfig readEnv(XMLableReader reader) { + EnvConfigXMLAdapter xmlAdapter = null; String tmpVal; //temp value if ((tmpVal = reader.getAttrAsString("class", null)) != null) { - if (tmpVal.endsWith(".LocalEnv")) { - env = LocalEnv.createEnv(); - } else if (tmpVal.endsWith(".RemoteEnv")) { - env = new RemoteEnv(); + if (tmpVal.contains(".LocalEnv")) { + xmlAdapter = new LocalEnvConfigXMLAdapter(); + } else if (tmpVal.contains(".RemoteEnv")) { + xmlAdapter = new RemoteEnvConfigXMLAdapter(); } } - if (env == null) { - return env; + if (xmlAdapter == null) { + return null; } - reader.readXMLObject(env); - - return env; + reader.readXMLObject(xmlAdapter); + return xmlAdapter.toEnvConfig(); } public AlphaFineConfigManager getAlphaFineConfigManager() { @@ -1790,4 +1789,78 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { public void setAlphaFineConfigManager(AlphaFineConfigManager alphaFineConfigManager) { this.alphaFineConfigManager = alphaFineConfigManager; } + + private interface EnvConfigXMLAdapter extends XMLReadable, XMLWriter { + EnvConfig toEnvConfig(); + + EnvConfigXMLAdapter fromEnvConfig(EnvConfig envConfig); + } + + private static class LocalEnvConfigXMLAdapter implements EnvConfigXMLAdapter { + private String path; + + public void readXML(XMLableReader reader) { + if (reader.isChildNode()) { + if ("DIR".equals(reader.getTagName())) { + this.path = reader.getElementValue(); + } + } + } + + public void writeXML(XMLPrintWriter writer) { + writer.startTAG("DIR").textNode(this.path).end(); + } + + public EnvConfig toEnvConfig() { + return new LocalEnvConfig(path); + } + + public EnvConfigXMLAdapter fromEnvConfig(EnvConfig envConfig) { + this.path = envConfig.getPath(); + return this; + } + + } + + private static class RemoteEnvConfigXMLAdapter implements EnvConfigXMLAdapter { + private String path; + private String username; + private String password; + + public void readXML(XMLableReader reader) { + if (reader.isChildNode()) { + String tmpVal; + if ("DIR".equals(reader.getTagName())) { + if ((tmpVal = reader.getAttrAsString("path", null)) != null) { + this.path = tmpVal; + } + if ((tmpVal = reader.getAttrAsString("user", null)) != null) { + this.username = tmpVal; + } + if ((tmpVal = reader.getAttrAsString("password", null)) != null) { + this.password = tmpVal; + } + } + } + } + + public void writeXML(XMLPrintWriter writer) { + writer.startTAG("DIR") + .attr("path", this.path) + .attr("user", this.username) + .attr("password", this.password) + .end(); + } + + public EnvConfig toEnvConfig() { + return new RemoteEnvConfig(path, username, password); + } + + public EnvConfigXMLAdapter fromEnvConfig(EnvConfig envConfig) { + this.path = envConfig.getPath(); + this.username = EnvConfigUtils.getUsername(envConfig); + this.password = EnvConfigUtils.getPassword(envConfig); + return this; + } + } } \ No newline at end of file diff --git a/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java b/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java index 57574ae253..602f440d96 100644 --- a/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java +++ b/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java @@ -1,14 +1,14 @@ package com.fr.design.actions.file; import com.fr.base.BaseUtils; -import com.fr.base.Env; import com.fr.base.FRContext; -import com.fr.dav.LocalEnv; +import com.fr.base.env.resource.LocalEnvConfig; +import com.fr.base.env.resource.RemoteEnvConfig; +import com.fr.core.env.EnvConfig; import com.fr.design.DesignerEnvManager; import com.fr.design.actions.UpdateAction; import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.tabledata.ResponseDataSourceChange; -import com.fr.design.dialog.InformationWarnPane; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; @@ -18,20 +18,15 @@ import com.fr.design.menu.MenuDef; import com.fr.design.menu.SeparatorDef; import com.fr.env.RemoteEnv; import com.fr.env.SignIn; -import com.fr.general.ComparatorUtils; -import com.fr.general.FRLogger; import com.fr.general.GeneralContext; import com.fr.general.Inter; import com.fr.stable.EnvChangedListener; -import com.fr.stable.ProductConstants; -import com.fr.stable.StringUtils; -import javax.swing.*; +import javax.swing.JOptionPane; import java.awt.event.ActionEvent; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import java.util.logging.Level; public class SwitchExistEnv extends MenuDef { @@ -71,10 +66,10 @@ public class SwitchExistEnv extends MenuDef { public GetExistEnvAction(String envName) { this.setName(envName); - Env env = DesignerEnvManager.getEnvManager().getEnv(envName); - if (env instanceof LocalEnv) { + EnvConfig env = DesignerEnvManager.getEnvManager().getEnv(envName); + if (env instanceof LocalEnvConfig) { this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/data/bind/localconnect.png")); - } else if (env instanceof RemoteEnv) { + } else if (env instanceof RemoteEnvConfig) { this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/data/bind/distanceconnect.png")); } } @@ -102,20 +97,12 @@ public class SwitchExistEnv extends MenuDef { */ public void actionPerformed(ActionEvent e) { DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); - Env selectedEnv = envManager.getEnv(this.getName()); + EnvConfig selectedEnv = envManager.getEnv(this.getName()); try { if (selectedEnv instanceof RemoteEnv && !((RemoteEnv) selectedEnv).testServerConnection()) { JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"})); return; } - String remoteVersion = selectedEnv.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"); - FRLogger.getLogger().log(Level.WARNING, infor); - new InformationWarnPane(infor, moreInfo, Inter.getLocText("Tooltips")).show(); - return; - } SignIn.signIn(selectedEnv); HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().refreshToolArea(); fireDSChanged(); diff --git a/designer-base/src/com/fr/design/file/TemplateTreePane.java b/designer-base/src/com/fr/design/file/TemplateTreePane.java index 9061521a49..a52e423893 100644 --- a/designer-base/src/com/fr/design/file/TemplateTreePane.java +++ b/designer-base/src/com/fr/design/file/TemplateTreePane.java @@ -143,7 +143,7 @@ public class TemplateTreePane extends JPanel implements FileOperations { public void openContainerFolder() { FileNode fn = TemplateTreePane.this.reportletsTree.getSelectedFileNode(); LocalEnv localEnv = (LocalEnv) FRContext.getCurrentEnv(); - String filePath = StableUtils.pathJoin(localEnv.path, fn.getEnvPath()); + String filePath = StableUtils.pathJoin(localEnv.getPath(), fn.getEnvPath()); filePath = filePath.substring(0, filePath.lastIndexOf(CoreConstants.SEPARATOR)); try { Desktop.getDesktop().open(new File(filePath)); @@ -193,6 +193,16 @@ public class TemplateTreePane extends JPanel implements FileOperations { reportletsTree.refresh(); } + @Override + public void lockFile() { + throw new UnsupportedOperationException("unsupport now"); + } + + @Override + public void unLockFile() { + throw new UnsupportedOperationException("unsupport now"); + } + private void deleteHistory(String fileName) { int index = HistoryTemplateListPane.getInstance().contains(fileName); int size = HistoryTemplateListPane.getInstance().getHistoryCount(); @@ -218,41 +228,6 @@ public class TemplateTreePane extends JPanel implements FileOperations { MutilTempalteTabPane.getInstance().repaint(); } - /** - * 加上文件锁 - */ - public void lockFile() { - FileNode fn = reportletsTree.getSelectedFileNode(); - RemoteEnv remoteEnv = (RemoteEnv) FRContext.getCurrentEnv(); - if (fn == null) { - return; - } - try { - remoteEnv.getLock(new String[]{fn.getEnvPath()}); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), e.getMessage()); - } - reportletsTree.refresh(); - } - - /** - * 文件解锁 - */ - public void unLockFile() { - FileNode fn = reportletsTree.getSelectedFileNode(); - if (fn == null) { - return; - } - RemoteEnv remoteEnv = (RemoteEnv) FRContext.getCurrentEnv(); - try { - remoteEnv.releaseLock(new String[]{fn.getEnvPath()}); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), e.getMessage()); - } - reportletsTree.refresh(); - } public String getSelectedTemplatePath() { return reportletsTree.getSelectedTemplatePath(); diff --git a/designer-base/src/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/com/fr/design/mainframe/DesignerFrame.java index c85565c15d..fa70748d8b 100644 --- a/designer-base/src/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/com/fr/design/mainframe/DesignerFrame.java @@ -6,6 +6,8 @@ package com.fr.design.mainframe; import com.fr.base.BaseUtils; import com.fr.base.Env; import com.fr.base.FRContext; +import com.fr.base.env.resource.EnvConfigUtils; +import com.fr.core.env.EnvConfig; import com.fr.design.DesignModelAdapter; import com.fr.design.DesignState; import com.fr.design.DesignerEnvManager; @@ -640,10 +642,10 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta defaultTitleSB.append(ProductConstants.BRANCH); // james:标识登录的用户和登录的ENV String envName = DesignerEnvManager.getEnvManager().getCurEnvName(); - Env env = DesignerEnvManager.getEnvManager().getEnv(envName); + EnvConfig env = DesignerEnvManager.getEnvManager().getEnv(envName); if (env != null) { - defaultTitleSB.append(env.getUser()).append('@').append(envName).append('['); - defaultTitleSB.append(env.getEnvDescription()); + defaultTitleSB.append(EnvConfigUtils.getUsername(env)).append('@').append(envName).append('['); + defaultTitleSB.append(Inter.getLocText("Env-Remote_Server")); defaultTitleSB.append(']'); if (editingTemplate != null) { String path = editingTemplate.getEditingFILE().getPath(); diff --git a/designer-base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java b/designer-base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java index 5e68607b14..af03db3fe1 100644 --- a/designer-base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java +++ b/designer-base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java @@ -249,38 +249,6 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt } } - /* - * 加锁 - */ - private class GetLockAction extends UpdateAction { - - public GetLockAction() { - this.setName(Inter.getLocText("FR-Designer_Get_Lock")); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/lock.png")); - } - - @Override - public void actionPerformed(ActionEvent evt) { - selectedOperation.lockFile(); - } - } - - /* - * 解锁 - */ - private class ReleaseLockAction extends UpdateAction { - - public ReleaseLockAction() { - this.setName(Inter.getLocText("FR-Designer_Release_Lock")); - this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/unlock.png")); - } - - @Override - public void actionPerformed(ActionEvent evt) { - selectedOperation.unLockFile(); - } - } - /** * 按钮状态改变 */ diff --git a/designer-base/src/com/fr/design/mainframe/TemplatePane.java b/designer-base/src/com/fr/design/mainframe/TemplatePane.java index 0aa0258a93..8d128ce5e3 100644 --- a/designer-base/src/com/fr/design/mainframe/TemplatePane.java +++ b/designer-base/src/com/fr/design/mainframe/TemplatePane.java @@ -1,7 +1,7 @@ package com.fr.design.mainframe; import com.fr.base.BaseUtils; -import com.fr.base.Env; +import com.fr.core.env.EnvConfig; import com.fr.dav.LocalEnv; import com.fr.design.DesignModelAdapter; import com.fr.design.DesignerEnvManager; @@ -22,8 +22,19 @@ import com.fr.stable.EnvChangedListener; import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; -import javax.swing.*; -import java.awt.*; +import javax.swing.BorderFactory; +import javax.swing.Icon; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.GradientPaint; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; @@ -97,6 +108,7 @@ public class TemplatePane extends JPanel implements MouseListener { /** * 是否可扩展 + * * @return 同上 */ public boolean IsExpanded() { @@ -111,7 +123,7 @@ public class TemplatePane extends JPanel implements MouseListener { private boolean envListOkAction(EnvListPane envListPane) { String selectedName = envListPane.updateEnvManager(); DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); - Env selectedEnv = envManager.getEnv(selectedName); + EnvConfig selectedEnv = envManager.getEnv(selectedName); GeneralContext.fireEnvWillChangeListener(); try { //如果是远程的还要先测试下,如果失败就不切换 @@ -120,7 +132,7 @@ public class TemplatePane extends JPanel implements MouseListener { JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"})); return false; } else { - String remoteVersion = selectedEnv.getDesignerVersion(); + String remoteVersion = getDesignerVersion(selectedEnv); 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"); @@ -147,6 +159,11 @@ public class TemplatePane extends JPanel implements MouseListener { return true; } + private String getDesignerVersion(EnvConfig selectedEnv) { +// return selectedEnv.getDesignerVersion(); + throw new UnsupportedOperationException("unsupport now"); + } + /** * 编辑items */ @@ -161,7 +178,7 @@ public class TemplatePane extends JPanel implements MouseListener { } public void doCancel() { - envListDialog.setVisible(false); + envListDialog.setVisible(false); } }); envListDialog.setVisible(true); @@ -209,6 +226,7 @@ public class TemplatePane extends JPanel implements MouseListener { /** * 鼠标点击 + * * @param e 事件 */ @Override @@ -217,6 +235,7 @@ public class TemplatePane extends JPanel implements MouseListener { /** * 鼠标按下 + * * @param e 事件 */ @Override @@ -231,6 +250,7 @@ public class TemplatePane extends JPanel implements MouseListener { /** * 鼠标放开 + * * @param e 事件 */ @Override @@ -239,6 +259,7 @@ public class TemplatePane extends JPanel implements MouseListener { /** * 鼠标进入 + * * @param e 事件 */ @Override @@ -247,6 +268,7 @@ public class TemplatePane extends JPanel implements MouseListener { /** * 鼠标离开 + * * @param e 事件 */ @Override diff --git a/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java b/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java index 7be558aca1..9a5effae4d 100644 --- a/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java +++ b/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java @@ -11,6 +11,7 @@ import com.fr.general.FRLogLevel; import com.fr.general.FRLogger; import com.fr.general.GeneralContext; import com.fr.general.Inter; +import com.fr.general.LogRecordTime; import com.fr.log.LogHandler; import com.fr.stable.EnvChangedListener; import com.fr.stable.xml.LogRecordTimeProvider; @@ -149,6 +150,10 @@ public class DesignerLogHandler { logHandlerArea.printStackTrace(message, level, date); } + public void printRemoteLog(LogRecordTime logRecordTime) { + logHandlerArea.printStackTrace(logRecordTime); + } + private class LogHandlerArea extends JPanel { private static final long serialVersionUID = 8215630927304621660L; diff --git a/designer-base/src/com/fr/design/mainframe/loghandler/socketio/DesignerSocketIO.java b/designer-base/src/com/fr/design/mainframe/loghandler/socketio/DesignerSocketIO.java new file mode 100644 index 0000000000..7e37460896 --- /dev/null +++ b/designer-base/src/com/fr/design/mainframe/loghandler/socketio/DesignerSocketIO.java @@ -0,0 +1,88 @@ +package com.fr.design.mainframe.loghandler.socketio; + +import com.fr.base.env.EnvContext; +import com.fr.base.env.resource.LocalEnvConfig; +import com.fr.core.env.EnvConfig; +import com.fr.core.env.EnvConstants; +import com.fr.core.env.EnvEvents; +import com.fr.decision.webservice.utils.DecisionServiceConstants; +import com.fr.design.mainframe.loghandler.DesignerLogHandler; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; +import com.fr.event.Null; +import com.fr.general.LogRecordTime; +import com.fr.general.LogUtils; +import com.fr.log.FineLoggerFactory; +import com.fr.third.guava.base.Optional; +import com.fr.web.WebSocketConfig; +import io.socket.client.IO; +import io.socket.client.Socket; +import io.socket.emitter.Emitter; + +import java.io.ByteArrayInputStream; +import java.net.URI; +import java.net.URL; + +public class DesignerSocketIO { + + private static Optional socketIO = Optional.absent(); + + private static final Emitter.Listener printLog = new Emitter.Listener() { + @Override + public void call(Object... objects) { + try { + LogRecordTime[] logRecordTimes = LogUtils.readXMLLogRecords(new ByteArrayInputStream((byte[]) objects[0])); + for (LogRecordTime logRecordTime : logRecordTimes) { + DesignerLogHandler.getInstance().printRemoteLog(logRecordTime); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } + }; + + static { + EventDispatcher.listen(EnvEvents.AFTER_SIGN_OUT, new Listener() { + @Override + public void on(Event event, Null param) { + if (socketIO.isPresent()) { + socketIO.get().close(); + socketIO = Optional.absent(); + } + } + }); + EventDispatcher.listen(EnvEvents.AFTER_SIGN_IN, new Listener() { + @Override + public void on(Event event, Null param) { + updateSocket(); + } + }); + } + + public static void init() { + updateSocket(); + } + + private static void updateSocket() { + EnvConfig env = EnvContext.currentEnv(); + if (env instanceof LocalEnvConfig) { + return; + } + + try { + String uri = String.format("http://%s:%s%s?%s=%s", + new URL(env.getPath()).getHost(), + WebSocketConfig.getInstance().getPort(), + EnvConstants.WS_NAMESPACE, + DecisionServiceConstants.WEB_SOCKET_TOKEN_NAME, + EnvContext.currentToken()); + + socketIO = Optional.of(IO.socket(new URI(uri))); + socketIO.get().on(EnvConstants.WS_LOGRECORD, printLog); + socketIO.get().connect(); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } +} \ No newline at end of file diff --git a/designer-base/src/com/fr/env/EnvListPane.java b/designer-base/src/com/fr/env/EnvListPane.java index 4165bf9bca..b7f3b29ede 100644 --- a/designer-base/src/com/fr/env/EnvListPane.java +++ b/designer-base/src/com/fr/env/EnvListPane.java @@ -1,7 +1,8 @@ package com.fr.env; -import com.fr.base.Env; -import com.fr.dav.LocalEnv; +import com.fr.base.env.resource.LocalEnvConfig; +import com.fr.base.env.resource.RemoteEnvConfig; +import com.fr.core.env.EnvConfig; import com.fr.design.DesignerEnvManager; import com.fr.design.gui.controlpane.JListControlPane; import com.fr.design.gui.controlpane.NameObjectCreator; @@ -59,9 +60,9 @@ public class EnvListPane extends JListControlPane { @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); + LocalEnvConfig.class, LocalEnvPane.class); NameableCreator remote = new NameObjectCreator(Inter.getLocText("Env-Remote_Server"), "com/fr/design/images/data/bind/distanceconnect.png", - RemoteEnv.class, RemoteEnvPane.class); + RemoteEnvConfig.class, RemoteEnvPane.class); return new NameableCreator[]{local, remote}; } @@ -104,7 +105,7 @@ public class EnvListPane extends JListControlPane { Nameable[] res = this.update(); for (Nameable re : res) { NameObject nameObject = (NameObject) re; - mgr.putEnv(nameObject.getName(), (Env) nameObject.getObject()); + mgr.putEnv(nameObject.getName(), (EnvConfig) nameObject.getObject()); } return this.getSelectedName(); } diff --git a/designer-base/src/com/fr/env/LocalEnvPane.java b/designer-base/src/com/fr/env/LocalEnvPane.java index 1ee7a25ff3..d2719636da 100644 --- a/designer-base/src/com/fr/env/LocalEnvPane.java +++ b/designer-base/src/com/fr/env/LocalEnvPane.java @@ -1,5 +1,6 @@ package com.fr.env; +import com.fr.base.env.resource.LocalEnvConfig; import com.fr.dav.LocalEnv; import com.fr.design.beans.BasicBeanPane; import com.fr.design.gui.ilable.UILabel; @@ -21,7 +22,7 @@ import java.io.File; /** * @author yaohwu */ -public class LocalEnvPane extends BasicBeanPane { +public class LocalEnvPane extends BasicBeanPane { private UITextField pathTextField; private JFileTree localEnvTree; @@ -70,9 +71,9 @@ public class LocalEnvPane extends BasicBeanPane { } @Override - public LocalEnv updateBean() { + public LocalEnvConfig updateBean() { String path = pathTextField.getText(); - return LocalEnv.createEnv(path); + return new LocalEnvConfig(path); } public String getPath() { @@ -80,7 +81,7 @@ public class LocalEnvPane extends BasicBeanPane { } @Override - public void populateBean(LocalEnv ob) { + public void populateBean(LocalEnvConfig ob) { if (StringUtils.isBlank(ob.getPath())) { return; } diff --git a/designer-base/src/com/fr/env/RemoteEnv.java b/designer-base/src/com/fr/env/RemoteEnv.java index f004606f4f..373b15f489 100644 --- a/designer-base/src/com/fr/env/RemoteEnv.java +++ b/designer-base/src/com/fr/env/RemoteEnv.java @@ -8,7 +8,10 @@ import com.fr.base.Parameter; import com.fr.base.StoreProcedureParameter; import com.fr.base.TableData; import com.fr.base.Utils; +import com.fr.base.env.EnvContext; +import com.fr.base.env.resource.RemoteEnvConfig; import com.fr.base.remote.RemoteDeziConstants; +import com.fr.core.env.EnvConstants; import com.fr.data.TableDataSource; import com.fr.data.core.DataCoreUtils; import com.fr.data.core.db.TableProcedure; @@ -35,11 +38,13 @@ import com.fr.general.IOUtils; import com.fr.general.Inter; import com.fr.general.LogRecordTime; import com.fr.general.LogUtils; +import com.fr.general.http.HttpToolbox; import com.fr.io.utils.ResourceIOUtils; import com.fr.json.JSONArray; import com.fr.json.JSONException; import com.fr.json.JSONObject; import com.fr.license.function.VT4FR; +import com.fr.log.FineLoggerFactory; import com.fr.regist.License; import com.fr.report.DesignAuthority; import com.fr.share.ShareConstants; @@ -56,6 +61,7 @@ import com.fr.stable.project.ProjectConstants; import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLTools; import com.fr.stable.xml.XMLableReader; +import com.fr.third.guava.collect.ImmutableMap; import com.fr.web.ResourceConstants; import com.fr.report.util.AuthorityXMLUtils; @@ -93,128 +99,41 @@ import java.util.TimerTask; import java.util.logging.Level; import java.util.regex.Pattern; +import static com.fr.third.guava.base.Preconditions.checkArgument; + /** * @author null */ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurable { - private static final int TIME_OUT = 30 * 1000; - private static final int PLAIN_SOCKET_PORT = 80; - private static final int SSL_PORT = 443; - private static final int MAX_PER_ROUTE = 20; - private static final int MAX_TOTAL = 100; - private static final String REMOTE_PLUGIN = "remote_plugin.info"; private static final String CERT_KEY = "javax.net.ssl.trustStore"; private static final String PWD_KEY = "javax.net.ssl.trustStorePassword"; private static final String HTTPS_PREFIX = "https:"; private final static String[] FILE_TYPE = {"cptx", "cpt", "frm", "form", "cht", "chart"}; - private String path; - private String user; - private String password; - private Clock clock = null; - private String userID; - private Timer timer; - private int licNotSupport = 0; - private boolean isRoot = false; - private Timer logTimer = null; - private static ThreadLocal threadLocal = new ThreadLocal<>(); - private boolean isReadTimeOut = false; private String buildFilePath; + private RemoteEnvConfig env; - public RemoteEnv() { - this.clock = new Clock(this); - } public RemoteEnv(String path, String userName, String password) { - this(); - this.path = path; - this.user = userName; - this.password = password; + env = new RemoteEnvConfig(path, userName, password); } - /** - * 返回env配置路径 - */ @Override public String getPath() { - return this.path; + return env.getPath(); } - public void setPath(String s) { - this.path = s; - } - - /** - * 当前设计环境的用户名,用于远程设计 - */ @Override public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - clearUserID(); + return env.getUsername(); } public String getPassword() { - return password; - } - - /** - * 修复密码中包含特殊字符,无法登录的问题 - * - * @return encoded password - */ - private String getEncodedPassword() { - try { - return URLEncoder.encode(password, "UTF-8"); - } catch (UnsupportedEncodingException e) { - return password; - } - } - - public void setPassword(String password) { - this.password = password; - clearUserID(); - } - - public Clock getClock() { - return this.clock; - } - - public void setClock(Clock clock) { - this.clock = clock; - } - - private void clearUserID() { - this.userID = null; - } - - public void setThreadLocal(String value) { - synchronized (this) { - threadLocal.set(value); - } - + return env.getPassword(); } - public String getThreadLocal() { - return threadLocal.get(); - } - - /** - * 所有与服务器端交互前,都要调用这个方法生成UserID - */ - public String getValidUserID() throws EnvException { - // 如果登录之后userID还是null - if (this.userID == null) { - if (!VT4FR.RemoteDesign.support() && licNotSupport <= 0) { - licNotSupport++; - JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Lic_does_not_Support_Remote")); - } - throw new EnvException(Inter.getLocText("Env-Invalid_User_and_Password")); - } - - return this.userID; + @Override + public String getUserID() { + return EnvContext.currentToken(); } /** @@ -248,15 +167,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl } } - private void doWithTimeOutException() { - boolean isNotNeedTip = ComparatorUtils.equals(getThreadLocal(), "HEART_BEAT") || ComparatorUtils.equals(getThreadLocal(), "LOG_MESSAGE"); - if (!isReadTimeOut && !isNotNeedTip) { - isReadTimeOut = true; - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"Data", "read_time_out"})); - isReadTimeOut = false; - } - FRContext.getLogger().info("Connection reset "); - } /** @@ -324,126 +234,64 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl private boolean testConnection(boolean needMessage, boolean isRegisteServer, Component parentComponent) throws Exception { - refreshHttpSProperty(); - changeEnvPathFromExtra(); - - if (path.startsWith("https") && (!DesignerEnvManager.getEnvManager().isHttps())) { - return false; - } - - InputStream inputStream = RemoteEnvUtils.testConnection(true, this); - inputStream = filterInputStream(inputStream); - String res = IOUtils.inputStream2String(inputStream, EncodeConstants.ENCODING_UTF_8); - - if (StringUtils.isEmpty(res)) { + checkArgument(parentComponent instanceof Component, "parentComponent should be a java.awt.component"); + Component component = parentComponent; + String url = String.format("%s/connection", EnvConstants.toDecisionPath(getPath())); + ImmutableMap params = ImmutableMap.of( + "version", (Object) ProductConstants.DESIGNER_VERSION + ); + ImmutableMap headers = ImmutableMap.of( + EnvConstants.USERNAME, getUser(), + EnvConstants.PWD, getPassword()); + String res = HttpToolbox.post(url, params, headers); + if (res == null) { if (needMessage) { - JOptionPane.showMessageDialog( - parentComponent, - Inter.getLocText("Datasource-Connection_failed"), - UIManager.getString("OptionPane.messageDialogTitle", parentComponent.getLocale()), - JOptionPane.ERROR_MESSAGE - ); + JOptionPane.showMessageDialog(component, Inter.getLocText("Datasource-Connection_failed")); } return false; } else if (ComparatorUtils.equals(res, "true")) { - if (!clock.connected && isRegisteServer) { - //服务器中断又重新启动之后,重新向远程服务器注册 - register2Server(); - } return true; - } else if (ComparatorUtils.equals(res, "invalid username or password.")) { - JOptionPane.showMessageDialog( - parentComponent, - Inter.getLocText( - new String[]{"Datasource-Connection_failed", "Registration-User_Name", "Password", "Error"}, - new String[]{",", "", "", "!"} - ), - Inter.getLocText("FR-Server-All_Error"), - JOptionPane.ERROR_MESSAGE); - return false; - } else if (res.contains("RegistEditionException")) { - if (needMessage) { - JOptionPane.showMessageDialog( - parentComponent, - Inter.getLocText( - new String[]{"Datasource-Connection_failed", "Version-does-not-support"}, - new String[]{",", "!"} - ), - UIManager.getString("OptionPane.messageDialogTitle", parentComponent.getLocale()), - JOptionPane.ERROR_MESSAGE - ); - } else { - FRContext.getLogger().info( - Inter.getLocText( - new String[]{"Datasource-Connection_failed", "Version-does-not-support"}, - new String[]{",", "!"} - ) - ); - } - return false; - } else if (ComparatorUtils.equals(res, "war not support remote design.")) { - if (needMessage) { - JOptionPane.showMessageDialog( - parentComponent, - Inter.getLocText( - new String[]{"Datasource-Connection_failed", "NS-war-remote"}, - new String[]{",", "!"} - ), - UIManager.getString("OptionPane.messageDialogTitle", parentComponent.getLocale()), - JOptionPane.ERROR_MESSAGE - ); + } else { + if (ComparatorUtils.equals(res, EnvConstants.AUTH_ERROR)) { + JOptionPane.showMessageDialog(component, + Inter.getLocText(new String[]{"Datasource-Connection_failed", "Registration-User_Name", "Password", "Error"}, new String[]{",", "", "", "!"}) + , Inter.getLocText("FR-Server-All_Error"), JOptionPane.ERROR_MESSAGE); + return false; } else { - FRContext.getLogger().info( - Inter.getLocText( - new String[]{"Datasource-Connection_failed", "NS-war-remote"}, - new String[]{",", "!"} - ) - ); + if (ComparatorUtils.equals(res, EnvConstants.WAR_ERROR)) { + if (needMessage) { + JOptionPane.showMessageDialog(component, Inter.getLocText(new String[]{"Datasource-Connection_failed", "NS-war-remote"}, new String[]{",", "!"})); + } else { + FineLoggerFactory.getLogger().info(Inter.getLocText(new String[]{"Datasource-Connection_failed", "NS-war-remote"}, new String[]{",", "!"})); + } + return false; + } else { + if (needMessage) { + JOptionPane.showMessageDialog(component, Inter.getLocText(new String[]{"Datasource-Connection_failed", "Version-does-not-support"}, new String[]{",", "!"})); + } else { + FineLoggerFactory.getLogger().info(Inter.getLocText(new String[]{"Datasource-Connection_failed", "Version-does-not-support"}, new String[]{",", "!"})); + } + return false; + } } - return false; - } else { - throw new EnvException(res); } } - private void changeEnvPathFromExtra() { - //在env连接之前, 加载一下不依赖env的插件. 看看需不需要改变参数. - DesignerEnvProcessor processor - = ExtraDesignClassManager.getInstance().getSingle(DesignerEnvProcessor.XML_TAG); - if (processor != null) { - this.path = processor.changeEnvPathBeforeConnect(user, password, path); - } - } private void refreshHttpSProperty() { - if (path.startsWith(HTTPS_PREFIX) && System.getProperty(CERT_KEY) == null) { + if (getPath().startsWith(HTTPS_PREFIX) && System.getProperty(CERT_KEY) == null) { DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); System.setProperty(CERT_KEY, envManager.getCertificatePath()); System.setProperty(PWD_KEY, envManager.getCertificatePass()); } } - private void register2Server() { - try { - SignIn.signIn(this); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - } /** * 心跳访问,用来更新当前用户的访问时间 * * @throws Exception e */ - public void heartBeatConnection() throws Exception { - // 刷新参数 - refreshHttpSProperty(); - // 获取结果 - InputStream inputStream = RemoteEnvUtils.headBeatConnection(this); - // 处理结果 - filterInputStream(inputStream); - } /** * 返回描述该运行环境的名字 @@ -455,227 +303,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return Inter.getLocText("Env-Remote_Server"); } - /** - * 登录,返回userID - */ - @Override - public void signIn() throws Exception { - if (clock != null && clock.connected) { - return; - } - String remoteVersion = getDesignerVersion(); - if (StringUtils.isBlank(remoteVersion) || ComparatorUtils.compare(remoteVersion, ProductConstants.DESIGNER_VERSION) < 0) { - throw new Exception("version not match"); - } - clearUserID(); - startLogTimer(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "r_sign_in"); - para.put("user", user); - para.put("password", getEncodedPassword()); - - simulateRPC(para, true); - - //neil:调用Clock方法,10秒向服务器发送一个字节,确保没掉线 - if (clock == null) { - Clock clock = new Clock(this); - setClock(clock); - } - clock.start(); - - // 远程登录的心跳访问, 防止设计器强制关闭而没有Logout - if (timer != null) { - timer.cancel(); - } - timer = new Timer(); - timer.schedule(new TimerTask() { - @Override - public void run() { - try { - RemoteEnv.this.setThreadLocal("HEART_BEAT"); - RemoteEnv.this.heartBeatConnection(); - } catch (Exception e) { - FRContext.getLogger().error("Server may be disconnected.", e); - } - } - }, RemoteDeziConstants.HEARTBEAT_DELAY, RemoteDeziConstants.HEARTBEAT_DELAY); - } - - - private void startLogTimer() { - if (logTimer != null) { - logTimer.cancel(); - } - - logTimer = new Timer(); - logTimer.schedule(new TimerTask() { - @Override - public void run() { - try { - RemoteEnv.this.setThreadLocal("LOG_MESSAGE"); - FRContext.getCurrentEnv().printLogMessage(); - } catch (Exception e) { - FRContext.getLogger().info(e.getMessage()); - } - } - }, 10000, 10000); - } - - private void stopLogTimer() { - if (logTimer != null) { - logTimer.cancel(); - logTimer = null; - } - } - - /** - * 根据userID sign out - * - * @return 成功签出返回true - * @throws Exception e - */ - @Override - public boolean signOut() throws Exception { - if (userID == null) { - return true; - } - stopLogTimer(); - // richer:登出的时候就把定时发送的时钟停掉 - clock.stop(); - // richer:把轮训使用的定时器也去掉 - timer.cancel(); - - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "r_sign_out"); - para.put("id", userID); - - return simulateRPC(para, false); - } - - protected boolean simulateRPC(HashMap para, boolean isSignIn) throws Exception { - refreshHttpSProperty(); - // execute method取到input stream再转成String - String result = null; - try { - result = stream2String(filterInputStream(RemoteEnvUtils.simulateRPCByHttpGet(para, isSignIn, this))); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - if (result == null) { - return false; - } - if (result.contains("RegistEditionException")) { - JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Lic_does_not_Support_Remote")); - return false; - } - try { - JSONObject jo = new JSONObject(result); - if (isSignIn) { - if (jo.has("id")) { - userID = jo.getString("id"); - } - if (jo.has("isRoot")) { - isRoot = jo.getBoolean("isRoot"); - } - - if (userID != null) { - return true; - } - } else { - if (jo.has("res")) { - return jo.getBoolean("res"); - } - } - String exception = jo.getString("exp"); - if (exception != null) { - throw new EnvException(exception); - } - } catch (JSONException je) { - return true; - } - - return true; - } - - protected boolean doLockOperation(String[] filePaths, String cmd) throws Exception { - if (filePaths == null || filePaths.length == 0) { - return true; - } - - JSONArray ja = new JSONArray(filePaths); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", cmd); - para.put("pathes", ja.toString()); - - return simulateRPC(para, false); - } - - /** - * 取路径filePath下面文件的lock - *

- * 处于同一个原子操作,要么拿到所有的锁,要么一个锁也没有拿到 - */ - public boolean getLock(String[] filePathes) throws Exception { - return doLockOperation(filePathes, "design_get_lock"); - } - - /** - * 解锁文件 - * - * @param filePaths 文件路径 - * @return 成功解锁返回true - * @throws Exception e - */ - public boolean releaseLock(String[] filePaths) throws Exception { - return doLockOperation(filePaths, "design_release_lock"); - } - - /** - * 当前Env下,tplPath目录下是否存在模板 - * - * @param reportPath 路径 - * @return 是否存在 - */ - @Override - public boolean isTemplateExist(String reportPath) throws Exception { - refreshHttpSProperty(); - if (reportPath == null) { - return false; - } - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_report_exist"); - para.put("report_path", reportPath); - - InputStream input = filterInputStream(RemoteEnvUtils.simulateRPCByHttpGet(para, false, this)); - return ComparatorUtils.equals(stream2String(input), "true"); - } - - /** - * 解锁当前模板,用于远程设计。当远程设计某张模板 时,在解锁之前改模板处于锁定状态 - * - * @param tplPath 路径 - * @throws Exception e - */ - @Override - public void unlockTemplate(String tplPath) throws Exception { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_close_report"); - para.put(RemoteDeziConstants.TEMPLATE_PATH, tplPath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - String info = Utils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8); - - FRContext.getLogger().info(info); - } - public class Bytes2ServerOutputStream extends OutputStream { private ByteArrayOutputStream out = new ByteArrayOutputStream(); private HashMap nameValuePairs; @@ -733,33 +360,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl } } - /** - * 测试数据连接是否能够正确的连接上 - * - * @param database 数据连接 - * @return 如果能正确的连接到数据库则返回true - * @throws Exception 无法正确连接到数据库则抛出此异常 - */ - @Override - public boolean testConnection(Connection database) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - // 把database写成xml文件到out - DavXMLUtils.writeXMLFileDatabaseConnection(database, out); - - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_test_con"); - - InputStream input = postBytes2ServerB(out.toByteArray(), para); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - @Override public boolean updateAuthorities(DesignAuthority[] authorities) { refreshHttpSProperty(); @@ -789,260 +389,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return authorities; } - /** - * ben:取schema - */ - @Override - public String[] getTableSchema(Connection database) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - DavXMLUtils.writeXMLFileDatabaseConnection(database, out); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_schema"); - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return null; - } - return DavXMLUtils.readXMLFileSchema(input); - } - - /** - * b:分别取Table,View,Procedure,实际应用时更有意义 - */ - @Override - public TableProcedure[] getTableProcedure(Connection database, String type, String schema) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - DavXMLUtils.writeXMLFileDatabaseConnection(database, out); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_tables"); - para.put("__type__", type); - para.put("__dbschema__", schema); - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return new TableProcedure[0]; - } - return DavXMLUtils.readXMLSQLTables(input); - } - - @Override - public List getProcedures(Connection datasource, String[] schemas, boolean isOracle, boolean isOracleSysSpace) throws Exception { - Map schemaTableProcedureMap = new HashMap<>(); - List sqlTableList = new ArrayList<>(); - TableProcedure[] sqlTableObj; - int len = schemas.length; - if (len > 0) { - for (String schema : schemas) { - sqlTableObj = this.getTableProcedure(datasource, TableProcedure.PROCEDURE, schema); - if (sqlTableObj == null) { - sqlTableObj = new TableProcedure[0]; - } - sqlTableList.add(sqlTableObj); - schemaTableProcedureMap.put(schema, sqlTableObj); - } - } else { - sqlTableObj = this.getTableProcedure(datasource, TableProcedure.PROCEDURE, null); - if (sqlTableObj == null) { - sqlTableObj = new TableProcedure[0]; - } - sqlTableList.add(sqlTableObj); - schemaTableProcedureMap.put(null, sqlTableObj); - } - DataCoreUtils.putProcedureMap(datasource, schemaTableProcedureMap); - return sqlTableList; - } - - /** - * 在当前路径下新建文件夹 - * - * @param folderPath 文件名 - * @return 成功创建返回true - * @throws Exception e - */ - @Override - public boolean createFolder(String folderPath) throws Exception { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_create_folder"); - para.put("folder_path", folderPath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - - /** - * 新建一个文件 - * - * @param filePath :目标文件相对路径 - * @return 成功新建返回true - * @throws Exception e - */ - @Override - public boolean createFile(String filePath) throws Exception { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_create_file"); - para.put("file_path", filePath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - - @Override - public boolean renameFile(String newPath, String oldPath) throws Exception { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_rename_file"); - para.put("newPath", newPath); - para.put("oldPath", oldPath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - - /** - * 判断文件是否存在 - * - * @param filePath :目标文件相对路径 - * @return 文件是否存在 - * @throws Exception e - */ - @Override - public boolean fileExists(String filePath) throws Exception { - refreshHttpSProperty(); - if (filePath == null) { - return false; - } - - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_file_exists"); - para.put("file_path", filePath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - - /** - * 判断文件是否锁住 - * - * @param filePath 文件路径 - * @return 文件被锁住了,返回true - * @throws Exception e - */ - @Override - public boolean fileLocked(String filePath) throws Exception { - refreshHttpSProperty(); - if (filePath == null) { - return false; - } - - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_file_locked"); - para.put("file_path", filePath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } - - - /** - * 注册环境,用于检测是否启动定时器,主要用于本地环境来监测远程 - * - * @param env 用户环境 - */ - @Override - public void registerUserEnv(UserBaseEnv env) { - } - - /** - * 用于检测用户环境 - * ,启动定时器 - */ - @Override - public void startUserCheckTimer() { - } - - - /** - * 停止定时器 - */ - public void stopUserCheckTimer() { - } - - /** - * 删除文件 - * - * @param filePath 文件地址 - * @return 删除成功返回true - */ - @Override - public boolean deleteFile(String filePath) { - refreshHttpSProperty(); - if (filePath == null) { - return false; - } - try { - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "delete_file"); - para.put("file_path", filePath); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - return false; - } - /** * 远程设计器设计时,假如开了权限就不可预览了。这边放一个全局的map来开后门 * @@ -1056,8 +402,8 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fr_remote_design"); para.put("cmd", "write_privilege_map"); - para.put("current_user", this.user); - para.put("current_password", this.password); + para.put("current_user", getUser()); + para.put("current_password", getPassword()); para.put("key", key); para.put("value", value); @@ -1094,158 +440,22 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl JSONArray ja = new JSONArray(stream2String(input)); ArrayList toBeRemoveTDName = new ArrayList<>(); for (int i = 0; i < ja.length(); i++) { - String toBeRemoveConnName = (String) ((JSONObject) ja.get(i)).get("name"); - ConnectionConfig.getInstance().removeConnection(toBeRemoveConnName); - Iterator it = dm.getTableDatas().keySet().iterator(); - while (it.hasNext()) { - String tdName = (String) it.next(); - TableData td = dm.getTableData(tdName); - td.registerNoPrivilege(toBeRemoveTDName, toBeRemoveConnName, tdName); - } - } - - for (int i = 0; i < toBeRemoveTDName.size(); i++) { - dm.removeTableData(toBeRemoveTDName.get(i)); - } - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - } - - /** - * 列出WEB-INF目录下指定路径的文件夹与文件 - * - * @param rootFilePath 指定目录 - * @return WEB-INF目录下指定路径的文件夹与文件 - * @throws Exception e - */ - @Override - public FileNode[] listFile(String rootFilePath) throws Exception { - return listFile(rootFilePath, false); - } - - /** - * 列出WEB-INF上层目录下指定路径的文件夹与文件 - * - * @param rootFilePath 指定目录 - * @return WEB-INF上层目录下指定路径的文件夹与文件 - * @throws Exception e - */ - @Override - public FileNode[] listReportPathFile(String rootFilePath) throws Exception { - return listFile(rootFilePath, true); - } - - private FileNode[] listFile(String rootFilePath, boolean isWebReport) throws Exception { - refreshHttpSProperty(); - InputStream inputStream = RemoteEnvUtils.listFile(rootFilePath, isWebReport, this); - inputStream = filterInputStream(inputStream); - return DavXMLUtils.readXMLFileNodes(inputStream); - } - - - /** - * 列出目标目录下所有cpt文件或文件夹 - * - * @param rootFilePath 指定目录 - * @return 列出目标目录下所有cpt文件或文件夹 - */ - @Override - public FileNode[] listCpt(String rootFilePath) { - return listCpt(rootFilePath, false); - } - - /** - * 列出目标目录下所有cpt文件或文件夹 - * - * @param rootFilePath 指定目录 - * @param recurse 是否递归查找其子目录 - * @return 列出目标目录下所有cpt文件或文件夹 - * @throws Exception e - */ - @Override - public FileNode[] listCpt(String rootFilePath, boolean recurse) { - List fileNodeList = new ArrayList<>(); - try { - listAll(rootFilePath, fileNodeList, new String[]{"cpt"}, recurse); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - } - return fileNodeList.toArray(new FileNode[fileNodeList.size()]); - } - - private void listAll(String rootFilePath, List nodeList, String[] fileTypes, boolean recurse) throws Exception { - FileNode[] fns = listFile(rootFilePath); - for (FileNode fileNode : fns) { - if (isAcceptFileType(fileNode, fileTypes)) { - nodeList.add(fileNode); - } else if (fileNode.isDirectory()) { - if (recurse) { - listAll(rootFilePath + File.separator + fileNode.getName(), nodeList, fileTypes, true); - } else { - nodeList.add(fileNode); - } - } - } - } - - private boolean isAcceptFileType(FileNode fileNode, String[] fileTypes) { - for (String fileType : fileTypes) { - if (fileNode.isFileType(fileType)) { - return true; - } - } - return false; - } - - /** - * 获取指定数据集的参数 - * - * @param tableData 数据集 - * @return 数据集的参数 - * @throws Exception 获取参数失败则抛出此异常 - */ - @Override - public Parameter[] getTableDataParameters(TableData tableData) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - //把tableData写成xml文件到out - DavXMLUtils.writeXMLFileTableData(tableData, out); - - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_td_pars"); - InputStream input = postBytes2ServerB(out.toByteArray(), para); - - if (input == null) { - return new Parameter[0]; - } - return DavXMLUtils.readXMLParameters(input); - } - - - /** - * 获取存储过程中的参数 - * - * @param storeProcedure 存储过程 - * @return 返回存储过程中的所有参数组成的数组 - * @throws Exception 如果获取参数失败则抛出此异常 - */ - @Override - public Parameter[] getStoreProcedureParameters(StoreProcedure storeProcedure) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - // 把tableData写成xml文件到out - DavXMLUtils.writeXMLFileStoreProcedureAndSource(storeProcedure, out); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_sp_pars"); - InputStream input = postBytes2ServerB(out.toByteArray(), para); + String toBeRemoveConnName = (String) ((JSONObject) ja.get(i)).get("name"); + ConnectionConfig.getInstance().removeConnection(toBeRemoveConnName); + Iterator it = dm.getTableDatas().keySet().iterator(); + while (it.hasNext()) { + String tdName = (String) it.next(); + TableData td = dm.getTableData(tdName); + td.registerNoPrivilege(toBeRemoveTDName, toBeRemoveConnName, tdName); + } + } - if (input == null) { - return new Parameter[0]; + for (int i = 0; i < toBeRemoveTDName.size(); i++) { + dm.removeTableData(toBeRemoveTDName.get(i)); + } + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage()); } - return DavXMLUtils.readXMLParameters(input); } @Override @@ -1321,163 +531,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return filterInputStream(RemoteEnvUtils.simulateRPCByHttpPost(bytes, para, false, this)); } - /** - * Read XML.
- * The method will be invoked when read data from XML file.
- * May override the method to read the data that you saved. - */ - @Override - public void readXML(XMLableReader reader) { - if (reader.isChildNode()) { - String tmpVal; - if ("DIR".equals(reader.getTagName())) { - if ((tmpVal = reader.getAttrAsString("path", null)) != null) { - this.path = tmpVal; - } - if ((tmpVal = reader.getAttrAsString("user", null)) != null) { - this.user = tmpVal; - } - if ((tmpVal = reader.getAttrAsString("password", null)) != null) { - this.password = tmpVal; - } - } - } - } - - /** - * Write XML.
- * The method will be invoked when save data to XML file.
- * May override the method to save your own data. - * - * @param writer the PrintWriter. - */ - @Override - public void writeXML(XMLPrintWriter writer) { - writer.startTAG("DIR").attr("path", this.path).attr("user", this.user).attr("password", this.password).end(); - } - - - public static class Clock { - - private static final long CONNECT_INTERVAL = 3000L; - private boolean connected = false; - - private RemoteEnv remoteEnv; - - public Clock(RemoteEnv remoteEnv) { - this.remoteEnv = remoteEnv; - } - - /** - * 开始连接 - */ - public void start() { - if (connected) { - return; - } - connected = true; - - new Thread(new Runnable() { - @Override - public void run() { - // richie:连续三次尝试连接都没有响应才判定为丢失连接 - while (connected) { - try { - attemptConnect(); - } catch (Exception ex) { - try { - attemptConnect(); - } catch (Exception ee) { - try { - attemptConnect(); - } catch (Exception exc) { - stop(); - if (exc instanceof NoRouteToHostException) { - //网络问题导致的连接中断 - if (JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Remote_Connect2Server_Again"), UIManager.getString("OptionPane.titleText"), JOptionPane.YES_NO_OPTION) - == JOptionPane.OK_OPTION) { - //调用重新连接服务器的方法 - connectedAgain(); - } - } else { - //服务器关闭引起的连接中断 - if (JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Remote_Re_Connect_to_Server"), UIManager.getString("OptionPane.titleText"), JOptionPane.YES_NO_OPTION) - == JOptionPane.OK_OPTION) { - //调用重新连接服务器的方法 - connectedAgain(); - } - } - } - } - } - } - } - }).start(); - } - - /** - * 服务器连接中断后重新连接 - */ - private void connectedAgain() { - try { - if (!remoteEnv.testServerConnectionWithOutShowMessagePane()) { - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"Datasource-Connection_failed", "check_communication"}, - new String[]{",", "!"})); - DesignerFrameFileDealerPane.getInstance().refresh(); - return; - } - String remoteVersion = remoteEnv.getDesignerVersion(); - if (StringUtils.isBlank(remoteVersion) || ComparatorUtils.compare(remoteVersion, ProductConstants.DESIGNER_VERSION) < 0) { - String infor = Inter.getLocText("FR-Server_Version_Tip"); - String moreInfo = Inter.getLocText("FR-Server_Version_Tip_MoreInfo"); - FRContext.getLogger().log(Level.WARNING, infor); - new InformationWarnPane(infor, moreInfo, Inter.getLocText("FR-Designer_Tooltips")).show(); - return; - } - SignIn.signIn(remoteEnv); - HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().refreshToolArea(); - } catch (Exception em) { - FRContext.getLogger().error(em.getMessage(), em); - } - } - - /** - * 停止连接 - */ - public void stop() { - connected = false; - } - - private void attemptConnect() throws Exception { - Thread.sleep(CONNECT_INTERVAL); - Pattern pattern = Pattern.compile("[/:]+"); - String[] strs = pattern.split(remoteEnv.path); - - //host,如:192.168.100.195 - String shost = strs[1]; - //端口,如:8080 - int sport = Integer.parseInt(strs[2]); - - Socket socket = new Socket(shost, sport); - //OOBBINLINE:是否支持发送一个字节的TCP紧急数据,false表示服务器不用处理这个数据 - socket.setOOBInline(false); - socket.sendUrgentData(0xFF); - socket.close(); - } - } - - /** - * 读报表运行环境所需的配置文件,如datasource.xml, config.xml,这些文件都保存在WEB-INF/resources目录下面 - * - * @param resourceName 配置文件的名字,如datasource.xml - * @return 输入流 - * @throws Exception e - */ - @Override - public InputStream readResource(String resourceName) throws Exception { - return readBean(resourceName, ProjectConstants.RESOURCES_NAME); - } - /** * 读取路径下的svg文件 @@ -1496,7 +549,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl para.put("op", "fr_remote_design"); para.put("cmd", "design_read_svgfile"); para.put("resourcePath", path); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); InputStream input = filterInputStream( @@ -1536,7 +589,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl para.put("op", "svgrelate"); para.put("cmd", "design_save_svg"); para.put("filePath", svgFile.getFilePath()); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); // 通过ByteArrayOutputStream将svg写成字节流 @@ -1590,7 +643,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl para.put("cmd", "design_save_resource"); para.put("resource", mgr.fileName()); para.put("class_name", mgr.getClass().getName()); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); // alex:通过ByteArrayOutputStream将mgr写成字节流 @@ -1653,38 +706,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return new Bytes2ServerOutputStream(para); } - /** - * 返回数据库表的列名 - * - * @param selectedName 所选择数据库名 - * @param schema 数据库模式,用于存储过程 - * @param tableName 所选择数据库名 - */ - @Override - public String[] getColumns(String selectedName, String schema, String tableName) throws Exception { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_columns"); - para.put("dsName", selectedName); - para.put("schema", schema); - para.put("tableName", tableName); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - - if (input == null) { - return null; - } - - String columns = stream2String(input); - if (StringUtils.isEmpty(columns)) { - return null; - } - return columns.split("\\."); - } - /** * 返回模板文件路径 */ @@ -1693,98 +714,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return getPath().substring(0, getPath().lastIndexOf("/")); } - @Override - public String getProcedureText(String connectionName, String databaseName) throws Exception { - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_procedure_text"); - para.put("procedure_name", databaseName); - para.put("connectionName", connectionName); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return StringUtils.EMPTY; - } - return DavXMLUtils.readXMLProcedureText(input); - } - - @Override - public StoreProcedureParameter[] getStoreProcedureDeclarationParameters(String connectionName, String databaseName, String parameterDefaultValue) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_sp_parameters"); - para.put("__name__", databaseName); - para.put("__default_value__", parameterDefaultValue); - para.put("connectionName", connectionName); - - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return new StoreProcedureParameter[0]; - } - return DavXMLUtils.readXMLStoreProcedureParameters(input); - } - - /** - * 获取datasource.xml文件的修改表 - */ - @Override - public ModifiedTable getDataSourceModifiedTables(String type) { - refreshHttpSProperty(); - try { - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "get_datasource_modified_tables"); - para.put("type", type); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - if (input == null) { - return new ModifiedTable(); - } - return DavXMLUtils.readXMLModifiedTables(input); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - return new ModifiedTable(); - } - - - /** - * 写修改表 - * - * @param modifiedTable 修改表 - * @param type 操作类型,是数据连接还是服务器数据集 - * @return 写入成功返回true - */ - @Override - public boolean writeDataSourceModifiedTables(ModifiedTable modifiedTable, String type) { - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - // 把tableData写成xml文件到out - DavXMLUtils.writeXMLModifiedTables(modifiedTable, out); - try { - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "update_modifytable_to_server"); - para.put("type", type); - - InputStream input = postBytes2ServerB(out.toByteArray(), para); - - if (input == null) { - return false; - } - - return Boolean.valueOf(IOUtils.inputStream2String(input, EncodeConstants.ENCODING_UTF_8)); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - return false; - } - public String[] getProcedureColumns(StoreProcedure storeProcedure, Map parameterMap) throws Exception { refreshHttpSProperty(); String[] columns; @@ -1851,102 +780,11 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl LogRecordTime[] records = LogUtils.readXMLLogRecords(input); } - @Override - public String getUserID() { - return userID; - } - - - /** - * 预览存储过程 - * - * @param storeProcedure 存储过程 - * @param parameterMap 参数map - * @param rowCount 行数 - * @return 返回取到的存储过程 - */ - @Override - public ProcedureDataModel[] previewProcedureDataModel(StoreProcedure storeProcedure, Map parameterMap, int rowCount) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - - // 把tableData写成xml文件到out - DavXMLUtils.writeXMLFileStoreProcedureAndSource(storeProcedure, out); - - // 把parameterMap转成JSON格式的字符串 - JSONObject jo = new JSONObject(parameterMap); - String jsonParameter = jo.toString(); - - try { - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "list_sp"); - para.put("pars", jsonParameter); - - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return null; - } - - TableData[] tableDatas = DavXMLUtils.readXMLTableDataArray(input); - if (tableDatas == null || tableDatas.length == 0) { - return new ProcedureDataModel[0]; - } - ProcedureDataModel[] procedureDataModels = new ProcedureDataModel[tableDatas.length]; - for (int i = 0; i < tableDatas.length; i++) { - if (tableDatas[i] instanceof EmbeddedTableData) { - procedureDataModels[i] = ((EmbeddedTableData) tableDatas[i]).trans2ProcedureDataModel(); - } - } - return procedureDataModels; - - - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - return new ProcedureDataModel[0]; - } - - - @Override - public String getAppName() { - return "WebReport"; - } - - /** - * 是否为Oracle数据连接 - * - * @param database 数据连接 - * @return 是返回true - * @throws Exception e - */ - @Override - public boolean isOracle(Connection database) throws Exception { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - DavXMLUtils.writeXMLFileDatabaseConnection(database, out); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_isOracle"); - InputStream input = postBytes2ServerB(out.toByteArray(), para); - if (input == null) { - return true; - } - return DavXMLUtils.readXMLBoolean(input); - } - @Override public String[] getSupportedTypes() { return FILE_TYPE; } - /** - * 在模板面板中是否支持增加打开所在文件夹、重命名、删除三个工具栏选项 - * - * @return 不支持返回false - */ - @Override - public boolean isSupportLocalFileOperate() { - return false; - } /** * 判断是否有文件夹权限 @@ -1961,7 +799,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fs_remote_design"); para.put("cmd", "design_filefolder_allow"); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put(RemoteDeziConstants.TEMPLATE_PATH, path); InputStream input = filterInputStream( @@ -1979,43 +817,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl } - /** - * 是否是管理员身份 - * - * @return 是则返回true - */ - @Override - public boolean isRoot() { - return isRoot; - } - - /** - * 是否为压缩包部署 - * - * @return 是则返回true - */ - @Override - public boolean isPackDeploy() { - return false; - } - - @Override - public String getDesignerVersion() { - refreshHttpSProperty(); - HashMap para = new HashMap<>(); - para.put("op", "fr_remote_design"); - para.put("cmd", "design_get_designer_version"); - para.put("user", user); - para.put("password", getEncodedPassword()); - - try { - return stream2String(filterInputStream(RemoteEnvUtils.simulateRPCByHttpGet(para, true, this))); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - return null; - } - @Override public InputStream getDataSourceInputStream(String filePath) throws Exception { return readBean(filePath, "datasource"); @@ -2046,15 +847,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return allRoleList; } - @Override - public String getLicName() { - return License.FILE_NAME; - } - - @Override - public void setLicName(String licName) { - //do nth - } /** @@ -2135,7 +927,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fr_remote_design"); para.put("cmd", "design_read_reufile"); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); //拿到服务端传过来的整个共享文件夹的压缩文件的文件流 @@ -2181,7 +973,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fr_remote_design"); para.put("cmd", "design_install_reufile"); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); para.put("reuFileName", reuFile.getName()); @@ -2218,7 +1010,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fr_remote_design"); para.put("cmd", "design_remove_reufile"); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); para.put("reuFileName", fileName); @@ -2238,7 +1030,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl HashMap para = new HashMap<>(); para.put("op", "fr_remote_design"); para.put("cmd", "design_get_share_path"); - para.put("current_uid", this.getValidUserID()); + para.put("current_uid", this.getUserID()); para.put("currentUsername", this.getUser()); InputStream input = filterInputStream( @@ -2250,16 +1042,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl } } - @Override - public void doWhenServerShutDown() { - - } - - @Override - public boolean isLocalEnv() { - - return false; - } @Override public boolean hasPluginServiceStarted(String key) { @@ -2267,22 +1049,4 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return true; } - @Override - public JSONArray getPluginStatus() { - refreshHttpSProperty(); - try { - HashMap para = new HashMap<>(); - para.put("op", "plugin"); - para.put("cmd", "get_status"); - para.put("current_uid", this.getValidUserID()); - para.put("currentUsername", this.getUser()); - - InputStream input = filterInputStream( - RemoteEnvUtils.simulateRPCByHttpGet(para, false, this) - ); - return new JSONArray(stream2String(input)); - } catch (Exception e) { - return JSONArray.create(); - } - } } \ No newline at end of file diff --git a/designer-base/src/com/fr/env/RemoteEnvPane.java b/designer-base/src/com/fr/env/RemoteEnvPane.java index 12fb4d2b40..20ca4715a2 100644 --- a/designer-base/src/com/fr/env/RemoteEnvPane.java +++ b/designer-base/src/com/fr/env/RemoteEnvPane.java @@ -1,6 +1,8 @@ package com.fr.env; import com.fr.base.FRContext; +import com.fr.base.env.resource.EnvConfigUtils; +import com.fr.base.env.resource.RemoteEnvConfig; import com.fr.design.DesignerEnvManager; import com.fr.design.beans.BasicBeanPane; import com.fr.design.border.UITitledBorder; @@ -49,7 +51,7 @@ import static com.fr.design.layout.TableLayout.PREFERRED; /** * @author yaohwu */ -public class RemoteEnvPane extends BasicBeanPane { +public class RemoteEnvPane extends BasicBeanPane { private static final Color TIPS_FONT_COLOR = new Color(0x8f8f92); @@ -100,7 +102,7 @@ public class RemoteEnvPane extends BasicBeanPane { /** * 主机位置 */ - private RemoteEnvURL remoteEnvURL; + private RemoteEnvURL remoteEnvURL = new RemoteEnvURL(""); /** * https 配置面板 */ @@ -151,6 +153,7 @@ public class RemoteEnvPane extends BasicBeanPane { @Override public void removeUpdate(DocumentEvent e) { + actionURLInputChange(); } @@ -250,7 +253,7 @@ public class RemoteEnvPane extends BasicBeanPane { } @Override - public void populateBean(RemoteEnv ob) { + public void populateBean(RemoteEnvConfig ob) { if (StringUtils.isEmpty(ob.getPath())) { remoteEnvURL = RemoteEnvURL.createDefaultURL(); @@ -265,18 +268,20 @@ public class RemoteEnvPane extends BasicBeanPane { fileChooserButton.setEnabled(remoteEnvURL.getHttps()); updateHttpsConfigPanel(); - this.usernameInput.setText(ob.getUser() == null ? StringUtils.EMPTY : ob.getUser()); + String username = EnvConfigUtils.getUsername(ob); + String pwd = EnvConfigUtils.getPassword(ob); + this.usernameInput.setText(username == null ? StringUtils.EMPTY : pwd); this.passwordInput.setText(ob.getPassword() == null ? StringUtils.EMPTY : ob.getPassword()); } @Override - public RemoteEnv updateBean() { + public RemoteEnvConfig updateBean() { String path = remoteEnvURL.getURL(); String user = this.usernameInput.getText(); String password = new String(this.passwordInput.getPassword()); - return new RemoteEnv(path, user, password); + return new RemoteEnvConfig(path, user, password); } @Override @@ -465,11 +470,8 @@ public class RemoteEnvPane extends BasicBeanPane { } private boolean testConnection() { - RemoteEnv env = new RemoteEnv(); String url = remoteEnvURL.getURL(); - env.setPath(url); - env.setUser(usernameInput.getText()); - env.setPassword(new String(passwordInput.getPassword())); + RemoteEnv env = new RemoteEnv(url, usernameInput.getText(), new String(passwordInput.getPassword())); boolean connect = false; try { if (StringUtils.isNotEmpty(url)) { diff --git a/designer-base/src/com/fr/env/RemoteEnvUtils.java b/designer-base/src/com/fr/env/RemoteEnvUtils.java index 7b9163d391..cf6b2d657e 100644 --- a/designer-base/src/com/fr/env/RemoteEnvUtils.java +++ b/designer-base/src/com/fr/env/RemoteEnvUtils.java @@ -57,7 +57,7 @@ public class RemoteEnvUtils { builder.addParameter(entry.getKey(), entry.getValue()); } if (!isSignIn) { - builder.addParameter("id", env.getValidUserID()); + builder.addParameter("id", env.getUserID()); } InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(bytes)); @@ -82,7 +82,7 @@ public class RemoteEnvUtils { builder.addParameter(entry.getKey(), entry.getValue()); } if (!isSignIn) { - builder.addParameter("id", env.getValidUserID()); + builder.addParameter("id", env.getUserID()); } try (CloseableHttpClient httpClient = HttpClients.createSystem()) { @@ -105,7 +105,7 @@ public class RemoteEnvUtils { builder.addParameter(entry.getKey(), entry.getValue()); } if (!isSignIn) { - builder.addParameter("id", env.getValidUserID()); + builder.addParameter("id", env.getUserID()); } try (CloseableHttpClient httpClient = HttpClients.createSystem()) { HttpUriRequest request = builder.build(); @@ -118,57 +118,10 @@ public class RemoteEnvUtils { } - public static InputStream headBeatConnection(RemoteEnv env) { - String path = env.getPath(); - String username = env.getUser(); - - InputStream inputStream = null; - try (CloseableHttpClient httpClient = HttpClients.createSystem()) { - HttpUriRequest request = RequestBuilder.get(path) - .addParameter("op", "fr_remote_design") - .addParameter("cmd", "heart_beat") - .addParameter("user", username) - .addParameter("id", env.getValidUserID()) - .build(); - - inputStream = httpClient.execute(request, responseHandler); - } catch (IOException | EnvException e) { - FRContext.getLogger().error(e.getMessage()); - } - return inputStream; - } - - - public static InputStream testConnection(boolean isSignIn, RemoteEnv env) throws EnvException { - String username = env.getUser(); - String path = env.getPath(); - String password = env.getPassword(); - - InputStream inputStream = null; - - try (CloseableHttpClient httpClient = HttpClients.createSystem()) { - RequestBuilder builder = RequestBuilder.get(path); - if (!isSignIn) { - builder.addParameter("id", env.getValidUserID()); - } - HttpUriRequest request = builder - .addParameter("op", "fr_remote_design") - .addParameter("cmd", "test_server_connection") - .addParameter("user", username) - .addParameter("password", URLEncoder.encode(password, EncodeConstants.ENCODING_UTF_8)) - .build(); - inputStream = httpClient.execute(request, responseHandler); - } catch (IOException e) { - FRContext.getLogger().error(e.getMessage()); - } - return inputStream; - } - - - public static InputStream updateAuthorities(DesignAuthority[] authorities, RemoteEnv env) throws EnvException { + public static InputStream updateAuthorities(DesignAuthority[] authorities, RemoteEnv env) { String path = env.getPath(); // 远程设计临时用户id - String userID = env.getValidUserID(); + String userID = env.getUserID(); InputStream inputStream = null; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); @@ -194,7 +147,7 @@ public class RemoteEnvUtils { public static InputStream getAuthorities(RemoteEnv env) throws EnvException { String path = env.getPath(); // 远程设计临时用户id - String userID = env.getValidUserID(); + String userID = env.getUserID(); InputStream inputStream = null; try (CloseableHttpClient httpClient = HttpClients.createSystem();) { @@ -211,28 +164,4 @@ public class RemoteEnvUtils { } - public static InputStream listFile(String pFilePath, boolean isWebReport, RemoteEnv env) throws EnvException { - String path = env.getPath(); - // 远程设计临时用户id - String userID = env.getValidUserID(); - String username = env.getUser(); - - InputStream inputStream = null; - try (CloseableHttpClient httpClient = HttpClients.createSystem()) { - HttpUriRequest request = RequestBuilder.get(path) - .addParameter("op", "fs_remote_design") - .addParameter("cmd", "design_list_file") - .addParameter("file_path", pFilePath) - .addParameter("currentUserName", username) - .addParameter("currentUserId", userID) - .addParameter("id", userID) - .addParameter("isWebReport", Boolean.toString(isWebReport)) - .build(); - inputStream = httpClient.execute(request, responseHandler); - } catch (IOException e) { - FRContext.getLogger().error(e.getMessage()); - } - return inputStream; - } - } diff --git a/designer-base/src/com/fr/env/SignIn.java b/designer-base/src/com/fr/env/SignIn.java index a5f2860ec6..09ba8c911a 100644 --- a/designer-base/src/com/fr/env/SignIn.java +++ b/designer-base/src/com/fr/env/SignIn.java @@ -1,43 +1,61 @@ package com.fr.env; -import com.fr.base.Env; import com.fr.base.FRContext; +import com.fr.base.env.EnvContext; +import com.fr.base.env.resource.EnvConfigUtils; +import com.fr.base.env.resource.RemoteEnvConfig; +import com.fr.core.env.EnvConfig; +import com.fr.core.env.EnvEvents; +import com.fr.dav.LocalEnv; import com.fr.design.utils.DesignUtils; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; +import com.fr.event.Null; import com.fr.general.ComparatorUtils; -import com.fr.general.env.EnvContext; +import com.fr.general.Inter; + +import javax.swing.JOptionPane; +import javax.swing.UIManager; public class SignIn { - public static Env lastSelectedEnv;// 记录最后登录的Env + + static { + EventDispatcher.listen(EnvEvents.CONNECTION_ERROR, new Listener() { + @Override + public void on(Event event, Null param) { + if (JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Remote_Connect2Server_Again"), UIManager.getString("OptionPane.titleText"), JOptionPane.YES_NO_OPTION) + == JOptionPane.OK_OPTION) { + try { + EnvContext.signIn(EnvContext.currentEnv()); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage()); + } + } + } + }); + } /** * 注册入环境 * @param selectedEnv 选择的环境 * @throws Exception 异常 */ - public static void signIn(Env selectedEnv) throws Exception { - boolean validServer; - signOutOldEnv(selectedEnv); - selectedEnv.signIn(); - validServer = true; - if (validServer) { - DesignUtils.switchToEnv(selectedEnv); - lastSelectedEnv = selectedEnv; + public static void signIn(EnvConfig selectedEnv) throws Exception { + if (EnvContext.currentEnv() != null && !ComparatorUtils.equals(EnvContext.currentEnv(), selectedEnv)) { + EnvContext.signOut(); } + EnvContext.signIn(selectedEnv); + DesignUtils.switchToEnv(trans(selectedEnv)); } - private static void signOutOldEnv(Env newEnv) { - // 环境相同直接返回,避免浪费过多时间 - if (lastSelectedEnv == null || ComparatorUtils.equals(lastSelectedEnv, newEnv)) { - return; - } - try { - EnvContext.fireBeforeSignOut(); - lastSelectedEnv.signOut(); - EnvContext.fireAfterSignOut(); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); + private static com.fr.base.Env trans(EnvConfig env) { + if (env instanceof RemoteEnvConfig) { + return new RemoteEnv(env.getPath(), EnvConfigUtils.getUsername(env), EnvConfigUtils.getPassword(env)); + } else { + return new LocalEnv(); } } } \ No newline at end of file diff --git a/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java b/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java index 7a8becd11e..b6abbdf85c 100644 --- a/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java +++ b/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java @@ -1,5 +1,6 @@ package com.fr.start.module; +import com.fr.design.mainframe.loghandler.socketio.DesignerSocketIO; import com.fr.design.module.DesignerModule; import com.fr.general.ModuleContext; import com.fr.locale.InterMutableKey; @@ -20,6 +21,8 @@ public class DesignerModuleActivator extends Activator implements Prepare { ModuleContext.registerModuleListener(getModule().upFindSingleton(ModuleListener.class)); ModuleContext.startModule(DesignerModule.class.getName()); ModuleContext.clearModuleListener(); + + DesignerSocketIO.init(); } @Override