Replaces xformManifest urls with URLs according to an internal Enketo Express url format

@param  {[type]} xmlDoc   libxmljs object
@param  {*} manifest      json representation of XForm manifest
@return {Promise}         libxmljs object
359948
function _replaceMediaSources( xmlDoc, mediaMap ) {
    if ( !mediaMap ) {
        return xmlDoc;
    }

    // iterate through each element with a src attribute
    xmlDoc.find( '//*[@src] | //a[@href]' ).forEach( mediaEl => {
        const attribute = ( mediaEl.name().toLowerCase() === 'a' ) ? 'href' : 'src';
        const src = mediaEl.attr( attribute ).value();
        const matches = src ? src.match( /jr:\/\/[\w-]+\/(.+)/ ) : null;
        const filename = matches && matches.length ? matches[ 1 ] : null;
        const replacement = filename ? mediaMap[ filename ] : null;
        if ( replacement ) {
            mediaEl.attr( attribute, replacement );
        }
    } );

    // add form logo <img> element if applicable
    const formLogo = mediaMap[ 'form_logo.png' ];
    const formLogoEl = xmlDoc.get( '//*[@class="form-logo"]' );
    if ( formLogo && formLogoEl ) {
        formLogoEl
            .node( 'img' )
            .attr( 'src', formLogo )
            .attr( 'alt', 'form logo' );
    }

    return xmlDoc;
}
1271393
function updateManifestWithPublisher (config, myBuildTargets) {
    if (!config.publisherId) return;

    var manifestFiles = myBuildTargets.map(function (proj) {
        return projFilesToManifests[proj];
    });
    manifestFiles.forEach(function (file) {
        var manifest = AppxManifest.get(path.join(ROOT, file));
        manifest.getIdentity().setPublisher(config.publisherId);
        manifest.write();
    });
}
845195
def UpdateManifestResourcesFromXML(dstpath, xmlstr, names=None, 
                                   languages=None):
    
    logger.info("Updating manifest in %s", dstpath)
    if dstpath.lower().endswith(".exe"):
        name = 1 
    else:
        name = 2
    winresource.UpdateResources(dstpath, xmlstr, RT_MANIFEST, names or [name], 
                             languages or [0, "*"])
436142
private static void completeManifest(Manifest manifest, URL url) {

    String path = url.getPath();
    int start = 0;
    int end = path.length();
    if (path.endsWith(JAR_SUFFIX)) {
      // 4 for ".jar"
      end = end - JAR_SUFFIX.length() + 4;
      start = path.lastIndexOf('/', end) + 1;
    }
    String source = path.substring(start, end);
    manifest.getMainAttributes().put(MANIFEST_SOURCE, source);
  }
345967
def build_urls(self: NodeVisitor, node: inheritance_diagram) -> Mapping[str, str]:
    
    current_filename = self.builder.current_docname + self.builder.out_suffix
    urls = {}
    for child in node:
        # Another document
        if child.get("refuri") is not None:
            uri = child.get("refuri")
            package_path = child["reftitle"]
            if uri.startswith("http"):
                _, _, package_path = uri.partition("#")
            else:
                uri = (
                    pathlib.Path("..")
                    / pathlib.Path(current_filename).parent
                    / pathlib.Path(uri)
                )
                uri = str(uri).replace(os.path.sep, "/")
            urls[package_path] = uri
        # Same document
        elif child.get("refid") is not None:
            urls[child["reftitle"]] = (
                "../" + current_filename + "#" + child.get("refid")
            )
    return urls
838225
public static String getManifestXml(byte[] apkData, Locale locale) throws IOException {
        try (ByteArrayApkFile apkFile = new ByteArrayApkFile(apkData)) {
            apkFile.setPreferredLocale(locale);
            return apkFile.getManifestXml();
        }
    }
156491
function formatURL(xStartHost, xurl, url, replaceHash, resultHost) {
    if (typeof url !== 'string') {
        return 'badurl:' + url;
    };

    if (typeof xurl !== 'string') {
        xurl = xurl.href;
    };

    if (!/[\/\.\:]/.test(url)) {
        if (replaceHash && replaceHash !== true) {
            var x = replaceHash[url];
            if (x !== und) {
                return !resultHost ? x.value : x;
            };
        };
    };

    var url = normalizeURL(url);

    if (/^\/([^\/]|$)/.test(url)) {
        if (xStartHost && xurl.indexOf(xStartHost) === 0) {
            url = xStartHost + url;
        };
    };

    url = aliasURL(URL.resolve(xurl, url), false);

    if (replaceHash && replaceHash !== true) {
        var und;
        var x = replaceHash[url];
        if (x !== und) {
            return !resultHost ? x.value : x;
        };

        var s = url.replace(/[^\/]+$/, '');
        for(; /^(file|https?):\/\/./.test(s);  s = s.replace(/[^\/]+\/+$/, '') ) {
            var x = replaceHash[s];
            if (x !== und) {
                if (x.type === 'path') {
                    var value = x.value + url.substring(s.length);
                    return !resultHost ? value : {
                        value: value,
                        host: x.host,
                        type: x.type
                    };

                } else {
                    return !resultHost ? x.value : x;
                };
            };
        };
    };

    return !resultHost ? url : {
        type: 'path',
        host: xStartHost,
        value: url
    };
}
778831
function generateManifestFile() {
    if (Object.keys(deps).length === 0) {
      this.emit('end');
    } else if (!entryPoint) {
      this.emit('error',
          new gutil.PluginError(PLUGIN_NAME, 'Closure entry point is not specified'));    
    } else {
      var manifest = generateManifest(entryPoint);

      var manifestFile = new gutil.File({
        contents: new Buffer(manifest.join('\n')),
        path: fileName
      });

      this.emit('data', manifestFile);
      this.emit('end');
    }
  }
75885
function (ui, opts) {
    
		log("xxmlmirror.init");

		var $el = $(ui);
		var state = ($("div.xmlmirrorstate:first", $el).html() || "").trim();
		opts = $.extend({ defaultScript: state }, opts);

		$el.html(template.trim());

		var editor = null;
		(function iframeImplementation() {
			var iframe = $("iframe", ui);

			editor = ns.widgets.xmleditorInitIframe(iframe);

		})();

		if (opts.defaultScript) {
			editor.set(ns.modules.string.htmlDecode(opts.defaultScript));
		}

		var me = {};
		me.refresh = function () { editor.refresh(); };
		me.getXml = function () {
			var code = editor.get();
			return code;
		};
		me.setXml = function (xml) {
			editor.set(xml);
		};

		return me;
	}
1301539
function _parseWithXml2js(xmlContent) {
  return new Promise(function(resolve, reject) {
    // parse the pom, erasing all
    xml2js.parseString(xmlContent, XML2JS_OPTS, function(err, pomObject) {
      if (err) {
        // Reject with the error
        reject(err);
      }

      // Replace the arrays with single elements with strings
      removeSingleArrays(pomObject);

      // Response to the call
      resolve({
        pomXml: xmlContent, // Only add the pomXml when loaded from the file-system.
        pomObject: pomObject // Always add the object
      });
    });
  });
}
263959
function transform( survey ) {
    let xformDoc;
    const xsltParams = survey.includeRelevantMsg ? {
        'include-relevant-msg': 1
    } : {};

    return _parseXml( survey.xform )
        .then( doc => {
            if ( typeof survey.preprocess === 'function' ) {
                doc = survey.preprocess.call( libxmljs, doc );
            }
            return doc;
        } )
        .then( doc => {
            xformDoc = doc;

            return _transform( sheets.xslForm, xformDoc, xsltParams );
        } )
        .then( htmlDoc => {
            htmlDoc = _replaceTheme( htmlDoc, survey.theme );
            htmlDoc = _replaceMediaSources( htmlDoc, survey.media );
            htmlDoc = _replaceLanguageTags( htmlDoc, survey );
            if ( survey.markdown !== false ) {
                survey.form = _renderMarkdown( htmlDoc );
            } else {
                survey.form = _docToString( htmlDoc );
            }

            return _transform( sheets.xslModel, xformDoc );
        } )
        .then( xmlDoc => {
            xmlDoc = _replaceMediaSources( xmlDoc, survey.media );
            xmlDoc = _addInstanceIdNodeIfMissing( xmlDoc );
            survey.model = xmlDoc.root().get( '*' ).toString( false );
            survey.transformerVersion = pkg.version;

            delete survey.xform;
            delete survey.media;
            delete survey.preprocess;
            delete survey.markdown;
            delete survey.includeRelevantMsg;
            return survey;
        } );
}
1081866
function XUnitExporter() {
    "use strict";
    this.results = undefined;
    this._xml = utils.node('testsuites');
    this._xml.toString = function toString() {
        return '<?xml version="1.0" encoding="UTF-8"?>' + this.outerHTML; // ouch
    };
}
787355
private static Document loadXML(InputSource source, boolean useNamespace) {
		try {
			org.w3c.dom.Document doc = getDocumentBuilder(null, useNamespace).parse(source);
			return new DocumentImpl(doc);
		} catch (Exception e) {
			throw new DomException(e);
		} finally {
			close(source);
		}
	}
1123812
function(src) {
		var doc = document;
		this.contentLocation = new gui.URL(doc, src);
		this.xguest = (function(secured) {
			if (secured) {
				return "*";
			} else if (gui.URL.external(src, doc)) {
				var url = new gui.URL(doc, src);
				return url.protocol + "//" + url.host;
			}
			return null;
		}(this._sandboxed()));
	}
213885
function getLayersFromManifest(manifest) {
    var i = 0;
    if (manifest.schemaVersion === 1) {
        return manifest.fsLayers.map(function (layer) {
            i += 1;
            return {
                i: i,
                digest: layer.blobSum
            };
        });
    }
    assert.equal(manifest.schemaVersion, 2, 'manifest.schemaVersion === 2');
    return manifest.layers.map(function (layer) {
        i += 1;
        return {
            i: i,
            digest: layer.digest
        };
    });
}
1027188
function constructPaths(xmlElement) {
  if (xmlElement['path'] == null) {
    return ['*'];
  }

  var paths = [];
  xmlElement.path.some(function(pathElement) {
    var url = pathElement['$']['url'];

    // Ignore explicit paths if '*' is defined
    if (url === '*') {
      paths = ['*'];
      return true;
    }

    paths.push(url);
  });

  return paths;
}
316987
function (xrefs, server){
    this._is_a = 'amigo2.linker';

    // TODO:BUG: With the new dispatcher, relative URLs no longer work.

    this._xrefs = xrefs;

    // Easy app base.
    this.app_base = server.app_base;
    // Internal term matcher.
    this.term_regexp = null;
    var internal_regexp_str = server.term_regexp;
    if( internal_regexp_str ){
	this.term_regexp = new RegExp(internal_regexp_str);
    }

    // Categories for different special cases (internal links).
    this.ont_category = {
	'term': true,
	'ontology_class': true,
	'annotation_class': true,
	'annotation_class_closure': true,
	'annotation_class_list': true,
	// Noctua model stuff.
	'function_class': true,
	'function_class_closure': true,
	'process_class': true,
	'process_class_closure': true,
	'location_list': true,
	'location_list_closure': true
    };
    this.bio_category = {
        'gp': true,
	'gene_product': true,
	'bioentity': true
    };
    this.ref_category = {
	'reference': true
    };
    this.model_category = {
        'model': true
    };
    this.search_category = { // not including the trivial medial_search below
        'search': true,
	'live_search': true
    };
    this.search_modifier = {
	// Possibly "dynamic".
	'gene_product': '/bioentity',
	'bioentity': '/bioentity',
	'ontology': '/ontology',
	'reference': '/reference',
	'annotation': '/annotation',
	'model': '/model',
	'family': '/family',
	'lego_unit': '/lego_unit',
	'general': '/general'
    };
    this.other_interlinks = {
	'medial_search': '/amigo/medial_search',
	'landing': '/amigo/landing',
	'tools': '/amigo/software_list',
	'schema_details': '/amigo/schema_details',
	'load_details': '/amigo/load_details',
	'browse': '/amigo/browse',
	'goose': '/goose',
	'grebe': '/grebe',
	'gannet': '/gannet',
	'repl': '/repl'	
    };
}