Java Code Examples for javax.jcr.Binary#getStream()

The following examples show how to use javax.jcr.Binary#getStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseRepositoryService.java    From urule with Apache License 2.0 8 votes vote down vote up
@Override
public InputStream readFile(String path,String version) throws Exception{
	if(StringUtils.isNotBlank(version)){
		repositoryInteceptor.readFile(path+":"+version);
		return readVersionFile(path, version);
	}
	repositoryInteceptor.readFile(path);
	Node rootNode=getRootNode();
	int colonPos = path.lastIndexOf(":");
	if (colonPos > -1) {
		version = path.substring(colonPos + 1, path.length());
		path = path.substring(0, colonPos);
		return readFile(path, version);
	}
	path = processPath(path);
	if (!rootNode.hasNode(path)) {
		throw new RuleException("File [" + path + "] not exist.");
	}
	Node fileNode = rootNode.getNode(path);
	Property property = fileNode.getProperty(DATA);
	Binary fileBinary = property.getBinary();
	return fileBinary.getStream();
}
 
Example 2
Source File: TreeSync.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
private void writeFile(SyncResult res, Entry e) throws IOException, RepositoryException {
    String action = e.file.exists() ? "U" : "A";
    Binary bin = null;
    InputStream in = null;
    OutputStream out = null;
    try {
        bin = e.node.getProperty("jcr:content/jcr:data").getBinary();
        in = bin.getStream();
        out = FileUtils.openOutputStream(e.file);
        IOUtils.copy(in, out);
        if (preserveFileDate) {
            Calendar lastModified = e.node.getProperty("jcr:content/jcr:lastModified").getDate();
            e.file.setLastModified(lastModified.getTimeInMillis());
        }
        syncLog.log("%s file://%s", action, e.file.getAbsolutePath());
        res.addEntry(e.getJcrPath(), e.getFsPath(), SyncResult.Operation.UPDATE_FS);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
        if (bin != null) {
            bin.dispose();
        }
    }
}
 
Example 3
Source File: BaseRepositoryService.java    From urule with Apache License 2.0 5 votes vote down vote up
private InputStream readVersionFile(String path, String version) throws Exception{
	path = processPath(path);
	Node rootNode=getRootNode();
	if (!rootNode.hasNode(path)) {
		throw new RuleException("File [" + path + "] not exist.");
	}
	Node fileNode = rootNode.getNode(path);
	VersionHistory versionHistory = versionManager.getVersionHistory(fileNode.getPath());
	Version v = versionHistory.getVersion(version);
	Node fnode = v.getFrozenNode();
	Property property = fnode.getProperty(DATA);
	Binary fileBinary = property.getBinary();
	return fileBinary.getStream();
}
 
Example 4
Source File: RepositoryServiceImpl.java    From urule with Apache License 2.0 5 votes vote down vote up
@Override
public List<UserPermission> loadResourceSecurityConfigs(String companyId) throws Exception{
	List<UserPermission> configs=new ArrayList<UserPermission>();
	String filePath=RESOURCE_SECURITY_CONFIG_FILE+(companyId == null ? "" : companyId);
	Node rootNode=getRootNode();
	Node fileNode = rootNode.getNode(filePath);
	Property property = fileNode.getProperty(DATA);
	Binary fileBinary = property.getBinary();
	InputStream inputStream = fileBinary.getStream();
	String content = IOUtils.toString(inputStream, "utf-8");
	inputStream.close();
	Document document = DocumentHelper.parseText(content);
	Element rootElement = document.getRootElement();
	for (Object obj : rootElement.elements()) {
		if (!(obj instanceof Element)) {
			continue;
		}
		Element element = (Element) obj;
		if (!element.getName().equals("user-permission")) {
			continue;
		}
		UserPermission userResource=new UserPermission();
		userResource.setUsername(element.attributeValue("username"));
		userResource.setProjectConfigs(parseProjectConfigs(element));
		configs.add(userResource);
	}
	return configs;
}
 
Example 5
Source File: RepositoryServiceImpl.java    From urule with Apache License 2.0 5 votes vote down vote up
@Override
public List<ClientConfig> loadClientConfigs(String project) throws Exception{
	if(!permissionService.isAdmin()){
		throw new NoPermissionException();
	}
	List<ClientConfig> clients=new ArrayList<ClientConfig>();
	Node rootNode=getRootNode();
	String filePath = processPath(project) + "/" + CLIENT_CONFIG_FILE;
	Node fileNode = rootNode.getNode(filePath);
	Property property = fileNode.getProperty(DATA);
	Binary fileBinary = property.getBinary();
	InputStream inputStream = fileBinary.getStream();
	String content = IOUtils.toString(inputStream, "utf-8");
	inputStream.close();
	Document document = DocumentHelper.parseText(content);
	Element rootElement = document.getRootElement();
	for (Object obj : rootElement.elements()) {
		if (!(obj instanceof Element)) {
			continue;
		}
		Element element = (Element) obj;
		if (!element.getName().equals("item")) {
			continue;
		}
		ClientConfig client = new ClientConfig();
		client.setName(element.attributeValue("name"));
		client.setClient(element.attributeValue("client"));
		client.setProject(project);
		clients.add(client);
	}
	return clients;
}
 
Example 6
Source File: BaseRepositoryService.java    From urule with Apache License 2.0 4 votes vote down vote up
@Override
public List<ResourcePackage> loadProjectResourcePackages(String project) throws Exception {
	Node rootNode=getRootNode();
	String filePath = processPath(project) + "/" + RES_PACKGE_FILE;
	SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	Node fileNode = rootNode.getNode(filePath);
	Property property = fileNode.getProperty(DATA);
	Binary fileBinary = property.getBinary();
	InputStream inputStream = fileBinary.getStream();
	String content = IOUtils.toString(inputStream, "utf-8");
	inputStream.close();
	Document document = DocumentHelper.parseText(content);
	Element rootElement = document.getRootElement();
	List<ResourcePackage> packages = new ArrayList<ResourcePackage>();
	for (Object obj : rootElement.elements()) {
		if (!(obj instanceof Element)) {
			continue;
		}
		Element element = (Element) obj;
		if (!element.getName().equals("res-package")) {
			continue;
		}
		ResourcePackage p = new ResourcePackage();
		String dateStr = element.attributeValue("create_date");
		if (dateStr != null) {
			p.setCreateDate(sd.parse(dateStr));
		}
		p.setId(element.attributeValue("id"));
		p.setName(element.attributeValue("name"));
		p.setProject(project);
		List<ResourceItem> items = new ArrayList<ResourceItem>();
		for (Object o : element.elements()) {
			if (!(o instanceof Element)) {
				continue;
			}
			Element ele = (Element) o;
			if (!ele.getName().equals("res-package-item")) {
				continue;
			}
			ResourceItem item = new ResourceItem();
			item.setName(ele.attributeValue("name"));
			item.setPackageId(p.getId());
			item.setPath(ele.attributeValue("path"));
			item.setVersion(ele.attributeValue("version"));
			items.add(item);
		}
		p.setResourceItems(items);
		packages.add(p);
	}
	return packages;
}