if (mime != null)
if (mime != null) {
	public Sequence evalWithCollection(Collection collection, Sequence args[],		Sequence contextSequence)		throws XPathException {		String docName = args[1].getLength() == 0 ? null : args[1].getStringValue();		if(docName != null && docName.length() == 0)			docName = null;		        String mimeType = "application/octet-stream";		boolean binary = false;		if(getSignature().getArgumentCount() == 4) {			mimeType = args[3].getStringValue();			binary = !("text/xml".equals(mimeType) || "application/xml".equals(mimeType));		} else if (docName != null){		    MimeType mime = MimeTable.getInstance().getContentTypeFor(docName);            if (mime != null)                mimeType = mime.getName();        }				Item item =			args[2].itemAt(0);		Resource resource;		try {			if(Type.subTypeOf(item.getType(), Type.JAVA_OBJECT)) {				Object obj = ((JavaObjectValue)item).getObject();				if(!(obj instanceof File))					throw new XPathException(getASTNode(), "Passed java object should be a File");				resource = loadFromFile(collection, (File)obj, docName, binary);			} else if(Type.subTypeOf(item.getType(), Type.ANY_URI)) {				try {					URI uri = new URI(item.getStringValue());					resource = loadFromURI(collection, uri, docName, binary);				} catch (URISyntaxException e) {					throw new XPathException(getASTNode(), "Invalid URI: " + item.getStringValue(), e);				}			} else {				if(binary) {					resource = collection.createResource(docName, "BinaryResource");                    ((EXistResource)resource).setMimeType(mimeType);                } else					resource = collection.createResource(docName, "XMLResource");				if(Type.subTypeOf(item.getType(), Type.STRING)) {					resource.setContent(item.getStringValue());				} else if(Type.subTypeOf(item.getType(), Type.NODE)) {					if(binary) {						StringWriter writer = new StringWriter();						SAXSerializer serializer = new SAXSerializer();						serializer.setOutput(writer, null);						item.toSAX(context.getBroker(), serializer);						resource.setContent(writer.toString());					} else {						ContentHandler handler = ((XMLResource)resource).setContentAsSAX();						handler.startDocument();						item.toSAX(context.getBroker(), handler);						handler.endDocument();					}				} else					throw new XPathException("Data should be either a node or a string");				collection.storeResource(resource);				context.getRootExpression().resetState();			}		} catch (XMLDBException e) {			throw new XPathException(				"XMLDB reported an exception while storing document",				e);		} catch (SAXException e) {			throw new XPathException(				"SAX reported an exception while storing document",				e);		}		if (resource == null)			return Sequence.EMPTY_SEQUENCE;		else			try {				return new StringValue(collection.getName() + '/' + resource.getId());			} catch (XMLDBException e) {				throw new XPathException("XMLDB reported an exception while retrieving the " +						"stored document", e);			}	}