public String serialize(Object value) {
      try {
        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        ObjectOutputStream objectOut = new ObjectOutputStream(bytesOut);
        objectOut.writeObject(value);
        objectOut.close();

        ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytesOut.toByteArray());
        ByteArrayOutputStream dataOut = new ByteArrayOutputStream();

        Base64Encoder enc = new Base64Encoder(bytesIn, dataOut);
        enc.process();

        return new String(dataOut.toByteArray(), "UTF-8");
      } catch (NotSerializableException e) {
        throw new JRRuntimeException("Value is not serializable", e);
      } catch (IOException e) {
        throw new JRRuntimeException(e);
      }
    }
  /**
   * @throws JRException
   * @throws IOException
   */
  public void exportImage(JRPrintImage image) throws JRException, IOException {
    xmlWriter.startElement(JRXmlConstants.ELEMENT_image);
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_scaleImage, image.getOwnScaleImageValue());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_hAlign, image.getOwnHorizontalAlignmentValue());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_vAlign, image.getOwnVerticalAlignmentValue());
    xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_isLazy, image.isLazy(), false);
    xmlWriter.addAttribute(
        JRXmlConstants.ATTRIBUTE_onErrorType, image.getOnErrorTypeValue(), OnErrorTypeEnum.ERROR);

    if (hyperlinkProducerFactory == null) {
      xmlWriter.addEncodedAttribute(
          JRXmlConstants.ATTRIBUTE_hyperlinkType,
          image.getLinkType(),
          HyperlinkTypeEnum.NONE.getName());
      xmlWriter.addEncodedAttribute(
          JRXmlConstants.ATTRIBUTE_hyperlinkReference, image.getHyperlinkReference());
      xmlWriter.addEncodedAttribute(
          JRXmlConstants.ATTRIBUTE_hyperlinkAnchor, image.getHyperlinkAnchor());
      xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_hyperlinkPage, image.getHyperlinkPage());
    } else {
      String reference = hyperlinkProducerFactory.produceHyperlink(image);
      if (reference != null) {
        xmlWriter.addAttribute(JRXmlConstants.ATTRIBUTE_hyperlinkType, HyperlinkTypeEnum.REFERENCE);
        xmlWriter.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_hyperlinkReference, reference);
      }
    }

    xmlWriter.addAttribute(
        JRXmlConstants.ATTRIBUTE_hyperlinkTarget,
        image.getLinkTarget(),
        HyperlinkTargetEnum.SELF
            .getName()); // FIXMETARGET this exporter is used in the Flash viewer
    xmlWriter.addEncodedAttribute(
        JRXmlConstants.ATTRIBUTE_hyperlinkTooltip, image.getHyperlinkTooltip());
    xmlWriter.addEncodedAttribute(JRXmlConstants.ATTRIBUTE_anchorName, image.getAnchorName());
    xmlWriter.addAttribute(
        JRXmlConstants.ATTRIBUTE_bookmarkLevel, image.getBookmarkLevel(), JRAnchor.NO_BOOKMARK);

    exportReportElement(image);
    exportBox(image.getLineBox());
    exportGraphicElement(image);

    JRRenderable renderer = image.getRenderer();
    if (renderer != null) {
      xmlWriter.startElement(JRXmlConstants.ELEMENT_imageSource);
      xmlWriter.addAttribute(
          JRXmlConstants.ATTRIBUTE_isEmbedded, isEmbeddingImages && !image.isLazy(), false);

      String imageSource = "";

      if (renderer.getType() == JRRenderable.TYPE_SVG) {
        renderer =
            new JRWrappingSvgRenderer(
                renderer,
                new Dimension(image.getWidth(), image.getHeight()),
                ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null);
      }

      if (image.isLazy()) {
        imageSource = ((JRImageRenderer) renderer).getImageLocation();
      } else if (isEmbeddingImages) {
        try {
          ByteArrayInputStream bais = new ByteArrayInputStream(renderer.getImageData());
          ByteArrayOutputStream baos = new ByteArrayOutputStream();

          Base64Encoder encoder = new Base64Encoder(bais, baos);
          encoder.process();

          imageSource = new String(baos.toByteArray(), DEFAULT_XML_ENCODING);
        } catch (IOException e) {
          throw new JRException("Error embedding image into XML.", e);
        }
      } else {
        if (renderer.getType() == JRRenderable.TYPE_IMAGE
            && rendererToImagePathMap.containsKey(renderer)) {
          imageSource = rendererToImagePathMap.get(renderer);
        } else {
          imageSource = IMAGE_PREFIX + getNextImageId();
          imageNameToImageDataMap.put(imageSource, renderer.getImageData());

          imageSource = new File(imagesDir, imageSource).getPath();
          rendererToImagePathMap.put(renderer, imageSource);
        }
      }

      xmlWriter.writeCDATA(imageSource);
      xmlWriter.closeElement();
    }

    if (hyperlinkProducerFactory == null) {
      exportHyperlinkParameters(image);
    }

    xmlWriter.closeElement();
  }
Пример #3
0
  public void run() {
    try {
      // Thread.currentThread().setContextClassLoader(it.businesslogic.ireport.gui.MainFrame.getMainInstance().getReportClassLoader() );

      java.util.Properties props =
          it.businesslogic.ireport.gui.MainFrame.getMainInstance().getProperties();

      if (props.getProperty("update.useProxy", "false").equals("true")) {
        System.getProperties().put("proxySet", "true");

        String urlProxy = props.getProperty("update.proxyUrl", "");
        String port = "8080";
        String server = urlProxy;
        if (urlProxy.indexOf(":") > 0) {
          port = urlProxy.substring(urlProxy.indexOf(":") + 1);
          server = urlProxy.substring(0, urlProxy.indexOf(":"));
        }

        System.getProperties().put("proxyHost", server);
        System.getProperties().put("proxyPort", port);

        MainFrame.getMainInstance().logOnConsole("Using proxy: " + urlProxy);
      }

      java.net.URL url = new java.net.URL("http://ireport.sf.net/lastversion.php");

      byte[] webBuffer = new byte[100];
      URLConnection uConn = url.openConnection();

      if (props.getProperty("update.useProxy", "false").equals("true")
          && props.getProperty("update.useAuth", "false").equals("true")) {
        String password =
            props.getProperty("update.username", "")
                + ":"
                + props.getProperty("update.password", "");

        org.w3c.tools.codec.Base64Encoder b = new org.w3c.tools.codec.Base64Encoder(password);
        String encodedPassword = b.processString();
        uConn.setRequestProperty("Proxy-Authorization", encodedPassword);
      }

      // uConn.setReadTimeout(1000);
      java.io.InputStream is = uConn.getInputStream();
      int readed = is.read(webBuffer);
      String version = new String(webBuffer, 0, readed);
      if (version.toLowerCase().startsWith("ireport")) {
        if (version.compareTo(it.businesslogic.ireport.gui.MainFrame.constTitle) > 0) {

          final String fversion = version;
          javax.swing.SwingUtilities.invokeLater(
              new Runnable() {
                public void run() {
                  javax.swing.JOptionPane.showMessageDialog(
                      it.businesslogic.ireport.gui.MainFrame.getMainInstance(),
                      I18n.getFormattedString(
                          "messages.upgradeSearch.newVersion",
                          "{0} is available on http://ireport.sf.net!",
                          new Object[] {fversion}));
                }
              });
        }
      }
    } catch (Throwable ex) {
      ex.printStackTrace();
    }

    if (win != null) win.setVisible(false);
  }