Transforms the source for the content output to the result.  If
the transformer is not specified, an identity transform sends
the source to the result.  When writing, the result is stored
in the database
@param result	the receiver of the transform output
499576
public void transform(Result result) {
    if (logger.isInfoEnabled())
      logger.info("Transforming source into result");
    try {
      if (content == null) {
        throw new IllegalStateException("No source to transform");
      }

      Transformer transformer = null;
      if (this.transformer != null) {
        transformer = getTransformer();
      } else {
        if (logger.isWarnEnabled())
          logger.warn("No transformer, so using identity transform");
        transformer = TransformerFactory.newInstance().newTransformer();
      }

      transformer.transform(content, result);
    } catch (TransformerException e) {
      logger.error("Failed to transform source into result",e);
      throw new MarkLogicIOException(e);
    }
  }
1148631
private void addResult(ValidationResult result) {
		if (result == null || result.count() == 0) {
			return;
		}
		this.results.add(result);
	}
654366
public static void check(final Object result, final Class<?> targetType) {
        if (result != null && !targetType.isAssignableFrom(result.getClass())) {
            // note: conversion logic may go wrong (e.g. because converter expect collection input mostly and may
            // not work correctly for single element), but anyway overall conversion would be considered failed.
            throw new ResultConversionException(String.format("Failed to convert %s to %s",
                    toStringType(result), targetType.getSimpleName()));
        }
    }
432934
@Override
    public void handleResult(RHI result) {
        if (wrappedResultHandler != null) {
            wrappedResultHandler.handleResult(resultTransformer.transform(result));
        }
    }
997150
public <T> void publisher(Class<T> api,
                          Result<T> result)
  {
    String path = api.getName();
      
    String address = address(path);
      
    ServicesAmp manager = ServicesAmp.current();
    ServiceRefAmp pubRef = manager.service(address);
      
    result.ok(pubRef.as(api));
  }
1122282
@Override
    public void marshal(Object graph, Result result) throws IOException, XmlMappingException {
        @SuppressWarnings("unchecked")
        final Tuple<String, Element> data = (Tuple<String, Element>) graph;

        final Transformer transformer;
        try {
            transformer = this.xmlUtilities.getIdentityTransformer();
        } catch (TransformerConfigurationException e) {
            throw new RuntimeException("Failed to load identity Transformer", e);
        }

        // Setup the transformer to pretty-print the output
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

        try {
            transformer.transform(new DocumentSource(data.second), result);
        } catch (TransformerException e) {
            throw new RuntimeException("Failed to write Element to Result for: " + data.first, e);
        }
    }
1155348
public static void transformDocumentToXml(DomDocument document, StreamResult result) {
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    try {
      Transformer transformer = transformerFactory.newTransformer();
      transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
      transformer.setOutputProperty(OutputKeys.INDENT, "yes");
      transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

      synchronized(document) {
        transformer.transform(document.getDomSource(), result);
      }
    } catch (TransformerConfigurationException e) {
      throw new ModelIoException("Unable to create a transformer for the model", e);
    } catch (TransformerException e) {
      throw new ModelIoException("Unable to transform model to xml", e);
    }
  }
1108628
private void writeResult(Object result) throws IOException {
		File outputFile = new File(outputFileLocation);
		File tempfile = FileSupport.createFile(tempOutputFileLocation);
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream(tempfile);
			PrintStream ps = new PrintStream(new FileOutputStream(tempfile));
			if (result != null) {
				if (result instanceof Throwable) {
					((Throwable) result).printStackTrace(ps);
				}
				ps.println(result.toString());
			}
			ps.close();
		} finally {
			fos.close();
		}

		if (outputFile.exists()) {
			boolean success = outputFile.delete();
		}

		boolean success = tempfile.renameTo(new File(outputFileLocation));
	}
367655
public void transform(Source source, boolean shouldRelease) throws TransformerException
  {

    try
    {
        
      // Patch for bugzilla #13863.  If we don't reset the namespaceContext
      // then we will get a NullPointerException if transformer is reused 
      // (for stylesheets that use xsl:key).  Not sure if this should go 
      // here or in reset(). -is  
      if(getXPathContext().getNamespaceContext() == null){
         getXPathContext().setNamespaceContext(getStylesheet());
      }
      String base = source.getSystemId();
      
      // If no systemID of the source, use the base of the stylesheet.
      if(null == base)
      {
        base = m_stylesheetRoot.getBaseIdentifier();
      }

      // As a last resort, use the current user dir.
      if(null == base)
      {
        String currentDir = "";
        try {
          currentDir = System.getProperty("user.dir");
        }
        catch (SecurityException se) {}// user.dir not accessible from applet
              
        if (currentDir.startsWith(java.io.File.separator))
          base = "file://" + currentDir;
        else
          base = "file:///" + currentDir;
        
        base = base + java.io.File.separatorChar
               + source.getClass().getName();
      }
      setBaseURLOfSource(base);
      DTMManager mgr = m_xcontext.getDTMManager();
      /*
       * According to JAXP1.2, new SAXSource()/StreamSource()
       * should create an empty input tree, with a default root node. 
       * new DOMSource()creates an empty document using DocumentBuilder.
       * newDocument(); Use DocumentBuilder.newDocument() for all 3 situations,
       * since there is no clear spec. how to create an empty tree when
       * both SAXSource() and StreamSource() are used.
       */
      if ((source instanceof StreamSource && source.getSystemId()==null &&
         ((StreamSource)source).getInputStream()==null &&
         ((StreamSource)source).getReader()==null)||
         (source instanceof SAXSource &&
         ((SAXSource)source).getInputSource()==null &&
         ((SAXSource)source).getXMLReader()==null )||
         (source instanceof DOMSource && ((DOMSource)source).getNode()==null)){
        try {
          DocumentBuilderFactory builderF = 
                   DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = builderF.newDocumentBuilder();
          String systemID = source.getSystemId();
          source = new DOMSource(builder.newDocument());

          // Copy system ID from original, empty Source to new Source
          if (systemID != null) {
            source.setSystemId(systemID);
          }
        } catch (ParserConfigurationException e) {
          fatalError(e);
        }           
      }
      DTM dtm = mgr.getDTM(source, false, this, true, true);
      dtm.setDocumentBaseURI(base);
      
      boolean hardDelete = true;  // %REVIEW% I have to think about this. -sb

      try
      {
      	// NOTE: This will work because this is _NOT_ a shared DTM, and thus has
      	// only a single Document node. If it could ever be an RTF or other
      	// shared DTM, look at dtm.getDocumentRoot(nodeHandle).
        this.transformNode(dtm.getDocument());
      }
      finally
      {
        if (shouldRelease)
          mgr.release(dtm, hardDelete);
      }

      // Kick off the parse.  When the ContentHandler gets 
      // the startDocument event, it will call transformNode( node ).
      // reader.parse( xmlSource );
      // This has to be done to catch exceptions thrown from 
      // the transform thread spawned by the STree handler.
      Exception e = getExceptionThrown();

      if (null != e)
      {
        if (e instanceof javax.xml.transform.TransformerException)
        {
          throw (javax.xml.transform.TransformerException) e;
        }
        else if (e instanceof org.apache.xml.utils.WrappedRuntimeException)
        {
          fatalError(
              ((org.apache.xml.utils.WrappedRuntimeException) e).getException());
        }
        else
        {
          throw new javax.xml.transform.TransformerException(e);
        }
      }
      else if (null != m_serializationHandler)
      {
        m_serializationHandler.endDocument();
      }
    }
    catch (org.apache.xml.utils.WrappedRuntimeException wre)
    {
      Throwable throwable = wre.getException();

      while (throwable
             instanceof org.apache.xml.utils.WrappedRuntimeException)
      {
        throwable =
          ((org.apache.xml.utils.WrappedRuntimeException) throwable).getException();
      }

      fatalError(throwable);
    }

    // Patch attributed to David Eisenberg <david@catcode.com>
    catch (org.xml.sax.SAXParseException spe)
    {
      fatalError(spe);
    }
    catch (org.xml.sax.SAXException se)
    {
      m_errorHandler.fatalError(new TransformerException(se));
    }
    finally
    {
      m_hasTransformThreadErrorCatcher = false;

      // This looks to be redundent to the one done in TransformNode.
      reset();
    }
  }
1327590
@Override
    public void handle(T result, HttpResponse response) {
        String transitionHeader = response.getHeaders().get(Headers.IBM_TRANSITION);
        if (transitionHeader != null) {
            result.setTransitionDate(parseDate(transitionHeader));
            String transition = parseTransition(transitionHeader);
            if (transition != null) {
                result.setTransition(transition);
            }
        }
    }
509890
private void assignReferenceToProxy(List results)
    {
        if (results != null)
        {
            for (Object obj : results)
            {
                kunderaMetadata.getCoreMetadata().getLazyInitializerFactory().setProxyOwners(getEntityMetadata(), obj);
            }
        }
    }
499672
public void writeContent(final OutputStream result) throws IOException
    {
		this.shapeNr = this.doc.getRandomInt();
		
		this.properties.put("ShapeType", new RtfShapeProperty("ShapeType", this.type));
		if(this.position.isShapeBelowText()) {
			this.properties.put("fBehindDocument", new RtfShapeProperty("fBehindDocument", true));
		}
		if(this.inTable) {
			this.properties.put("fLayoutInCell", new RtfShapeProperty("fLayoutInCell", true));
		}
		if(this.properties.containsKey("posh")) {
			this.position.setIgnoreXRelative(true);
		}
		if(this.properties.containsKey("posv")) {
			this.position.setIgnoreYRelative(true);
		}
    	
    	result.write(OPEN_GROUP);
    	result.write(DocWriter.getISOBytes("\\shp"));
    	result.write(DocWriter.getISOBytes("\\shplid"));
    	result.write(intToByteArray(this.shapeNr));
    	this.position.writeContent(result);
    	switch(this.wrapping) {
    	case SHAPE_WRAP_NONE:
    		result.write(DocWriter.getISOBytes("\\shpwr3"));
    		break;
    	case SHAPE_WRAP_TOP_BOTTOM:
    		result.write(DocWriter.getISOBytes("\\shpwr1"));
    		break;
    	case SHAPE_WRAP_BOTH:
    		result.write(DocWriter.getISOBytes("\\shpwr2"));
    		result.write(DocWriter.getISOBytes("\\shpwrk0"));
    		break;
    	case SHAPE_WRAP_LEFT:
    		result.write(DocWriter.getISOBytes("\\shpwr2"));
    		result.write(DocWriter.getISOBytes("\\shpwrk1"));
    		break;
    	case SHAPE_WRAP_RIGHT:
    		result.write(DocWriter.getISOBytes("\\shpwr2"));
    		result.write(DocWriter.getISOBytes("\\shpwrk2"));
    		break;
    	case SHAPE_WRAP_LARGEST:
    		result.write(DocWriter.getISOBytes("\\shpwr2"));
    		result.write(DocWriter.getISOBytes("\\shpwrk3"));
    		break;
    	case SHAPE_WRAP_TIGHT_BOTH:
    		result.write(DocWriter.getISOBytes("\\shpwr4"));
    		result.write(DocWriter.getISOBytes("\\shpwrk0"));
    		break;
    	case SHAPE_WRAP_TIGHT_LEFT:
    		result.write(DocWriter.getISOBytes("\\shpwr4"));
    		result.write(DocWriter.getISOBytes("\\shpwrk1"));
    		break;
    	case SHAPE_WRAP_TIGHT_RIGHT:
    		result.write(DocWriter.getISOBytes("\\shpwr4"));
    		result.write(DocWriter.getISOBytes("\\shpwrk2"));
    		break;
    	case SHAPE_WRAP_TIGHT_LARGEST:
    		result.write(DocWriter.getISOBytes("\\shpwr4"));
    		result.write(DocWriter.getISOBytes("\\shpwrk3"));
    		break;
    	case SHAPE_WRAP_THROUGH:
    		result.write(DocWriter.getISOBytes("\\shpwr5"));
    		break;
    	default:
    		result.write(DocWriter.getISOBytes("\\shpwr3"));
    	}
    	if(this.inHeader) {
    		result.write(DocWriter.getISOBytes("\\shpfhdr1"));
    	} 
    	this.doc.outputDebugLinebreak(result);
    	result.write(OPEN_GROUP);
    	result.write(DocWriter.getISOBytes("\\*\\shpinst"));
    	Iterator it = this.properties.values().iterator();
    	while(it.hasNext()) {
    		RtfShapeProperty rsp = (RtfShapeProperty) it.next();
    		rsp.setRtfDocument(this.doc);
    		rsp.writeContent(result);
    	}
    	if(!this.shapeText.equals("")) {
    		result.write(OPEN_GROUP);
    		result.write(DocWriter.getISOBytes("\\shptxt"));
    		result.write(DELIMITER);
    		result.write(DocWriter.getISOBytes(this.shapeText));
    		result.write(CLOSE_GROUP);
    	}
    	result.write(CLOSE_GROUP);
    	this.doc.outputDebugLinebreak(result);
    	result.write(CLOSE_GROUP);
		
    }
307689
public void transform( InputStream xmlIS,
                           InputStream xslIS,
                           Map params,
                           OutputStream result,
                           String encoding) {
        try {
            TransformerFactory trFac = TransformerFactory.newInstance();
            Transformer transformer = trFac.newTransformer(new StreamSource(xslIS));
            Iterator it = params.keySet().iterator();
            while (it.hasNext()) {
                String key = (String)it.next();
                transformer.setParameter(key, (String)params.get(key));
            }
            transformer.setOutputProperty("encoding", encoding);
            transformer.transform(new StreamSource(xmlIS), new StreamResult(result));
        } catch (Exception e) {
            getLogger().severe("XmlHttpProxy: Exception with xslt " + e);
        }
    }
1219811
public void setResultProperties(AbstractWrapperIdPages results) {
        // There are no values to copy
        results.setId(0);
        results.setPage(0);
        results.setTotalPages(0);
        results.setTotalResults(0);
    }
1162576
public boolean copyMessageToResult(javax.xml.transform.Result resultTarget)
   {
       Node tree = this.getDOM();
       return Utility.copyTreeToResult(tree, resultTarget);
   }
317856
public void writeContent(final OutputStream result) throws IOException
    {
        if(this.background != null) {
            result.write(OPEN_GROUP);
        }
        
        this.font.writeBegin(result);
        if(superSubScript < 0) {
            result.write(FONT_SUBSCRIPT);
        } else if(superSubScript > 0) {
            result.write(FONT_SUPERSCRIPT);
        }
        if(this.background != null) {
            result.write(BACKGROUND_COLOR);
            result.write(intToByteArray(this.background.getColorNumber()));
        }
        result.write(DELIMITER);
        document.filterSpecialChar(result, content, false, softLineBreaks || this.document.getDocumentSettings().isAlwaysGenerateSoftLinebreaks());
        
        if(superSubScript != 0) {
            result.write(FONT_END_SUPER_SUBSCRIPT);
        }
        this.font.writeEnd(result);
        
        if(this.background != null) {
            result.write(CLOSE_GROUP);
        }    	
    }
1092347
public void execute(
          TransformerImpl transformer)
            throws TransformerException
  {
    try
    {
      SerializationHandler rth = transformer.getResultTreeHandler();

        if (m_disableOutputEscaping)
      {
        rth.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
      }

      rth.characters(m_ch, 0, m_ch.length);

      if (m_disableOutputEscaping)
      {
        rth.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
      }
    }
    catch(SAXException se)
    {
      throw new TransformerException(se);
    }
  }