Package com.webobjects.foundation

Examples of com.webobjects.foundation.NSData


  public String asString() {
    return entityName() + "." + ERXEOControlUtilities.primaryKeyStringForGlobalID(this);
  }

  public NSData asData() {
    return new NSData(asString().getBytes());
  }
View Full Code Here


    super.appendToResponse(response, aContext);
    if (enabled()) {
      File tempFile = null;
      File psFile = null;
      try {
        NSData content = response.content();
        tempFile = File.createTempFile("pdftops", "pdf");
        tempFile.deleteOnExit();
        psFile = File.createTempFile("pdftops", "ps");
        psFile.deleteOnExit();
        NSMutableArray<String> array = new NSMutableArray<String>(pdftops, "-expand", tempFile.getPath(), psFile.getPath());
        if (duplex()) {
          array.add(1, "-duplex");
        }
        content.writeToStream(new FileOutputStream(tempFile));
        Process process = Runtime.getRuntime().exec(array.toArray(new String[array.size()]));
        process.waitFor();
        NSData data = new NSData(new FileInputStream(psFile), 4096);
        String header = response.headerForKey("content-disposition");
        response.setHeader(header.replace(".pdf", ".ps"), "content-disposition");
        response.setHeader("application/postscript", "Content-Type");
        response.setHeader(String.valueOf(data.length()), "Content-Length");
        response.setContent(data);
      } catch (FileNotFoundException e) {
        throw NSForwardException._runtimeExceptionForThrowable(e);
      } catch (IOException e) {
        throw NSForwardException._runtimeExceptionForThrowable(e);
View Full Code Here

    if (element.getNodeName().equals("img")
        && element.getAttribute("src").matches(".*/wr\\?wodata=[\\-0-9]*$")) {
      String key = element.getAttribute("src").replaceFirst(".*/wr\\?wodata=(.*)", "$1");
      try {
        NSData data = cachedDataForKey(key);
        FSImage fsImage = new ITextFSImage(Image.getInstance(data.bytes()));
        if (cssWidth != -1 || cssHeight != -1) {
          fsImage.scale(cssWidth, cssHeight);
        }
        return new ITextImageElement(fsImage);
      } catch (Exception e) {
View Full Code Here

  public String name() {
    return _name;
  }
 
  public String process(SeleniumTest test) {
    WORequest request = WOApplication.application().createRequest("GET", WOApplication.application().baseURL(), "HTTP/1.1", new NSDictionary(), new NSData(), new NSDictionary());
    assert(request != null);
    WOContext context = WOApplication.application().createContextForRequest(request);
    assert(context != null);
    WOComponent component = WOApplication.application().pageWithName(_componentName, context);
    assert(component != null);
View Full Code Here

      if (hasBinding(Bindings.data)) {
        if (hasBinding(Bindings.filePath)) {
          NSArray aValue = request.formValuesForKey(uploadName());

          if (aValue != null) {
            NSData data = null;
            try {
              data = (NSData) aValue.objectAtIndex(0);
            } catch (ClassCastException e) {
              throw new ClassCastException("AjaxUploadButton: Value in request was of type '" + aValue.objectAtIndex(0).getClass().getName() + "' instead of NSData. Verify that the WOForm's 'enctype' binding is set to 'multipart/form-data'");
            }
View Full Code Here

  public String name() {
    return "presentation";
  }
 
  public String process(SeleniumTest test) {
    WORequest request = WOApplication.application().createRequest("GET", WOApplication.application().baseURL(), "HTTP/1.1", new NSDictionary(), new NSData(), new NSDictionary());
    WOContext context = WOApplication.application().createContextForRequest(request);
    WOComponent component = WOApplication.application().pageWithName(PRESENTATION_COMPONENT, context);
    WOResponse response = WOApplication.application().createResponseInContext(context);
    assert(request != null && context != null && component != null && response != null);
   
View Full Code Here

    EOEditingContext ec = ERXEC.newEditingContext();
    Company.createCompany(ec, "Some fruit company");
   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = null;
    NSData data = null;

    try {
      oos = new ObjectOutputStream(baos);
      oos.writeObject(ec);
      oos.flush();
      byte[] bytes = baos.toByteArray();
      data = new NSData(bytes);
    } finally {
      if (oos != null) {
        oos.close();
      }
    }
   
    Object object = null;
    byte[] bytes = data.bytes();
    ObjectInputStream ois = null;
    try {
      ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
      object = ois.readObject();
    } finally {
View Full Code Here

  public void testFromData() {

    int pk = ERXTestUtilities.pkOne(ec, co);
   
    ERXKeyGlobalID xkgid = ERXKeyGlobalID.fromData(new NSData((Company.ENTITY_NAME+"."+pk).getBytes()));
    Assert.assertNotNull(xkgid);
  }
View Full Code Here

    int pk = ERXTestUtilities.pkOne(ec, co);

    ERXKeyGlobalID xkgid1 = new ERXKeyGlobalID(Company.ENTITY_NAME, new Integer[] { pk });
    Assert.assertEquals(gid, xkgid1.globalID());
       
    ERXKeyGlobalID xkgid2 = ERXKeyGlobalID.fromData(new NSData((Company.ENTITY_NAME+"."+pk).getBytes()));
    Assert.assertEquals(gid, xkgid2.globalID());

    ERXKeyGlobalID xkgid3 = ERXKeyGlobalID.fromString(Company.ENTITY_NAME+"."+pk);
    Assert.assertEquals(gid, xkgid3.globalID());
  }
View Full Code Here

      Country country = Country.createCountry(ec, "USA", "United States of America");
      country.setCapital(city);
      try {
        // make sure blobs work
        NSData flag = new NSData(ERXFileUtilities.inputStreamForResourceNamed("us.png", null, null), 1024);
        country.setFlag(flag);
      } catch (IOException e) {
        log.error(org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(e), e);
        throw new RuntimeException(e.getMessage(), e);
      }
View Full Code Here

TOP

Related Classes of com.webobjects.foundation.NSData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.