本文整理汇总了Java中javax.jcr.Binary类的典型用法代码示例。如果您正苦于以下问题:Java Binary类的具体用法?Java Binary怎么用?Java Binary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Binary类属于javax.jcr包,在下文中一共展示了Binary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readFile
import javax.jcr.Binary; //导入依赖的package包/类
@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();
}
示例2: loadResourceSecurityConfigs
import javax.jcr.Binary; //导入依赖的package包/类
@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;
}
示例3: get
import javax.jcr.Binary; //导入依赖的package包/类
private byte[] get(final String path) throws LoginException, RepositoryException, IOException {
byte[] ret = null;
Session session = null;
try {
session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
Binary b = session.getRootNode().getProperty(path).getBinary();
ret = IOUtils.toByteArray(b.getStream());
b.dispose();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null) {
session.logout();
}
}
return ret;
}
示例4: mapSerializedFieldToProperty
import javax.jcr.Binary; //导入依赖的package包/类
private void mapSerializedFieldToProperty(Field field, Object obj, Node node, int depth, NodeFilter nodeFilter) throws IllegalAccessException, RepositoryException, IOException {
String propertyName = getSerializedPropertyName(field);
Object fieldValue = getObject(field, obj);
// make sure that this property is supposed to be updated
if (nodeFilter == null || nodeFilter.isIncluded(NodeFilter.PROPERTY_PREFIX + field.getName(), node, depth)) {
if (fieldValue != null) {
// serialize and store
//node.setProperty(propertyName, new ByteArrayInputStream(serialize(fieldValue)));
ValueFactory valueFactory = node.getSession().getValueFactory();
Binary binary = valueFactory.createBinary(new ByteArrayInputStream(serialize(fieldValue)));
node.setProperty(propertyName, binary);
} else {
// remove the value
node.setProperty(propertyName, (Value) null);
}
}
}
示例5: mapSerializedFieldToProperty
import javax.jcr.Binary; //导入依赖的package包/类
private void mapSerializedFieldToProperty(Field field, Object obj, Node node, int depth, NodeFilter nodeFilter) throws IllegalAccessException,
RepositoryException, IOException
{
String propertyName = getSerializedPropertyName(field);
Object fieldValue = field.get(obj);
// make sure that this property is supposed to be updated
if (nodeFilter == null || nodeFilter.isIncluded(NodeFilter.PROPERTY_PREFIX + field.getName(), node, depth))
{
if (fieldValue != null)
{
// serialize and store
// node.setProperty(propertyName, new ByteArrayInputStream(serialize(fieldValue)));
ValueFactory valueFactory = node.getSession().getValueFactory();
Binary binary = valueFactory.createBinary(new ByteArrayInputStream(serialize(fieldValue)));
node.setProperty(propertyName, binary);
}
else
{
// remove the value
node.setProperty(propertyName, (Value) null);
}
}
}
示例6: populateItem
import javax.jcr.Binary; //导入依赖的package包/类
private void populateItem(InputStream inputStream, Node qrCodeNode, final String fileName) throws RepositoryException {
if (inputStream != null) {
try {
Property data = getPropertyOrNull(qrCodeNode, JCR_DATA);
Binary binary = ValueFactoryImpl.getInstance().createBinary(inputStream);
if (data == null) {
qrCodeNode.setProperty(JCR_DATA, binary);
} else {
data.setValue(binary);
}
setProperty(qrCodeNode, FileProperties.PROPERTY_FILENAME, fileName);
setProperty(qrCodeNode, FileProperties.PROPERTY_CONTENTTYPE, MIME_TYPE);
Calendar calValue = new GregorianCalendar(TimeZone.getDefault());
setProperty(qrCodeNode, FileProperties.PROPERTY_LASTMODIFIED, calValue);
} catch (RepositoryException re) {
LOGGER.error("Could not get Binary. Upload will not be performed", re);
}
}
}
示例7: doGet
import javax.jcr.Binary; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
throws IOException, ServletException {
//TODO: put all of the logic in a context processor (need to fix templating support filter bug first)
String transformName = BLANK;
if (PathInfoUtil.getSuffixSegments(request).length == 2) {
String firstSuffixSegment = PathInfoUtil.getFirstSuffixSegment(request);
if (this.namedImageTransformers.keySet().contains(firstSuffixSegment)) {
transformName = firstSuffixSegment;
}
}
//Adds the asset binary to the inputStream
try {
Resource assetResource = getAssetResource(request);
if (DamUtil.isAsset(assetResource)) {
Binary binary;
String mimeType = BLANK;
Asset asset = DamUtil.resolveToAsset(assetResource);
Resource original = asset.getOriginal();
Node assetNode = original.adaptTo(Node.class);
if (assetNode.hasNode(JCR_CONTENT)) {
Node assetInfo = assetNode.getNode(JCR_CONTENT);
if (assetInfo.hasProperty(JCR_MIMETYPE)) {
mimeType = assetInfo.getProperty(JCR_MIMETYPE).getString();
}
if (StringUtils.isNotBlank(mimeType)) {
response.setContentType(mimeType);
}
binary = assetInfo.getProperty(JCR_DATA).getBinary();
InputStream inputStream = binary.getStream();
OutputStream outputStream = response.getOutputStream();
boolean shouldTransform = StringUtils.isNotBlank(transformName);
if (shouldTransform && ImageUtils.isImage(assetResource)) {
double quality = 1;
double maxGifQuality = 255;
// Transform the image
final Layer layer = new Layer(inputStream, new Dimension(maxWidth, maxHeight));
Layer newLayer = null;
try {
final NamedImageTransformer namedImageTransformer = this.namedImageTransformers.get(transformName);
newLayer = namedImageTransformer.transform(layer);
if (StringUtils.isBlank(mimeType) || !ImageIO.getImageWritersByMIMEType(mimeType).hasNext()) {
mimeType = getImageMimeType(layer, asset.getName());
response.setContentType(mimeType);
}
// For GIF images the colors will be reduced according to the quality argument.
if (StringUtils.equals(mimeType, GIF_MIME_TYPE)) {
quality = quality * maxGifQuality;
}
newLayer.write(mimeType, quality, outputStream);
} finally {
if (layer != null) {
layer.dispose();
}
if (newLayer != null) {
newLayer.dispose();
}
}
} else {
ByteStreams.copy(inputStream, outputStream);
}
response.flushBuffer();
outputStream.close();
}
}
} catch (RepositoryException repoException) {
LOGGER.error("Repository Exception. ", repoException);
}
}
示例8: readVersionFile
import javax.jcr.Binary; //导入依赖的package包/类
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();
}
示例9: loadClientConfigs
import javax.jcr.Binary; //导入依赖的package包/类
@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;
}
示例10: createFileNode
import javax.jcr.Binary; //导入依赖的package包/类
private void createFileNode(String path, String content,User user,boolean isFile) throws Exception{
String createUser=user.getUsername();
repositoryInteceptor.createFile(path,content);
Node rootNode=getRootNode();
path = processPath(path);
try {
if (rootNode.hasNode(path)) {
throw new RuleException("File [" + path + "] already exist.");
}
Node fileNode = rootNode.addNode(path);
fileNode.addMixin("mix:versionable");
fileNode.addMixin("mix:lockable");
Binary fileBinary = new BinaryImpl(content.getBytes());
fileNode.setProperty(DATA, fileBinary);
if(isFile){
fileNode.setProperty(FILE, true);
}
fileNode.setProperty(CRATE_USER, createUser);
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
DateValue dateValue = new DateValue(calendar);
fileNode.setProperty(CRATE_DATE, dateValue);
session.save();
} catch (Exception ex) {
throw new RuleException(ex);
}
}
示例11: putFile
import javax.jcr.Binary; //导入依赖的package包/类
private Node putFile(
Node parent, String name, String mime,
InputStream data) throws RepositoryException {
Binary binary = parent.getSession().getValueFactory().createBinary(data);
try {
Node file = getOrAddNode(parent, name, NodeType.NT_FILE);
//oak:Resource is non referenceable hence less overhead
String nodeType = useOakResource ? "oak:Resource" : NodeType.NT_RESOURCE;
Node content = getOrAddNode(file, Node.JCR_CONTENT, nodeType);
content.setProperty(Property.JCR_MIMETYPE, mime);
String[] parameters = mime.split(";");
for (int i = 1; i < parameters.length; i++) {
int equals = parameters[i].indexOf('=');
if (equals != -1) {
String parameter = parameters[i].substring(0, equals);
if ("charset".equalsIgnoreCase(parameter.trim())) {
content.setProperty(
Property.JCR_ENCODING,
parameters[i].substring(equals + 1).trim());
}
}
}
content.setProperty(Property.JCR_LAST_MODIFIED, Calendar.getInstance());
content.setProperty(Property.JCR_DATA, binary);
return file;
} finally {
binary.dispose();
}
}
示例12: saveScript
import javax.jcr.Binary; //导入依赖的package包/类
private Script saveScript(ResourceResolver resolver, final String fileName, final InputStream input,
final boolean overwrite) {
Script result = null;
final Session session = resolver.adaptTo(Session.class);
final ValueFactory valueFactory;
try {
valueFactory = session.getValueFactory();
final Binary binary = valueFactory.createBinary(input);
final Node saveNode = session.getNode(getSavePath());
final Node fileNode, contentNode;
if (overwrite && saveNode.hasNode(fileName)) {
fileNode = saveNode.getNode(fileName);
contentNode = fileNode.getNode(JcrConstants.JCR_CONTENT);
} else {
fileNode = saveNode.addNode(generateFileName(fileName, saveNode), JcrConstants.NT_FILE);
contentNode = fileNode.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
}
contentNode.setProperty(JcrConstants.JCR_DATA, binary);
contentNode.setProperty(JcrConstants.JCR_ENCODING, SCRIPT_ENCODING.name());
JcrUtils.setLastModified(contentNode, Calendar.getInstance());
session.save();
result = scriptFinder.find(fileNode.getPath(), resolver);
} catch (RepositoryException e) {
LOG.error(e.getMessage(), e);
}
return result;
}
示例13: selectPropertyType
import javax.jcr.Binary; //导入依赖的package包/类
private static int selectPropertyType(Object value) {
return (value instanceof String) ? PropertyType.STRING :
(value instanceof Long) ? PropertyType.LONG :
(value instanceof Double) ? PropertyType.DOUBLE :
(value instanceof BigDecimal) ? PropertyType.DECIMAL :
(value instanceof Calendar) ? PropertyType.DATE :
(value instanceof Boolean) ? PropertyType.BOOLEAN :
(value instanceof Binary) ? PropertyType.BINARY :
PropertyType.UNDEFINED;
}
示例14: createBinary
import javax.jcr.Binary; //导入依赖的package包/类
@Override
public Binary createBinary(InputStream stream) throws RepositoryException {
Binary b = new BinaryImpl(stream);
try {
stream.close();
}
catch (IOException ioe) { /* ignore */ }
return b;
}
示例15: createBinary
import javax.jcr.Binary; //导入依赖的package包/类
@Override
public Binary createBinary(InputStream stream) throws RepositoryException {
try {
return new BinaryImpl(createBinaryValue(stream));
} catch (IOException e) {
throw new RepositoryException(e);
}
}