List of usage examples for java.awt.image BufferedImage TYPE_INT_ARGB
int TYPE_INT_ARGB
To view the source code for java.awt.image BufferedImage TYPE_INT_ARGB.
Click Source Link
From source file:edu.umn.cs.spatialHadoop.operations.GeometricPlot.java
/** * Combines images of different datasets into one image that is displayed * to users./*from w w w . j av a 2 s . co m*/ * This method is called from the web interface to display one image for * multiple selected datasets. * @param fs The file system that contains the datasets and images * @param files Paths to directories which contains the datasets * @param includeBoundaries Also plot the indexing boundaries of datasets * @return An image that is the combination of all datasets images * @throws IOException */ public static BufferedImage combineImages(Configuration conf, Path[] files, boolean includeBoundaries, int width, int height) throws IOException { BufferedImage result = null; // Retrieve the MBRs of all datasets Rectangle allMbr = new Rectangle(Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); for (Path file : files) { Rectangle mbr = FileMBR.fileMBR(file, new OperationsParams(conf)); allMbr.expand(mbr); } // Adjust width and height to maintain aspect ratio if ((allMbr.x2 - allMbr.x1) / (allMbr.y2 - allMbr.y1) > (double) width / height) { // Fix width and change height height = (int) ((allMbr.y2 - allMbr.y1) * width / (allMbr.x2 - allMbr.x1)); } else { width = (int) ((allMbr.x2 - allMbr.x1) * height / (allMbr.y2 - allMbr.y1)); } result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); for (Path file : files) { FileSystem fs = file.getFileSystem(conf); if (fs.getFileStatus(file).isDir()) { // Retrieve the MBR of this dataset Rectangle mbr = FileMBR.fileMBR(file, new OperationsParams(conf)); // Compute the coordinates of this image in the whole picture mbr.x1 = (mbr.x1 - allMbr.x1) * width / allMbr.getWidth(); mbr.x2 = (mbr.x2 - allMbr.x1) * width / allMbr.getWidth(); mbr.y1 = (mbr.y1 - allMbr.y1) * height / allMbr.getHeight(); mbr.y2 = (mbr.y2 - allMbr.y1) * height / allMbr.getHeight(); // Retrieve the image of this dataset Path imagePath = new Path(file, "_data.png"); if (!fs.exists(imagePath)) throw new RuntimeException("Image " + imagePath + " not ready"); FSDataInputStream imageFile = fs.open(imagePath); BufferedImage image = ImageIO.read(imageFile); imageFile.close(); // Draw the image Graphics graphics = result.getGraphics(); graphics.drawImage(image, (int) mbr.x1, (int) mbr.y1, (int) mbr.getWidth(), (int) mbr.getHeight(), null); graphics.dispose(); if (includeBoundaries) { // Plot also the image of the boundaries // Retrieve the image of the dataset boundaries imagePath = new Path(file, "_partitions.png"); if (fs.exists(imagePath)) { imageFile = fs.open(imagePath); image = ImageIO.read(imageFile); imageFile.close(); // Draw the image graphics = result.getGraphics(); graphics.drawImage(image, (int) mbr.x1, (int) mbr.y1, (int) mbr.getWidth(), (int) mbr.getHeight(), null); graphics.dispose(); } } } } return result; }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
/** * Draw an overlay on the image, such as a box cover specific for videosource, container, certification if wanted * * @param movie//from w w w.jav a2s. co m * @param bi * @param offsetY * @param offsetX * @return */ private BufferedImage drawOverlay(Movie movie, BufferedImage bi, int offsetX, int offsetY) { String source; if (overlaySource.equalsIgnoreCase(VIDEOSOURCE)) { source = movie.getVideoSource(); } else if (overlaySource.equalsIgnoreCase(CERTIFICATION)) { source = movie.getCertification(); } else if (overlaySource.equalsIgnoreCase(CONTAINER)) { source = movie.getContainer(); } else { source = DEFAULT; } // Make sure the source is formatted correctly source = source.toLowerCase().trim(); // Check for a blank or an UNKNOWN source and correct it if (StringTools.isNotValidString(source)) { source = DEFAULT; } String overlayFilename = source + "_overlay_" + imageType + ".png"; try { BufferedImage biOverlay = GraphicTools.loadJPEGImage(getResourcesPath() + overlayFilename); BufferedImage returnBI = new BufferedImage(biOverlay.getWidth(), biOverlay.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2BI = returnBI.createGraphics(); g2BI.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2BI.drawImage(bi, offsetX, offsetY, offsetX + bi.getWidth(), offsetY + bi.getHeight(), 0, 0, bi.getWidth(), bi.getHeight(), null); g2BI.drawImage(biOverlay, 0, 0, null); g2BI.dispose(); return returnBI; } catch (FileNotFoundException ex) { LOG.warn(LOG_FAILED_TO_LOAD, overlayFilename); } catch (IOException ex) { LOG.warn("Failed drawing overlay to {}. Please check that {} is in the resources directory.", movie.getBaseName(), overlayFilename); } return bi; }
From source file:edu.ku.brc.ui.UIRegistry.java
/** * Reads in the disciplines file (is loaded when the class is loaded). * @return Reads in the disciplines file (is loaded when the class is loaded). *///from w w w. ja v a 2 s .c om public static BufferedImage getGlassPaneBufferedImage(final int width, final int height) { BufferedImage bufImg = null; if (glassPaneBufferedImageSR != null) { bufImg = glassPaneBufferedImageSR.get(); } if (bufImg != null) { if (bufImg.getWidth() != width && bufImg.getHeight() != height) { bufImg = null; } } if (bufImg == null) { glassPaneBufferedImageSR = new SoftReference<BufferedImage>( new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB)); } return glassPaneBufferedImageSR.get(); }
From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java
private BufferedImage createFloorImage(HmFolder floor, double scale, int floorWidth, int floorHeight, Map<Long, Integer> channelMap, Map<Long, Integer> colorMap, int borderX, int borderY, double gridSize) throws Exception { BufferedImage image = new BufferedImage(floorWidth + borderX + 1, floorHeight + borderY + 1, BufferedImage.TYPE_INT_ARGB); if (floor == null) { return image; }/*from w w w . j a va 2s . c o m*/ double metricWidth = 0.0, metricHeight = 0.0, offsetX = 0.0, offsetY = 0.0; int imageWidth = 0; LengthUnit lengthUnit = LengthUnit.METERS; if (null != floor.getMetricWidth()) { metricWidth = floor.getMetricWidth().doubleValue(); } if (null != floor.getMetricHeight()) { metricHeight = floor.getMetricHeight().doubleValue(); } if (null != floor.getImageWidth()) { imageWidth = floor.getImageWidth().intValue(); } if (null != floor.getOffsetX()) { offsetX = floor.getOffsetX().doubleValue(); } if (null != floor.getOffsetY()) { offsetY = floor.getOffsetY().doubleValue(); } if (null != floor.getLengthUnit()) { lengthUnit = floor.getLengthUnit(); } Graphics2D g2 = image.createGraphics(); g2.setStroke(new BasicStroke(1)); if (getDistanceMetric(metricWidth, lengthUnit) == 0) { g2.setColor(new Color(255, 255, 255)); g2.fillRect(borderX, 0, floorWidth + 1, borderY); g2.fillRect(0, 0, borderX, borderY + floorHeight + 1); g2.setColor(new Color(120, 120, 120)); g2.drawLine(0, borderY, floorWidth + borderX, borderY); g2.drawLine(borderX, 0, borderX, floorHeight + borderY); g2.setColor(new Color(255, 255, 204)); g2.fillRect(borderX + 2, borderY + 2, 162, 25); g2.setColor(new Color(0, 51, 102)); g2.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 12)); g2.drawString("Please size this floor plan.", borderX + 8, borderY + 19); return image; } double screenWidth = scale * getDistanceMetric(metricWidth, lengthUnit); double imageScale = screenWidth / imageWidth; int originX = (int) (getDistanceMetric(offsetX, lengthUnit) * scale); int originY = (int) (getDistanceMetric(offsetY, lengthUnit) * scale); g2.setColor(new Color(255, 255, 255)); if (floor.getBackground() != null && floor.getBackground().length() > 0) { LinkedMultiValueMap<String, String> metadata = new LinkedMultiValueMap<>(); String url = getImageBaseUrl(floor.getOwnerId()) + floor.getBackground(); try { BufferedImage map = ImageIO.read(clientFileService.getFile(url, "AFS_TOKEN", metadata)); AffineTransform transform = new AffineTransform(); transform.scale(imageScale, imageScale); g2.drawImage(map, new AffineTransformOp(transform, null), getFloorX(0, borderX, originX), getFloorY(0, borderY, originY)); } catch (Exception e) { logger.error(String.format("image file not found with url: %s", url)); double screenHeight = scale * getDistanceMetric(metricHeight, lengthUnit); g2.fillRect(getFloorX(0, borderX, originX), getFloorY(0, borderY, originY), (int) screenWidth, (int) screenHeight); } } else { double screenHeight = scale * getDistanceMetric(metricHeight, lengthUnit); g2.fillRect(getFloorX(0, borderX, originX), getFloorY(0, borderY, originY), (int) screenWidth, (int) screenHeight); } g2.setColor(new Color(204, 204, 204)); // Right edge border g2.drawLine(borderX + floorWidth, borderY + 1, borderX + floorWidth, borderY + floorHeight); // Left edge border (right of tick marks) g2.drawLine(borderX + 1, borderY + floorHeight, borderX + floorWidth, borderY + floorHeight); g2.setColor(new Color(255, 255, 255)); g2.fillRect(borderX, 0, floorWidth + 1, borderY); g2.fillRect(0, 0, borderX, borderY + floorHeight + 1); g2.setColor(new Color(120, 120, 120)); g2.drawLine(0, borderY, floorWidth + borderX, borderY); g2.drawLine(borderX, 0, borderX, floorHeight + borderY); Font font = new Font(Font.SANS_SERIF, Font.BOLD, 12); double actualWidth = floorWidth / scale; double actualHeight = floorHeight / scale; String firstLabel; double unitScale = scale; if (LengthUnit.FEET == lengthUnit) { firstLabel = "0 feet"; actualWidth /= HmFolder.FEET_TO_METERS; actualHeight /= HmFolder.FEET_TO_METERS; unitScale *= HmFolder.FEET_TO_METERS; } else { firstLabel = "0 meters"; } g2.drawString(firstLabel, borderX + 4, 12); double gridX = gridSize; while (gridX < actualWidth) { int x = (int) (gridX * unitScale) + borderX; g2.drawLine(x, 0, x, borderY); boolean label = true; if (gridX + gridSize >= actualWidth) { // Last mark if (x + getNumberPixelWidth(gridX) + 2 > floorWidth) { label = false; } } if (label) { g2.drawString("" + (int) gridX, x + 4, 12); } gridX += gridSize; } double gridY = 0; while (gridY < actualHeight) { int y = (int) (gridY * unitScale) + borderY; g2.drawLine(0, y, borderX, y); double lx = gridY; int dx = 1; for (int bx = borderX; bx >= 16; bx -= 7) { if (lx < 10) { dx += 7; } else { lx /= 10; } } boolean label = true; if (gridY + gridSize >= actualHeight) { // Last mark if (y - borderY + 13 > floorHeight) { label = false; } } if (label) { g2.drawString("" + (int) gridY, dx, y + 13); } gridY += gridSize; } double mapToImage = getMapToMetric(metricWidth, imageWidth, lengthUnit) * scale; if (floor.getPerimeter().size() > 0) { g2.setStroke(new BasicStroke(2)); g2.setColor(new Color(2, 159, 245)); int[] xPoints = new int[floor.getPerimeter().size()]; int[] yPoints = new int[floor.getPerimeter().size()]; int nPoints = 0; int perimId = floor.getPerimeter().get(0).getId(); for (int i = 0; i < floor.getPerimeter().size(); i++) { HmVertex vertex = floor.getPerimeter().get(i); if (vertex.getId() != perimId) { g2.drawPolygon(xPoints, yPoints, nPoints); nPoints = 0; perimId = vertex.getId(); } xPoints[nPoints] = getFloorX((int) (vertex.getX() * mapToImage), borderX, originX); yPoints[nPoints++] = getFloorY((int) (vertex.getY() * mapToImage), borderY, originY); } g2.drawPolygon(xPoints, yPoints, nPoints); } g2.setStroke(new BasicStroke(1)); g2.setColor(new Color(0, 170, 0)); g2.setFont(font.deriveFont(Font.BOLD, 11)); List<HmDeviceLocationEx> devices = deviceLocationExRep.findAllHmDevices(floor.getId()); if (null != devices && !devices.isEmpty()) { for (HmDeviceLocationEx device : devices) { double x = device.getX() * mapToImage; double y = device.getY() * mapToImage; createNodeImage(device.getId(), channelMap, colorMap, getFloorX((int) x, borderX, originX), getFloorY((int) y, borderY, originY), g2); } } else { List<HmDevicePlanningEx> plannedDevices = devicePlanningExRep.findAllPlannedDevices(floor.getId()); for (HmDevicePlanningEx plannedDevice : plannedDevices) { double x = plannedDevice.getX() * mapToImage; double y = plannedDevice.getY() * mapToImage; createNodeImage(plannedDevice.getId(), channelMap, colorMap, getFloorX((int) x, borderX, originX), getFloorY((int) y, borderY, originY), g2); } } return image; }
From source file:base.BasePlayer.AminoTable.java
void addRowGeneheader(Object column) { Object[] obj = new Object[3]; if (Main.bedCanvas.bedTrack.size() == 0 || column instanceof BedTrack) { obj[0] = column;//from w w w .j a v a2s .c o m obj[1] = (int) geneheader.get(geneheader.size() - 1)[1] + (int) geneheader.get(geneheader.size() - 1)[2]; obj[2] = 100; geneheader.add(obj); } else { } if ((int) obj[1] + (int) obj[2] > this.getWidth()) { if (bufImage.getWidth() < (int) obj[1] + (int) obj[2]) { bufImage = MethodLibrary.toCompatibleImage( new BufferedImage((int) width * 2, (int) height, BufferedImage.TYPE_INT_ARGB)); buf = (Graphics2D) bufImage.getGraphics(); } this.setPreferredSize(new Dimension((int) obj[1] + (int) obj[2], this.getHeight())); this.revalidate(); } }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
public static Dimension2D calculateSizeOfMapInPixels(final MindMap model, final MindMapPanelConfig cfg, final boolean expandAll) { final MindMap workMap = new MindMap(model, null); workMap.resetPayload();// ww w. j av a 2 s .c om BufferedImage img = new BufferedImage(32, 32, cfg.isDrawBackground() ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB); Dimension2D blockSize = null; Graphics2D gfx = img.createGraphics(); try { Utils.prepareGraphicsForQuality(gfx); if (calculateElementSizes(gfx, workMap, cfg)) { if (expandAll) { final AbstractElement root = (AbstractElement) workMap.getRoot().getPayload(); root.collapseOrExpandAllChildren(false); calculateElementSizes(gfx, workMap, cfg); } blockSize = layoutModelElements(workMap, cfg); final double paperMargin = cfg.getPaperMargins() * cfg.getScale(); blockSize.setSize(blockSize.getWidth() + paperMargin * 2, blockSize.getHeight() + paperMargin * 2); } } finally { gfx.dispose(); } return blockSize; }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
public static BufferedImage renderMindMapAsImage(final MindMap model, final MindMapPanelConfig cfg, final boolean expandAll) { final MindMap workMap = new MindMap(model, null); workMap.resetPayload();// w w w. j av a 2 s. c o m if (expandAll) { MindMapUtils.removeCollapseAttr(workMap); } final Dimension2D blockSize = calculateSizeOfMapInPixels(workMap, cfg, expandAll); if (blockSize == null) { return null; } final BufferedImage img = new BufferedImage((int) blockSize.getWidth(), (int) blockSize.getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D gfx = img.createGraphics(); try { Utils.prepareGraphicsForQuality(gfx); gfx.setClip(0, 0, img.getWidth(), img.getHeight()); layoutFullDiagramWithCenteringToPaper(gfx, workMap, cfg, blockSize); drawOnGraphicsForConfiguration(gfx, cfg, workMap, false, null); } finally { gfx.dispose(); } return img; }
From source file:lucee.runtime.img.Image.java
public static BufferedImage toBufferedImage(java.awt.Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }//from ww w . ja v a 2 s . co m // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Determine if the image has transparent pixels; for this method's boolean hasAlpha = hasAlpha(image); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { // Determine the type of transparency of the new buffered image int transparency = Transparency.OPAQUE; if (hasAlpha) { transparency = Transparency.BITMASK; } // Create the buffered image GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency); } catch (HeadlessException e) { // The system does not have a screen } if (bimage == null) { // Create a buffered image using the default color model int type = BufferedImage.TYPE_INT_RGB; if (hasAlpha) { type = BufferedImage.TYPE_INT_ARGB; } bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); } // Copy image to buffered image Graphics g = bimage.createGraphics(); // Paint the image onto the buffered image g.drawImage(image, 0, 0, null); g.dispose(); return bimage; }
From source file:au.org.ala.biocache.web.WMSController.java
/** * Method that produces the downloadable map integrated in AVH/OZCAM/Biocache. * * @param requestParams//ww w .j av a2 s . co m * @param format * @param extents * @param widthMm * @param pointRadiusMm * @param pradiusPx * @param pointColour * @param pointOpacity * @param baselayer * @param scale * @param dpi * @param outlinePoints * @param outlineColour * @param fileName * @param request * @param response * @throws Exception */ @RequestMapping(value = { "/webportal/wms/image", "/mapping/wms/image" }, method = RequestMethod.GET) public void generatePublicationMap(SpatialSearchRequestParams requestParams, @RequestParam(value = "format", required = false, defaultValue = "jpg") String format, @RequestParam(value = "extents", required = true) String extents, @RequestParam(value = "widthmm", required = false, defaultValue = "60") Double widthMm, @RequestParam(value = "pradiusmm", required = false, defaultValue = "2") Double pointRadiusMm, @RequestParam(value = "pradiuspx", required = false) Integer pradiusPx, @RequestParam(value = "pcolour", required = false, defaultValue = "FF0000") String pointColour, @RequestParam(value = "popacity", required = false, defaultValue = "0.8") Double pointOpacity, @RequestParam(value = "baselayer", required = false, defaultValue = "world") String baselayer, @RequestParam(value = "scale", required = false, defaultValue = "off") String scale, @RequestParam(value = "dpi", required = false, defaultValue = "300") Integer dpi, @RequestParam(value = "outline", required = true, defaultValue = "false") boolean outlinePoints, @RequestParam(value = "outlineColour", required = true, defaultValue = "#000000") String outlineColour, @RequestParam(value = "fileName", required = false) String fileName, HttpServletRequest request, HttpServletResponse response) throws Exception { String[] bb = extents.split(","); double long1 = Double.parseDouble(bb[0]); double lat1 = Double.parseDouble(bb[1]); double long2 = Double.parseDouble(bb[2]); double lat2 = Double.parseDouble(bb[3]); if (lat1 <= -90) { lat1 = -89.999; } if (lat2 >= 90) { lat2 = 89.999; } int pminx = convertLngToPixel(long1); int pminy = convertLatToPixel(lat1); int pmaxx = convertLngToPixel(long2); int pmaxy = convertLatToPixel(lat2); int width = (int) ((dpi / 25.4) * widthMm); int height = (int) Math.round(width * ((pminy - pmaxy) / (double) (pmaxx - pminx))); if (height * width > MAX_IMAGE_PIXEL_COUNT) { String errorMessage = "Image size in pixels " + width + "x" + height + " exceeds " + MAX_IMAGE_PIXEL_COUNT + " pixels. Make the image smaller"; response.sendError(response.SC_NOT_ACCEPTABLE, errorMessage); throw new Exception(errorMessage); } int pointSize = -1; if (pradiusPx != null) { pointSize = (int) pradiusPx; } else { pointSize = (int) ((dpi / 25.4) * pointRadiusMm); } double[] boundingBox = transformBbox4326To900913(Double.parseDouble(bb[0]), Double.parseDouble(bb[1]), Double.parseDouble(bb[2]), Double.parseDouble(bb[3])); //"http://biocache.ala.org.au/ws/webportal/wms/reflect? //q=macropus&ENV=color%3Aff0000%3Bname%3Acircle%3Bsize%3A3%3Bopacity%3A1 //&BBOX=12523443.0512,-2504688.2032,15028131.5936,0.33920000120997&WIDTH=256&HEIGHT=256"); String speciesAddress = baseWsUrl + "/ogc/wms/reflect?" + "ENV=color%3A" + pointColour + "%3Bname%3Acircle%3Bsize%3A" + pointSize + "%3Bopacity%3A" + pointOpacity + "&BBOX=" + boundingBox[0] + "," + boundingBox[1] + "," + boundingBox[2] + "," + boundingBox[3] + "&WIDTH=" + width + "&HEIGHT=" + height + "&OUTLINE=" + outlinePoints + "&OUTLINECOLOUR=" + outlineColour + "&" + request.getQueryString(); URL speciesURL = new URL(speciesAddress); BufferedImage speciesImage = ImageIO.read(speciesURL); //"http://spatial.ala.org.au/geoserver/wms/reflect? //LAYERS=ALA%3Aworld&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES= //&FORMAT=image%2Fjpeg&SRS=EPSG%3A900913&BBOX=12523443.0512,-1252343.932,13775787.3224,0.33920000004582&WIDTH=256&HEIGHT=256" String layout = ""; if (!scale.equals("off")) { layout += "layout:scale"; } String basemapAddress = geoserverUrl + "/wms/reflect?" + "LAYERS=ALA%3A" + baselayer + "&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=" + "&FORMAT=image%2Fpng&SRS=EPSG%3A900913" //specify the mercator projection + "&BBOX=" + boundingBox[0] + "," + boundingBox[1] + "," + boundingBox[2] + "," + boundingBox[3] + "&WIDTH=" + width + "&HEIGHT=" + height + "&OUTLINE=" + outlinePoints + "&format_options=dpi:" + dpi + ";" + layout; BufferedImage basemapImage = ImageIO.read(new URL(basemapAddress)); BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D combined = (Graphics2D) img.getGraphics(); combined.drawImage(basemapImage, 0, 0, Color.WHITE, null); //combined.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, pointOpacity.floatValue())); combined.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); combined.drawImage(speciesImage, null, 0, 0); combined.dispose(); //if filename supplied, force a download if (fileName != null) { response.setContentType("application/octet-stream"); response.setHeader("Content-Description", "File Transfer"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); response.setHeader("Content-Transfer-Encoding", "binary"); } else if (format.equalsIgnoreCase("png")) { response.setContentType("image/png"); } else { response.setContentType("image/jpeg"); } if (format.equalsIgnoreCase("png")) { OutputStream os = response.getOutputStream(); ImageIO.write(img, format, os); os.close(); } else { //handle jpeg + BufferedImage.TYPE_INT_ARGB BufferedImage img2; Graphics2D c2; (c2 = (Graphics2D) (img2 = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)).getGraphics()) .drawImage(img, 0, 0, Color.WHITE, null); c2.dispose(); OutputStream os = response.getOutputStream(); ImageIO.write(img2, format, os); os.close(); } }
From source file:wsserver.EKF1TimerSessionBean.java
private boolean postMultipartSectUpd(List<CbEkfgroupUpd1csectToBx> uswps) { String charset = "UTF-8"; String requestURL = systemURL + "bitrix/ekflibraries/corpbus/manipulate_data.php"; boolean reply = true; String sreply = ""; if (uswps.isEmpty()) return reply; long allFileSize = 0; String logStr = "Upd sect cnt=" + uswps.size() + ". "; CloseableHttpClient httpclient = HttpClients.createDefault(); try {/* w w w . ja v a 2s . co m*/ MultipartUtility multipart = new MultipartUtility(requestURL, charset); HttpPost httppost = new HttpPost(requestURL); MultipartEntityBuilder reqBuilder = MultipartEntityBuilder.create(); multipart.addHeaderField("User-Agent", "CodeJava"); httppost.addHeader("User-Agent", "CodeJava"); multipart.addHeaderField("Test-Header", "Header-Value"); int index = 0; multipart.addFormField("OTYPE", "UPDATE"); reqBuilder.addPart("OTYPE", new StringBody("UPDATE", ContentType.TEXT_PLAIN)); multipart.addFormField("ENTITY", "1CSECT"); reqBuilder.addPart("ENTITY", new StringBody("1CSECT", ContentType.TEXT_PLAIN)); int ocnt = uswps.size(); multipart.addFormField("OCNT", "" + ocnt); reqBuilder.addPart("OCNT", new StringBody("" + ocnt, ContentType.TEXT_PLAIN)); //String logStr=""; for (CbEkfgroupUpd1csectToBx npwp : uswps) { multipart.addFormField("SID" + index, npwp.getSid()); reqBuilder.addPart("SID" + index, new StringBody(npwp.getSid(), ContentType.TEXT_PLAIN)); //if(!npwp.getSid().equals(npwp.getCbBxgroupId())) // multipart.addFormField("SETSID"+index, "1"); //else // multipart.addFormField("SETSID"+index, "0"); //multipart.addFormField("NEWSID"+index, npwp.getCbBxgroupId()); logStr += "[" + index + "] NAME " + npwp.getBxname() + "," + npwp.getF1cname() + "," + npwp.getBxparentId() + "," + npwp.getF1cparentId(); if (!npwp.getBxname().equals(npwp.getF1cname())) { multipart.addFormField("SETSNAME" + index, "1"); reqBuilder.addPart("SETSNAME" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETSNAME" + index, "0"); reqBuilder.addPart("SETSNAME" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } if (!npwp.getBxparentId().equals(npwp.getF1cparentId())) { multipart.addFormField("SETSGRXMLID" + index, "1"); reqBuilder.addPart("SETSGRXMLID" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETSGRXMLID" + index, "0"); reqBuilder.addPart("SETSGRXMLID" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("SNAME" + index, npwp.getF1cname()); reqBuilder.addPart("SNAME" + index, new StringBody(npwp.getF1cname(), ContentType.TEXT_PLAIN)); multipart.addFormField("SGRXMLID" + index, npwp.getF1cparentId()); reqBuilder.addPart("SGRXMLID" + index, new StringBody(npwp.getF1cparentId(), ContentType.TEXT_PLAIN)); boolean error_file_operation = false, uploadFiles = true; long sectFilesSize = 0; boolean tooLargeDsc = false, tooLargeGb = false, tooLargeDoc = false; ArrayList<String> dscFiles = new ArrayList<String>(); try { if (!npwp.getBxDescriptsJson().equals(npwp.getF1cDescriptsJson())) { //logStr+="["+npwp.getF1cDescriptsJson()+"]"; JsonReader jsonReader = Json.createReader(new StringReader(npwp.getF1cDescriptsJson())); JsonObject jo = jsonReader.readObject(); int dcount = 0; logStr += "cnt=" + jo.getString("dc", "0"); for (int i = 0; i < Tools.parseInt(jo.getString("dc", "0"), 0); i++) { logStr += ("[" + i + "]"); try { if (jo.getString("fp" + i).length() > 0 && uploadFiles) { File f = new File(mountImgPath + jo.getString("fp" + i).replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + sectFilesSize + f.length()) < maxPostFilePartSize)) { dscFiles.add(jo.getString("fp" + i).replace("\\", "/")); multipart.addFormField("FDSC" + index + "DSC" + dcount, jo.getString("dsc" + i)); multipart.addFormField("FDSC" + index + "FN" + dcount, jo.getString("fn" + i)); reqBuilder.addPart("FDSC" + index + "DSC" + dcount, new StringBody(jo.getString("dsc" + i), ContentType.TEXT_PLAIN)); reqBuilder.addPart("FDSC" + index + "FN" + dcount, new StringBody(jo.getString("fn" + i), ContentType.TEXT_PLAIN)); sectFilesSize += f.length(); dcount++; } else { tooLargeDsc = true; logStr += "Too large " + jo.getString("fp" + i); } } } catch (Exception fle) { //sectFilesSize=0; error_file_operation = true; logStr += ("NAME " + npwp.getF1cname() + " - Error dsc file operation!!! " + fle); } } if (dcount > 0) { multipart.addFormField("FDSCDC" + index, "" + dcount); reqBuilder.addPart("FDSCDC" + index, new StringBody("" + dcount, ContentType.TEXT_PLAIN)); } } } catch (Exception fle) { logStr += (npwp.getF1cname() + " Error F1cDescriptsJson parse operation!!! " + fle + "[[" + npwp.getF1cDescriptsJson() + "]]"); } ArrayList<String> gbFiles = new ArrayList<String>(); try { if (!npwp.getBxGabaritsJson().equals(npwp.getF1cGabaritsJson())) { //logStr+="["+npwp.getF1cGabaritsJson()+"]"; JsonReader jsonReader = Json.createReader(new StringReader(npwp.getF1cGabaritsJson())); JsonObject jo = jsonReader.readObject(); int dcount = 0; logStr += "cnt=" + jo.getString("dc", "0"); for (int i = 0; i < Tools.parseInt(jo.getString("dc", "0"), 0); i++) { logStr += ("[" + i + "]"); try { if (jo.getString("fp" + i).length() > 0 && uploadFiles) { File f = new File(mountImgPath + jo.getString("fp" + i).replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + sectFilesSize + f.length()) < maxPostFilePartSize)) { gbFiles.add(jo.getString("fp" + i).replace("\\", "/")); multipart.addFormField("FGB" + index + "DSC" + dcount, jo.getString("dsc" + i)); multipart.addFormField("FGB" + index + "FN" + dcount, jo.getString("fn" + i)); reqBuilder.addPart("FGB" + index + "DSC" + dcount, new StringBody(jo.getString("dsc" + i), ContentType.TEXT_PLAIN)); reqBuilder.addPart("FGB" + index + "FN" + dcount, new StringBody(jo.getString("fn" + i), ContentType.TEXT_PLAIN)); sectFilesSize += f.length(); dcount++; logStr += "[=" + dcount + "=]"; } else { tooLargeGb = true; logStr += "Too large " + jo.getString("fp" + i); } } } catch (Exception fle) { //sectFilesSize=0; error_file_operation = true; logStr += ("NAME " + npwp.getF1cname() + " - Error dsc file operation!!! " + fle); } } if (dcount > 0) { multipart.addFormField("FGBDC" + index, "" + dcount); reqBuilder.addPart("FGBDC" + index, new StringBody("" + dcount, ContentType.TEXT_PLAIN)); } } } catch (Exception fle) { logStr += (npwp.getF1cname() + " Error F1cGabaritsJson parse operation!!! " + fle + "[[" + npwp.getF1cGabaritsJson() + "]]"); } ArrayList<String> docFiles = new ArrayList<String>(); try { if (!npwp.getBxDocsJson().equals(npwp.getF1cDocsJson())) { //logStr+="["+npwp.getF1cDocsJson()+"]"; JsonReader jsonReader = Json.createReader(new StringReader(npwp.getF1cDocsJson())); JsonObject jo = jsonReader.readObject(); int dcount = 0; logStr += "cnt=" + jo.getString("dc", "0"); for (int i = 0; i < Tools.parseInt(jo.getString("dc", "0"), 0); i++) { logStr += ("[" + i + "]"); try { if (jo.getString("fp" + i).length() > 0 && uploadFiles) { File f = new File(mountImgPath + jo.getString("fp" + i).replace("\\", "/")); if (f.length() <= maxPostedDocFileSize && ((allFileSize + sectFilesSize + f.length()) < maxPostFilePartSize)) { docFiles.add(jo.getString("fp" + i).replace("\\", "/")); multipart.addFormField("FDOC" + index + "DSC" + dcount, jo.getString("dsc" + i)); //logStr+=("FDOC"+index+"FN+"+dcount+"="+jo.getString("fn"+i)); multipart.addFormField("FDOC" + index + "FN" + dcount, jo.getString("fn" + i)); reqBuilder.addPart("FDOC" + index + "DSC" + dcount, new StringBody(jo.getString("dsc" + i), ContentType.TEXT_PLAIN)); reqBuilder.addPart("FDOC" + index + "FN" + dcount, new StringBody(StringEscapeUtils.escapeJava(jo.getString("fn" + i)), ContentType.TEXT_PLAIN)); sectFilesSize += f.length(); dcount++; } else { tooLargeDoc = true; logStr += "Too large " + jo.getString("fp" + i); } } } catch (Exception fle) { //sectFilesSize=0; error_file_operation = true; logStr += ("NAME " + npwp.getF1cname() + " - Error doc file operation!!! " + fle); } } if (dcount > 0) { multipart.addFormField("FDOCDC" + index, "" + dcount); reqBuilder.addPart("FDOCDC" + index, new StringBody("" + dcount, ContentType.TEXT_PLAIN)); } } } catch (Exception fle) { logStr += (npwp.getF1cname() + " Error F1cDocsJson parse operation!!! " + fle + "[[" + npwp.getF1cDocsJson() + "]]"); } try { if (npwp.getF1cPicture().length() > 0 && npwp.getBxPicture().length() == 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getF1cPicture().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + sectFilesSize + f.length()) < maxPostFilePartSize)) { sectFilesSize += f.length(); } } } catch (Exception fle) { //sectFilesSize=0; error_file_operation = true; logStr += ("NAME " + npwp.getF1cname() + " - Error getF1cPicture file operation!!! " + fle); } try { if (npwp.getF1cMcatalog().length() > 0 && npwp.getBxMcatalog().length() == 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getF1cMcatalog().replace("\\", "/")); if (f.length() <= maxPostedDocFileSize && ((allFileSize + sectFilesSize + f.length()) < maxPostFilePartSize)) { sectFilesSize += f.length(); } } } catch (Exception fle) { //sectFilesSize=0; error_file_operation = true; logStr += ("NAME " + npwp.getF1cname() + " - Error getF1cMcatalog file operation!!! " + fle); } if ((allFileSize + sectFilesSize) > maxPostFilePartSize) { logStr += ("NAME " + npwp.getF1cname() + " - too big sect files sizes summ!!!"); //continue; } else { if (!error_file_operation) { try { if (!npwp.getF1cPicture().equals(npwp.getBxPicture()) && uploadFiles) { File f = new File(mountImgPath + npwp.getF1cPicture().replace("\\", "/")); if (f.length() <= maxPostedFileSize && ((allFileSize + f.length()) < maxPostFilePartSize)) { logStr += ",getF1cPicture " + npwp.getF1cPicture() + "fname=" + f.getName() + ",fpath=" + f.getPath() + ",flength=[" + f.length() + "]"; allFileSize += f.length(); try { BufferedImage originalImage = ImageIO.read(f); if ((originalImage.getHeight() > 400 || originalImage.getWidth() > 400) && false) { int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType(); BufferedImage resizeImageJpg = resizeImage(originalImage, type); logStr += "Not require resize"; //multipart.addFilePart("PICTURE"+index, (resizeImageJpg) ); //multipart.addFormField("SETPICTURE"+index, "1"); } else { logStr += "Not require resize"; multipart.addFilePart("PICTURE" + index, (f)); multipart.addFormField("SETPICTURE" + index, "1"); multipart.addFormField("PICTURE_PATH" + index, StringEscapeUtils.escapeJava(npwp.getF1cPicture())); reqBuilder.addPart("PICTURE" + index, new FileBody(f)); reqBuilder.addPart("SETPICTURE" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } } catch (Exception frle) { logStr += "Error resizing" + frle; multipart.addFilePart("PICTURE" + index, (f)); multipart.addFormField("SETPICTURE" + index, "1"); multipart.addFormField("PICTURE_PATH" + index, StringEscapeUtils.escapeJava(npwp.getF1cPicture())); reqBuilder.addPart("PICTURE" + index, new FileBody(f)); reqBuilder.addPart("SETPICTURE" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } } else { multipart.addFormField("SETPICTURE" + index, "0"); reqBuilder.addPart("SETPICTURE" + index, new StringBody("0", ContentType.TEXT_PLAIN)); logStr += ",getF1cPicture " + f.length() + " more " + maxPostedFileSize / 1000000 + "Mbytes or too big allFileSize"; } } } catch (Exception fle) { error_file_operation = true; logStr += ("NAME " + npwp.getF1cname() + " - Error getF1cPicture file operation!!! " + fle); } try { if (npwp.getF1cMcatalog().length() > 0 && npwp.getBxMcatalog().length() == 0 && uploadFiles) { File f = new File(mountImgPath + npwp.getF1cMcatalog().replace("\\", "/")); if (f.length() <= maxPostedDocFileSize && ((allFileSize + f.length()) < maxPostFilePartSize)) { logStr += ",getF1cMcatalog " + npwp.getF1cMcatalog(); allFileSize += f.length(); multipart.addFilePart("MASTER_CATALOG" + index, (f)); multipart.addFormField("SETMASTER_CATALOG" + index, "1"); reqBuilder.addPart("MASTER_CATALOG" + index, new FileBody(f)); reqBuilder.addPart("SETMASTER_CATALOG" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETMASTER_CATALOG" + index, "0"); reqBuilder.addPart("SETMASTER_CATALOG" + index, new StringBody("0", ContentType.TEXT_PLAIN)); logStr += ",getF1cMcatalog " + f.length() + " more " + maxPostedDocFileSize / 1000000 + "Mbytes or too big allFileSize"; } } } catch (Exception fle) { error_file_operation = true; logStr += ("NAME " + npwp.getF1cname() + " - Error getF1cMcatalog file operation!!! " + fle); } int succFilesCount = 0; for (int i = 0; i < dscFiles.size(); i++) { try { if (dscFiles.get(i).length() > 0 && uploadFiles) { File f = new File(mountImgPath + dscFiles.get(i)); long lastFSize = 0; lastFSize = f.length(); if (lastFSize <= maxPostedFileSize && ((allFileSize + lastFSize) < maxPostFilePartSize)) { logStr += ",dscFiles " + dscFiles.get(i); multipart.addFilePart("FDSC" + index + "FP" + i, (f)); multipart.addFormField("FDSC" + index + "FPSET" + i, "1"); reqBuilder.addPart("FDSC" + index + "FP" + i, new FileBody(f)); reqBuilder.addPart("FDSC" + index + "FPSET" + i, new StringBody("1", ContentType.TEXT_PLAIN)); succFilesCount++; allFileSize += lastFSize; } else { //if(lastFSize>maxPostedFileSize) // succFilesCount++; tooLargeDsc = true; multipart.addFormField("FDSC" + index + "FPSET" + i, "0"); reqBuilder.addPart("FDSC" + index + "FPSET" + i, new StringBody("0", ContentType.TEXT_PLAIN)); logStr += ",dscFiles " + f.length() + " more " + maxPostedFileSize / 1000000 + "Mbytes or too big allFileSize"; } } } catch (Exception fle) { tooLargeDsc = true; error_file_operation = true; logStr += ("NAME " + npwp.getF1cname() + " - Error dscFiles file operation!!! " + fle); } } if (!tooLargeDsc) { if ((dscFiles.size() <= 0) || ((succFilesCount >= 1) && (succFilesCount >= (int) (dscFiles.size() / 2)))) { if (!npwp.getBxDescriptsJson().equals(npwp.getF1cDescriptsJson())) { multipart.addFormField("SETDESCRIPTS_JSON" + index, "1"); reqBuilder.addPart("SETDESCRIPTS_JSON" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETDESCRIPTS_JSON" + index, "0"); reqBuilder.addPart("SETDESCRIPTS_JSON" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("DESCRIPTS_JSON" + index, StringEscapeUtils.escapeJava(npwp.getF1cDescriptsJson())); reqBuilder.addPart("DESCRIPTS_JSON" + index, new StringBody(StringEscapeUtils.escapeJava(npwp.getF1cDescriptsJson()), ContentType.TEXT_PLAIN)); } else logStr += ("NAME " + npwp.getF1cname() + " - Error dscFiles count!!! "); } succFilesCount = 0; for (int i = 0; i < gbFiles.size(); i++) { try { if (gbFiles.get(i).length() > 0 && uploadFiles) { File f = new File(mountImgPath + gbFiles.get(i)); long lastFSize = 0; lastFSize = f.length(); if (lastFSize <= maxPostedFileSize && ((allFileSize + lastFSize) < maxPostFilePartSize)) { logStr += ",gbFiles " + gbFiles.get(i); multipart.addFilePart("FGB" + index + "FP" + i, (f)); multipart.addFormField("FGB" + index + "FPSET" + i, "1"); reqBuilder.addPart("FGB" + index + "FP" + i, new FileBody(f)); reqBuilder.addPart("FGB" + index + "FPSET" + i, new StringBody("1", ContentType.TEXT_PLAIN)); succFilesCount++; allFileSize += lastFSize; } else { //if(lastFSize>maxPostedFileSize) // succFilesCount++; tooLargeGb = true; multipart.addFormField("FGB" + index + "FPSET" + i, "0"); reqBuilder.addPart("FGB" + index + "FPSET" + i, new StringBody("0", ContentType.TEXT_PLAIN)); logStr += ",gbFiles " + f.length() + " more " + maxPostedFileSize / 1000000 + "Mbytes or too big allFileSize"; } } } catch (Exception fle) { tooLargeGb = true; error_file_operation = true; logStr += ("NAME " + npwp.getF1cname() + " - Error gbrFiles file operation!!! " + fle); } } if (!tooLargeGb) { if ((gbFiles.size() <= 0) || ((succFilesCount >= 1) && (succFilesCount >= (int) (gbFiles.size() / 2)))) { if (!npwp.getBxGabaritsJson().equals(npwp.getF1cGabaritsJson())) { multipart.addFormField("SETGABARITS_JSON" + index, "1"); reqBuilder.addPart("SETGABARITS_JSON" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETGABARITS_JSON" + index, "0"); reqBuilder.addPart("SETGABARITS_JSON" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("GABARITS_JSON" + index, StringEscapeUtils.escapeJava(npwp.getF1cGabaritsJson())); reqBuilder.addPart("GABARITS_JSON" + index, new StringBody(StringEscapeUtils.escapeJava(npwp.getF1cGabaritsJson()), ContentType.TEXT_PLAIN)); } else logStr += ("NAME " + npwp.getF1cname() + " - Error gbrFiles count!!! "); } succFilesCount = 0; for (int i = 0; i < docFiles.size(); i++) { try { if (docFiles.get(i).length() > 0 && uploadFiles) { File f = new File(mountImgPath + docFiles.get(i)); long lastFSize = 0; lastFSize = f.length(); if (lastFSize <= maxPostedDocFileSize && ((allFileSize + lastFSize) < maxPostFilePartSize)) { logStr += ",docFiles " + docFiles.get(i); multipart.addFilePart("FDOC" + index + "FP" + i, (f)); multipart.addFormField("FDOC" + index + "FPSET" + i, "1"); reqBuilder.addPart("FDOC" + index + "FP" + i, new FileBody(f)); reqBuilder.addPart("FDOC" + index + "FPSET" + i, new StringBody("1", ContentType.TEXT_PLAIN)); succFilesCount++; allFileSize += lastFSize; } else { //if(lastFSize>maxPostedFileSize) // succFilesCount++; tooLargeDoc = true; multipart.addFormField("FDOC" + index + "FPSET" + i, "0"); reqBuilder.addPart("FDOC" + index + "FPSET" + i, new StringBody("0", ContentType.TEXT_PLAIN)); logStr += ",docFiles " + f.length() + " more " + maxPostedDocFileSize / 1000000 + "Mbytes or too big allFileSize"; } } } catch (Exception fle) { tooLargeDoc = true; error_file_operation = true; logStr += ("NAME " + npwp.getF1cname() + " - Error docFiles file operation!!! " + fle); } } if (!tooLargeDoc) { if ((docFiles.size() <= 0) || ((succFilesCount >= 1) && (succFilesCount >= (int) (docFiles.size() / 2)))) { if (!npwp.getBxDocsJson().equals(npwp.getF1cDocsJson())) { multipart.addFormField("SETDOCS_JSON" + index, "1"); reqBuilder.addPart("SETDOCS_JSON" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETDOCS_JSON" + index, "0"); reqBuilder.addPart("SETDOCS_JSON" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("DOCS_JSON" + index, StringEscapeUtils.escapeJava(npwp.getF1cDocsJson())); reqBuilder.addPart("DOCS_JSON" + index, new StringBody(StringEscapeUtils.escapeJava(npwp.getF1cDocsJson()), ContentType.TEXT_PLAIN)); } else logStr += ("NAME " + npwp.getF1cname() + " - Error docFiles count!!! "); } } } if (npwp.getBxSortOrder() != npwp.getF1cSortOrder()) { multipart.addFormField("SETSORT_ORDER" + index, "1"); reqBuilder.addPart("SETSORT_ORDER" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETSORT_ORDER" + index, "0"); reqBuilder.addPart("SETSORT_ORDER" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("SORT_ORDER" + index, "" + npwp.getF1cSortOrder()); reqBuilder.addPart("SORT_ORDER" + index, new StringBody("" + npwp.getF1cSortOrder(), ContentType.TEXT_PLAIN)); if (!npwp.getBxDescription().equals(npwp.getF1cDescription())) { multipart.addFormField("SETDESCRIPTION" + index, "1"); reqBuilder.addPart("SETDESCRIPTION" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETDESCRIPTION" + index, "0"); reqBuilder.addPart("SETDESCRIPTION" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("DESCRIPTION" + index, StringEscapeUtils.escapeJava(npwp.getF1cDescription())); reqBuilder.addPart("DESCRIPTION" + index, new StringBody("" + npwp.getF1cSortOrder(), ContentType.TEXT_PLAIN)); if (!npwp.getBxFullDescription().equals(npwp.getF1cFullDescription())) { multipart.addFormField("SETFULL_DESCRIPTION" + index, "1"); reqBuilder.addPart("SETFULL_DESCRIPTION" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETFULL_DESCRIPTION" + index, "0"); reqBuilder.addPart("SETFULL_DESCRIPTION" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("FULL_DESCRIPTION" + index, StringEscapeUtils.escapeJava(npwp.getF1cFullDescription())); reqBuilder.addPart("FULL_DESCRIPTION" + index, new StringBody( StringEscapeUtils.escapeJava(npwp.getF1cFullDescription()), ContentType.TEXT_PLAIN)); if (!npwp.getBxTypeCompleting().equals(npwp.getF1cTypeCompleting())) { multipart.addFormField("SETTYPE_COMPLETING" + index, "1"); reqBuilder.addPart("SETTYPE_COMPLETING" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETTYPE_COMPLETING" + index, "0"); reqBuilder.addPart("SETTYPE_COMPLETING" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("TYPE_COMPLETING" + index, StringEscapeUtils.escapeJava(npwp.getF1cTypeCompleting())); reqBuilder.addPart("TYPE_COMPLETING" + index, new StringBody( StringEscapeUtils.escapeJava(npwp.getF1cTypeCompleting()), ContentType.TEXT_PLAIN)); if (!npwp.getBxCharGabarits().equals(npwp.getF1cCharGabarits())) { multipart.addFormField("SETCHAR_GABARITS" + index, "1"); reqBuilder.addPart("SETCHAR_GABARITS" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETCHAR_GABARITS" + index, "0"); reqBuilder.addPart("SETCHAR_GABARITS" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("CHAR_GABARITS" + index, StringEscapeUtils.escapeJava(npwp.getF1cCharGabarits())); reqBuilder.addPart("CHAR_GABARITS" + index, new StringBody( StringEscapeUtils.escapeJava(npwp.getF1cCharGabarits()), ContentType.TEXT_PLAIN)); if (!npwp.getBxShortDescription().equals(npwp.getF1cShortDescription())) { multipart.addFormField("SETSHORT_DESCRIPTION" + index, "1"); reqBuilder.addPart("SETSHORT_DESCRIPTION" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETSHORT_DESCRIPTION" + index, "0"); reqBuilder.addPart("SETSHORT_DESCRIPTION" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("SHORT_DESCRIPTION" + index, StringEscapeUtils.escapeJava(npwp.getF1cShortDescription())); reqBuilder.addPart("SHORT_DESCRIPTION" + index, new StringBody( StringEscapeUtils.escapeJava(npwp.getF1cShortDescription()), ContentType.TEXT_PLAIN)); if (!npwp.getBxDocumentation().equals(npwp.getF1cDocumentation())) { multipart.addFormField("SETDOCUMENTATION" + index, "1"); reqBuilder.addPart("SETDOCUMENTATION" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETDOCUMENTATION" + index, "0"); reqBuilder.addPart("SETDOCUMENTATION" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("DOCUMENTATION" + index, StringEscapeUtils.escapeJava(npwp.getF1cDocumentation())); reqBuilder.addPart("DOCUMENTATION" + index, new StringBody( StringEscapeUtils.escapeJava(npwp.getF1cDocumentation()), ContentType.TEXT_PLAIN)); if (!npwp.getBxVideoDescription().equals(npwp.getF1cVideoDescription())) { multipart.addFormField("SETVIDEO_DESCRIPTION" + index, "1"); reqBuilder.addPart("SETVIDEO_DESCRIPTION" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETVIDEO_DESCRIPTION" + index, "0"); reqBuilder.addPart("SETVIDEO_DESCRIPTION" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("VIDEO_DESCRIPTION" + index, StringEscapeUtils.escapeJava(npwp.getF1cVideoDescription())); reqBuilder.addPart("VIDEO_DESCRIPTION" + index, new StringBody( StringEscapeUtils.escapeJava(npwp.getF1cVideoDescription()), ContentType.TEXT_PLAIN)); if (npwp.getBxCollapsevc() != npwp.getF1cCollapsevc()) { multipart.addFormField("SETCOLLAPSEVC" + index, "1"); reqBuilder.addPart("SETCOLLAPSEVC" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETCOLLAPSEVC" + index, "0"); reqBuilder.addPart("SETCOLLAPSEVC" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("COLLAPSEVC" + index, StringEscapeUtils.escapeJava("" + npwp.getF1cCollapsevc())); reqBuilder.addPart("COLLAPSEVC" + index, new StringBody( StringEscapeUtils.escapeJava("" + npwp.getF1cCollapsevc()), ContentType.TEXT_PLAIN)); if (!npwp.getBxAdvants().equals(npwp.getF1cAdvants())) { multipart.addFormField("SETADVANTS" + index, "1"); reqBuilder.addPart("SETADVANTS" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETADVANTS" + index, "0"); reqBuilder.addPart("SETADVANTS" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("ADVANTS" + index, StringEscapeUtils.escapeJava(npwp.getF1cAdvants())); reqBuilder.addPart("ADVANTS" + index, new StringBody(StringEscapeUtils.escapeJava(npwp.getF1cAdvants()), ContentType.TEXT_PLAIN)); if (!npwp.getBxFilterProps().equals(npwp.getF1cFilterProps())) { multipart.addFormField("SETFILTER_PROPS" + index, "1"); reqBuilder.addPart("SETFILTER_PROPS" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETFILTER_PROPS" + index, "0"); reqBuilder.addPart("SETFILTER_PROPS" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("FILTER_PROPS" + index, StringEscapeUtils.escapeJava(npwp.getF1cFilterProps())); reqBuilder.addPart("FILTER_PROPS" + index, new StringBody( StringEscapeUtils.escapeJava(npwp.getF1cFilterProps()), ContentType.TEXT_PLAIN)); if (!npwp.getBxSeoAliasUrl().equals(npwp.getF1cSeoAliasUrl()) && npwp.getF1cSeoAliasUrl().length() > 3) { multipart.addFormField("SETSEO_ALIAS_URL" + index, "1"); reqBuilder.addPart("SETSEO_ALIAS_URL" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETSEO_ALIAS_URL" + index, "0"); reqBuilder.addPart("SETSEO_ALIAS_URL" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("SEO_ALIAS_URL" + index, StringEscapeUtils.escapeJava(npwp.getF1cSeoAliasUrl())); reqBuilder.addPart("SEO_ALIAS_URL" + index, new StringBody( StringEscapeUtils.escapeJava(npwp.getF1cSeoAliasUrl()), ContentType.TEXT_PLAIN)); if (npwp.getBxSeoAliasUrl().length() <= 0 && npwp.getF1cSeoAliasUrl().length() <= 3 && npwp.getF1cname().length() > 0) { multipart.addFormField("SETSEO_ALIAS_URL_FROM_NAME" + index, "1"); multipart.addFormField("SEO_ALIAS_URL_FROM_NAME" + index, StringEscapeUtils.escapeJava(npwp.getF1cname())); reqBuilder.addPart("SETSEO_ALIAS_URL_FROM_NAME" + index, new StringBody("1", ContentType.TEXT_PLAIN)); reqBuilder.addPart("SEO_ALIAS_URL_FROM_NAME" + index, new StringBody( StringEscapeUtils.escapeJava(npwp.getF1cname()), ContentType.TEXT_PLAIN)); } if (!npwp.getBxSeoTitle().equals(npwp.getF1cSeoTitle())) { multipart.addFormField("SETSEO_TITLE" + index, "1"); reqBuilder.addPart("SETSEO_TITLE" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETSEO_TITLE" + index, "0"); reqBuilder.addPart("SETSEO_TITLE" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("SEO_TITLE" + index, StringEscapeUtils.escapeJava(npwp.getF1cSeoTitle())); reqBuilder.addPart("SEO_TITLE" + index, new StringBody( StringEscapeUtils.escapeJava(npwp.getF1cSeoTitle()), ContentType.TEXT_PLAIN)); if (!npwp.getBxSeoH1().equals(npwp.getF1cSeoH1())) { multipart.addFormField("SETSEO_H1" + index, "1"); reqBuilder.addPart("SETSEO_H1" + index, new StringBody("1", ContentType.TEXT_PLAIN)); } else { multipart.addFormField("SETSEO_H1" + index, "0"); reqBuilder.addPart("SETSEO_H1" + index, new StringBody("0", ContentType.TEXT_PLAIN)); } multipart.addFormField("SEO_H1" + index, StringEscapeUtils.escapeJava(npwp.getF1cSeoH1())); reqBuilder.addPart("SEO_H1" + index, new StringBody(StringEscapeUtils.escapeJava(npwp.getF1cSeoH1()), ContentType.TEXT_PLAIN)); index++; } try { if (logStr.length() > 0) cbLogsFacade.insertLog("INFO", "UPD SECT TO SEND ", "<p style=\"font-size:10px !important;\">" + logStr + "</p>"); } catch (Exception lgen) { } List<String> response = multipart.finish(); for (String line : response) { sreply = sreply + line; } /*sreply = "{}"; HttpEntity reqEntity = reqBuilder.build(); httppost.setEntity(reqEntity); //System.out.println("executing request " + httppost.getRequestLine()); try { CloseableHttpResponse clresponse = httpclient.execute(httppost); try { //System.out.println("----------------------------------------"); //clresponse.getStatusLine(); HttpEntity resEntity = clresponse.getEntity(); if (resEntity != null) { //System.out.println("Response content length: " + resEntity.getContentLength()); //resEntity.getContent(); resEntity.getContentEncoding() try { String responseString = EntityUtils.toString(resEntity, "UTF-8"); sreply = responseString; EntityUtils.consume(resEntity); } catch(Exception ee) { } } } finally { try { clresponse.close(); } catch(Exception ee) { } } } catch(Exception ee) { }*/ try { JsonReader jsonReader = Json.createReader(new StringReader(sreply)); JsonObject jobject = jsonReader.readObject(); try { cbLogsFacade.insertLog("INFO", "SUCCESS OF PARSE SERVER REPLY", "SUCCESS OF PARSE SERVER REPLY=" + jobject.toString()); } catch (Exception lge) { } try { if (jobject.getString("critical_info", "").length() > 0) cbLogsFacade.insertLog("CRITICAL_INFO", "SERVER REPLY DETAIL", jobject.getString("critical_info", "")); } catch (Exception lge) { } try { if (jobject.getString("critical_errs", "").length() > 0) cbLogsFacade.insertLog("CRITICAL_ERRS", "SERVER REPLY DETAIL", jobject.getString("critical_errs", "")); } catch (Exception lge) { } } catch (Exception pe) { try { cbLogsFacade.insertLog("ERROR", "ERROR OF PARSE SERVER REPLY", "ERROR OF PARSE SERVER REPLY" + sreply); } catch (Exception lge) { } } } catch (Exception ex) { try { cbLogsFacade.insertLog("ERROR", "ERROR of postMultipartSectUpd", logStr + " ERROR of postMultipartSectUpd " + ex); } catch (Exception lge) { } } return reply; }