Browse Source

REPORT-20328 sonar

research/11.0
jinbokai 5 years ago
parent
commit
d259b596ff
  1. 14
      designer-base/src/main/java/com/fr/design/gui/iscrollbar/UIScrollBarUI.java
  2. 10
      designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java
  3. 18
      designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java
  4. 18
      designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java

14
designer-base/src/main/java/com/fr/design/gui/iscrollbar/UIScrollBarUI.java

@ -1,5 +1,7 @@
package com.fr.design.gui.iscrollbar; package com.fr.design.gui.iscrollbar;
import com.fr.design.constants.UIConstants;
import com.fr.stable.StringUtils;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Container; import java.awt.Container;
@ -20,7 +22,6 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import javax.swing.BoundedRangeModel; import javax.swing.BoundedRangeModel;
import javax.swing.InputMap; import javax.swing.InputMap;
import javax.swing.JComponent; import javax.swing.JComponent;
@ -38,8 +39,6 @@ import javax.swing.event.ChangeListener;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.ScrollBarUI; import javax.swing.plaf.ScrollBarUI;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import com.fr.design.constants.UIConstants;
import sun.swing.DefaultLookup; import sun.swing.DefaultLookup;
/** /**
@ -148,6 +147,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo
* *
* @param c * @param c
*/ */
@Override
public void installUI(JComponent c) { public void installUI(JComponent c) {
scrollbar = (JScrollBar) c; scrollbar = (JScrollBar) c;
thumbRect = new Rectangle(0, 0, 0, 0); thumbRect = new Rectangle(0, 0, 0, 0);
@ -163,6 +163,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo
* *
* @param c * @param c
*/ */
@Override
public void uninstallUI(JComponent c) { public void uninstallUI(JComponent c) {
scrollbar = (JScrollBar) c; scrollbar = (JScrollBar) c;
uninstallListeners(); uninstallListeners();
@ -357,6 +358,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo
/** /**
* 只画Thumb * 只画Thumb
*/ */
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
Rectangle thumbBounds = getThumbBounds(); Rectangle thumbBounds = getThumbBounds();
if (thumbBounds.intersects(g.getClipBounds())) { if (thumbBounds.intersects(g.getClipBounds())) {
@ -380,6 +382,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo
* @see #getMaximumSize * @see #getMaximumSize
* @see #getMinimumSize * @see #getMinimumSize
*/ */
@Override
public Dimension getPreferredSize(JComponent c) { public Dimension getPreferredSize(JComponent c) {
return (scrollbar.getOrientation() == JScrollBar.VERTICAL) ? new Dimension(scrollBarWidth, 48) : new Dimension(48, scrollBarWidth); return (scrollbar.getOrientation() == JScrollBar.VERTICAL) ? new Dimension(scrollBarWidth, 48) : new Dimension(48, scrollBarWidth);
} }
@ -390,6 +393,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo
* @see #getMinimumSize * @see #getMinimumSize
* @see #getPreferredSize * @see #getPreferredSize
*/ */
@Override
public Dimension getMaximumSize(JComponent c) { public Dimension getMaximumSize(JComponent c) {
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
} }
@ -937,6 +941,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo
private transient int direction = +1; private transient int direction = +1;
@Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
isPressing = false; isPressing = false;
if (isDragging) { if (isDragging) {
@ -968,6 +973,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo
* one page. If there is no thumb then page up if the mouse is in the * one page. If there is no thumb then page up if the mouse is in the
* upper half of the track. * upper half of the track.
*/ */
@Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
boolean isMiddle = !isSupportsAbsolutePositioning() && SwingUtilities.isMiddleMouseButton(e); boolean isMiddle = !isSupportsAbsolutePositioning() && SwingUtilities.isMiddleMouseButton(e);
if (SwingUtilities.isRightMouseButton(e) || isMiddle) { if (SwingUtilities.isRightMouseButton(e) || isMiddle) {
@ -1313,7 +1319,7 @@ public class UIScrollBarUI extends ScrollBarUI implements LayoutManager, SwingCo
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
String propertyName = e.getPropertyName(); String propertyName = e.getPropertyName();
if ("model" == propertyName) { if (StringUtils.equals("model", propertyName)) {
BoundedRangeModel oldModel = (BoundedRangeModel) e.getOldValue(); BoundedRangeModel oldModel = (BoundedRangeModel) e.getOldValue();
BoundedRangeModel newModel = (BoundedRangeModel) e.getNewValue(); BoundedRangeModel newModel = (BoundedRangeModel) e.getNewValue();
oldModel.removeChangeListener(modelListener); oldModel.removeChangeListener(modelListener);

10
designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java

@ -95,10 +95,6 @@ import com.fr.stable.module.Module;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
import com.fr.web.controller.ViewRequestConstants; import com.fr.web.controller.ViewRequestConstants;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -106,6 +102,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JPanel;
/** /**
* JWorkBook used to edit WorkBook. * JWorkBook used to edit WorkBook.
@ -1103,9 +1102,8 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
// 弹出输入参数 // 弹出输入参数
java.util.Map<String, Object> parameterMap = inputParameters(tpl); java.util.Map<String, Object> parameterMap = inputParameters(tpl);
try {
String fullPath = StableUtils.pathJoin(WorkContext.getCurrent().getPath(), newFile.getPath()); String fullPath = StableUtils.pathJoin(WorkContext.getCurrent().getPath(), newFile.getPath());
FileOutputStream fileOutputStream = new FileOutputStream(fullPath); try (FileOutputStream fileOutputStream = new FileOutputStream(fullPath)) {
EmbeddedTableDataExporter exporter = new EmbeddedTableDataExporter(); EmbeddedTableDataExporter exporter = new EmbeddedTableDataExporter();
exporter.export(fileOutputStream, tpl, parameterMap); exporter.export(fileOutputStream, tpl, parameterMap);
} catch (Exception e1) { } catch (Exception e1) {

18
designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java

@ -2,14 +2,17 @@ package com.fr.design.mainframe.errorinfo;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import com.fr.json.JSONException;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
import com.fr.stable.EncodeConstants; import com.fr.stable.EncodeConstants;
import com.fr.stable.ProductConstants; import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
import com.fr.stable.core.UUID; import com.fr.stable.core.UUID;
import java.io.ByteArrayInputStream;
import java.io.*; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.Date; import java.util.Date;
@ -124,13 +127,14 @@ public class ErrorInfo {
String content = jo.toString(); String content = jo.toString();
String fileName = UUID.randomUUID() + ErrorInfoUploader.SUFFIX; String fileName = UUID.randomUUID() + ErrorInfoUploader.SUFFIX;
File file = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), ErrorInfoUploader.FOLDER_NAME, fileName)); File file = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), ErrorInfoUploader.FOLDER_NAME, fileName));
try { FileOutputStream out = null;
try (InputStream in = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) {
StableUtils.makesureFileExist(file); StableUtils.makesureFileExist(file);
FileOutputStream out = new FileOutputStream(file); out = new FileOutputStream(file);
InputStream in = new ByteArrayInputStream(content.getBytes(EncodeConstants.ENCODING_UTF_8));
IOUtils.copyBinaryTo(in, out); IOUtils.copyBinaryTo(in, out);
out.close();
} catch (IOException ignore) { } catch (IOException ignore) {
} finally {
IOUtils.close(out);
} }
} }
} }

18
designer-realize/src/main/java/com/fr/design/mainframe/messagecollect/entity/FileEntityBuilder.java

@ -19,7 +19,9 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.UUID; import java.util.UUID;
import java.util.zip.ZipOutputStream;
/** /**
* @author alex sung * @author alex sung
@ -52,13 +54,15 @@ public class FileEntityBuilder {
return null; return null;
} }
File zipFile = null; File zipFile = null;
ZipOutputStream zipOut = null;
try { try {
zipFile = new File(pathName + ".zip"); zipFile = new File(pathName + ".zip");
java.util.zip.ZipOutputStream zipOut = new java.util.zip.ZipOutputStream(new FileOutputStream(zipFile)); zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
IOUtils.zip(zipOut, new File(pathName)); IOUtils.zip(zipOut, new File(pathName));
zipOut.close();
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
IOUtils.close(zipOut);
} }
return zipFile; return zipFile;
} }
@ -67,18 +71,18 @@ public class FileEntityBuilder {
if (jsonArray.size() == 0) { if (jsonArray.size() == 0) {
return; return;
} }
try { FileOutputStream out = null;
String content = jsonArray.toString(); String content = jsonArray.toString();
try (InputStream in = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))) {
String fileName = String.valueOf(UUID.randomUUID()); String fileName = String.valueOf(UUID.randomUUID());
File file = new File(folderName + File.separator + fileName + ".json"); File file = new File(folderName + File.separator + fileName + ".json");
StableUtils.makesureFileExist(file); StableUtils.makesureFileExist(file);
FileOutputStream out = new FileOutputStream(file); out = new FileOutputStream(file);
InputStream in = new ByteArrayInputStream(content.getBytes(EncodeConstants.ENCODING_UTF_8));
IOUtils.copyBinaryTo(in, out); IOUtils.copyBinaryTo(in, out);
in.close();
out.close();
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); FineLoggerFactory.getLogger().error(e.getMessage(), e);
} finally {
IOUtils.close(out);
} }
} }

Loading…
Cancel
Save