/*
(non-Javadoc)

@see
org.archive.wayback.replay.html.StringTransformer#transform(org.archive
.wayback.replay.html.ReplayParseContext, java.lang.String)
326028
public String transform(ReplayParseContext context, String input) {
		// Ex. <META HTTP-EQUIV="Refresh" CONTENT="0; URL=/ics/default.asp">
		// input receives the value of the "CONTENT" attribute.
		// So, we need to search for the "URL=", take everything to the right of
		// that, trim it, contextualize it, and return that.
		Matcher m = refreshURLPattern.matcher(input);
		if (m.matches()) {
			if (m.groupCount() == 1) {
				String url = m.group(1);
				String replayUrl = context.contextualizeUrl(url);
				if (replayUrl != url) {
					input = input.substring(0, m.start(1)) + replayUrl +
							input.substring(m.end(1));
				}
			}
		}
		return input;
	}
618999
public Object transformObject(TransformationDescription description, Object source, Object target)
        throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        checkNeededValues(description);
        Class<?> sourceClass = modelRegistry.loadModel(description.getSourceModel());
        Class<?> targetClass = modelRegistry.loadModel(description.getTargetModel());
        if (!sourceClass.isAssignableFrom(source.getClass())) {
            throw new IllegalArgumentException("The given source object does not match the given description");
        }
        this.source = source;
        if (target == null) {
            this.target = targetClass.newInstance();
        } else {
            this.target = target;
        }
        for (TransformationStep step : description.getTransformingSteps()) {
            performTransformationStep(step);
        }
        return this.target;
    }
896699
@Override
    protected Map<String, Object> transformElement(T entity) {
        try {
            return UtilJdbc.getRowFromObject(entity);
        } catch(IllegalAccessException | InvocationTargetException | InstantiationException e) {
            throw new DeepTransformException(e);
        }
    }
748347
@Override
	public void accept(final TransformContext transformContext) {
		TransformContext childCtx = transformContext.copyTransformContext();
		super.accept(childCtx);
		if (childCtx.isEnabled()) {
			transformContext.addSqlPart(childCtx.getExecutableSql());
			transformContext.addBindNames(childCtx.getBindNames());
			transformContext.addBindVariables(childCtx.getBindVariables());
			passState(true);
		} else {
			passState(false);
		}
	}
304318
function relayRelayDirectiveTransform(
  context: CompilerContext,
): CompilerContext {
  return IRTransformer.transform(context, {
    Fragment: visitRelayMetadata(fragmentMetadata),
    FragmentSpread: visitRelayMetadata(fragmentSpreadMetadata),
  });
}
747298
protected String transformMardownLinks(String content, ReferenceContext references) {
		if (!isMarkdownToHtmlReferenceTransformation()) {
			return content;
		}

		// Prepare replacement data structures
		final Map<BasedSequence, String> replacements = new TreeMap<>((cmp1, cmp2) -> {
			final int cmp = Integer.compare(cmp2.getStartOffset(), cmp1.getStartOffset());
			if (cmp != 0) {
				return cmp;
			}
			return Integer.compare(cmp2.getEndOffset(), cmp1.getEndOffset());
		});

		// Visit the links and record the transformations
		final MutableDataSet options = new MutableDataSet();
		final Parser parser = Parser.builder(options).build();
		final Node document = parser.parse(content);
		final NodeVisitor visitor = new NodeVisitor(
				new VisitHandler<>(Link.class, it -> {
					URL url = FileSystem.convertStringToURL(it.getUrl().toString(), true);
					url = transformURL(url, references);
					if (url != null) {
						replacements.put(it.getUrl(), convertURLToString(url));
					}
				}));
		visitor.visitChildren(document);

		// Apply the replacements
		if (!replacements.isEmpty()) {
			final StringBuilder buffer = new StringBuilder(content);
			for (final Entry<BasedSequence, String> entry : replacements.entrySet()) {
				final BasedSequence seq = entry.getKey();
				buffer.replace(seq.getStartOffset(), seq.getEndOffset(), entry.getValue());
			}
			return buffer.toString();
		}
		return content;
	}
847501
@Override
    public Object transform( Object input ) {

        // Wrap the input in a map to fool the CompositeSpec to recurse itself.
        Map<String,Object> wrappedMap = new HashMap<>();
        wrappedMap.put(ROOT_KEY, input);
        rootSpec.applyToMap( wrappedMap );
        return input;
    }
841227
public Object transform( int to, Object input, Map<String, Object> context ) {
        return transform( 0, to, input, context );
    }
343697
public void transform(String name, String transform) throws Exception {

        File configFile = new File(m_configDir, name);
        File transformFile = new File(m_xsltDir, transform);
        try (InputStream stream = new FileInputStream(transformFile)) {
            StreamSource source = new StreamSource(stream);
            transform(configFile, source);
        }
    }
773679
public void transform(Source xmlSource, Result outputTarget, boolean shouldRelease)
          throws TransformerException
  {

    synchronized (m_reentryGuard)
    {
      SerializationHandler xoh = createSerializationHandler(outputTarget);
      this.setSerializationHandler(xoh);        

      m_outputTarget = outputTarget;

      transform(xmlSource, shouldRelease);
    }
  }
244624
public static <T extends ViewTraverse<T>> Map<String, Object> replaceDataReferences(
            final Map<String, Object> input,
            final T currentContext,
            final BiFunction<Integer, String, T> viewMap,
            final Converter<String, String> converter,
            final MultiDataContext<T, DataContext> data,
            boolean failOnUnexpanded,
            boolean blankIfUnexpanded
    )
    {
        final HashMap<String, Object> output = new HashMap<>();
        for (final String s : input.keySet()) {
            Object o = input.get(s);
            output.put(
                    s,
                    replaceDataReferencesInObject(o,
                                                  currentContext,
                                                  viewMap,
                                                  converter,
                                                  data,
                                                  failOnUnexpanded,
                                                  blankIfUnexpanded
                    )
            );
        }
        return output;
    }
651302
@Override
	public void accept(final TransformContext transformContext) {
		Object value = eval(transformContext);

		transformContext.addSqlPart("?");
		if (outputBindComment) {
			transformContext.addSqlPart("/*").addSqlPart(expression).addSqlPart("*/");
		}
		transformContext.addBindName(expression);
		transformContext.addBindVariable(value);
		pass();
	}
146907
@Override
	public ContextTransformer parse() {
		push(new ContainerNode(0, 0));
		while (TokenType.EOF != tokenizer.next()) {
			parseToken();
		}
		return new ContextTransformer(pop());
	}
736304
public void setTransform(final Document xsltdoc)
            throws TransformerConfigurationException {
        //
        //  scan transform source for xsl:output elements
        //    and extract encoding, media (mime) type and output method
        //
        String encodingName = null;
        mediaType = null;
        String method = null;
        NodeList nodes = xsltdoc.getElementsByTagNameNS(
                XSLT_NS,
                "output");
        for(int i = 0; i < nodes.getLength(); i++) {
            Element outputElement = (Element) nodes.item(i);
            if (method == null || method.length() == 0) {
                method = outputElement.getAttributeNS(null, "method");
            }
            if (encodingName == null || encodingName.length() == 0) {
                encodingName = outputElement.getAttributeNS(null, "encoding");
            }
            if (mediaType == null || mediaType.length() == 0) {
                mediaType = outputElement.getAttributeNS(null, "media-type");
            }
        }

        if (mediaType == null || mediaType.length() == 0) {
            if ("html".equals(method)) {
                mediaType = "text/html";
            } else if ("xml".equals(method)) {
                mediaType = "text/xml";
            } else {
                mediaType = "text/plain";
            }
        }

        //
        //  if encoding was not specified,
        //     add xsl:output encoding=US-ASCII to XSLT source
        //
        if (encodingName == null || encodingName.length() == 0) {
            Element transformElement = xsltdoc.getDocumentElement();
            Element outputElement = xsltdoc.
                    createElementNS(XSLT_NS, "output");
            outputElement.setAttributeNS(null, "encoding", "US-ASCII");
            transformElement.insertBefore(outputElement, transformElement.getFirstChild());
            encoding = Charset.forName("US-ASCII");
        } else {
            encoding = Charset.forName(encodingName);
        }

        DOMSource transformSource = new DOMSource(xsltdoc);
        
        templates = transformerFactory.newTemplates(transformSource);

    }
360894
private void transform(final String xml, final UIContext uic, final PrintWriter writer) {

		Transformer transformer = newTransformer();
		Source inputXml;
		try {
			inputXml = new StreamSource(new ByteArrayInputStream(xml.getBytes("utf-8")));
			StreamResult result = new StreamResult(writer);
			if (debugRequested) {
				transformer.setParameter("isDebug", 1);
			}
			transformer.transform(inputXml, result);
		} catch (UnsupportedEncodingException | TransformerException ex) {
			throw new SystemException("Could not transform xml", ex);
		}
	}
735382
@Override
	public List<Metric> transform(QueryContext context, List<Metric> metrics) {
		SystemAssert.requireArgument(metrics != null, "Cannot transform null metric/metrics");
		return computeDerivedValues(metrics, -1L);
	}
534962
public void setPresetTransformer(String transformerName){
        for(Transformer t : Transformer.values()){
            if(t.equals(transformerName)){
                setPresetTransformer(t);
                return;
            }
        }
    }