本文整理了Java中org.wso2.carbon.registry.core.Resource.setMediaType
方法的一些代码示例,展示了Resource.setMediaType
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resource.setMediaType
方法的具体详情如下:
包路径:org.wso2.carbon.registry.core.Resource
类名称:Resource
方法名:setMediaType
暂无
代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.mashup.javascript.hostobjects.registry
public void jsSet_mediaType(Object mediaType) throws CarbonException {
if (mediaType instanceof String) {
this.resource.setMediaType((String) mediaType);
} else {
throw new CarbonException("Invalid property type for mediaType");
}
}
代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.resource
public static void updateMediaType(UserRegistry userRegistry, String path, String mediaType)
throws RegistryException {
try {
Resource currentResource = userRegistry.get(path);
currentResource.setMediaType(mediaType);
userRegistry.put(path, currentResource);
} catch (RegistryException e) {
throw new RegistryException("Failed to update media type of the resource : "+path);
}
}
}
代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl
private static void loadCustomAppPropertyDefinitionsForAppType(String appType, UserRegistry registry) throws RegistryException, IOException {
if(!registry.resourceExists(getCustomPropertyDefinitionsResourcePath(appType))){
String customPropertyDefinitions = CarbonUtils.getCarbonHome() + File.separator +
AppMConstants.RESOURCE_FOLDER_LOCATION + File.separator +
AppMConstants.CUSTOM_PROPERTY_DEFINITIONS_PATH + File.separator +
appType + ".json";
File customPropertyDefinitionsFile = new File(customPropertyDefinitions);
byte[] data;
if (customPropertyDefinitionsFile.exists()) {
FileInputStream fileInputStream = new FileInputStream(customPropertyDefinitionsFile);
data = IOUtils.toByteArray(fileInputStream);
Resource resource = registry.newResource();
resource.setMediaType(AppMConstants.APPLICATION_JSON_MEDIA_TYPE);
resource.setContent(data);
String customPropertyDefinitionsRegistryPath = getCustomPropertyDefinitionsResourcePath(appType);
registry.put(customPropertyDefinitionsRegistryPath, resource);
log.debug(String.format("Added custom property mapping ('%s') for '%s'", customPropertyDefinitionsRegistryPath, appType));
}else{
log.warn(String.format("Can't find custom property definitions file ('%s') for '%s'", customPropertyDefinitionsFile, AppMConstants.WEBAPP_ASSET_TYPE));
}
}
}
代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl
resource.setMediaType(AppMConstants.APPLICATION_JSON_MEDIA_TYPE);
resource.setContent(data);
代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.indexing
private void defineQueries(String queryPath, String queryContent) throws RegistryException {
UserRegistry registry =
(UserRegistry) Utils.getRegistry();
Resource q1 = registry.newResource();
q1.setContent(queryContent);
q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
q1.addProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME,
RegistryConstants.RESOURCES_RESULT_TYPE);
registry.put(queryPath, q1);
}
代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl
Resource resource = govRegistry.newResource();
resource.setContent(data);
resource.setMediaType(AppMConstants.WORKFLOW_MEDIA_TYPE);
govRegistry.put(AppMConstants.WORKFLOW_EXECUTOR_LOCATION, resource);
代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.extensions
resource.setProperty("version", version);
resource.setMediaType(this.mediaType);
InputStream inputStream;
try {
代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.extensions
private void addPolicyImportys(RequestContext context, String version) throws RegistryException {
/* storing policyReferences in to Registry if available in the WSDL */
for (WSDLInfo wsdlInfo : wsdls.values()) {
if(wsdlInfo.isExistPolicyReferences()){
Iterator iter = wsdlInfo.getPolicyDependencies().iterator();
while(iter.hasNext()){
String policyURL = (String)iter.next();
boolean lockAlreadyAcquired = !CommonUtil.isUpdateLockAvailable();
CommonUtil.releaseUpdateLock();
try{
Resource policyResource = registry.newResource();
policyResource.setMediaType("application/policy+xml");
String path = policyURL.substring(policyURL.lastIndexOf(RegistryConstants.PATH_SEPARATOR) + 1);
if(policyURL.lastIndexOf(RegistryConstants.PATH_SEPARATOR) > 0){
policyResource.setProperty("version", version);
policyResource.setProperties(copyProperties(context));
String policyPath = registry.importResource(path ,policyURL,policyResource);
registry.addAssociation(policyPath, wsdlInfo.getProposedRegistryURL(), CommonConstants.USED_BY);
registry.addAssociation(wsdlInfo.getProposedRegistryURL(), policyPath, CommonConstants.DEPENDS);
}
}finally {
if (lockAlreadyAcquired) {
CommonUtil.acquireUpdateLock();
}
}
}
}
}
}
代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl
public String addIcon(String resourcePath, Icon icon) throws AppManagementException {
try {
Resource thumb = registry.newResource();
thumb.setContentStream(icon.getContent());
thumb.setMediaType(icon.getContentType());
registry.put(resourcePath, thumb);
if(tenantDomain.equalsIgnoreCase(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)){
return RegistryConstants.PATH_SEPARATOR + "registry"
+ RegistryConstants.PATH_SEPARATOR + "resource"
+ RegistryConstants.PATH_SEPARATOR + "_system"
+ RegistryConstants.PATH_SEPARATOR + "governance"
+ resourcePath;
}
else{
return "/t/"+tenantDomain+ RegistryConstants.PATH_SEPARATOR + "registry"
+ RegistryConstants.PATH_SEPARATOR + "resource"
+ RegistryConstants.PATH_SEPARATOR + "_system"
+ RegistryConstants.PATH_SEPARATOR + "governance"
+ resourcePath;
}
} catch (RegistryException e) {
handleException("Error while adding the icon image to the registry", e);
}
return null;
}
代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl
public String addResourceFile(String resourcePath, FileContent resourceFile) throws AppManagementException {
try {
Resource thumb = registry.newResource();
thumb.setContentStream(resourceFile.getContent());
thumb.setMediaType(resourceFile.getContentType());
registry.put(resourcePath, thumb);
if(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equalsIgnoreCase(tenantDomain)){
return RegistryConstants.PATH_SEPARATOR + "registry"
+ RegistryConstants.PATH_SEPARATOR + "resource"
+ RegistryConstants.PATH_SEPARATOR + "_system"
+ RegistryConstants.PATH_SEPARATOR + "governance"
+ resourcePath;
}
else{
return "/t/"+tenantDomain+ RegistryConstants.PATH_SEPARATOR + "registry"
+ RegistryConstants.PATH_SEPARATOR + "resource"
+ RegistryConstants.PATH_SEPARATOR + "_system"
+ RegistryConstants.PATH_SEPARATOR + "governance"
+ resourcePath;
}
} catch (RegistryException e) {
handleException("Error while adding the resource to the registry", e);
}
return null;
}
代码示例来源:origin: org.wso2.carbon.analytics/org.wso2.carbon.analytics.dashboard
public static void createRegistryResource(String url, Object content) throws RegistryException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
Registry registry = ServiceHolder.getRegistryService().getConfigSystemRegistry(tenantId);
Resource resource = registry.newResource();
resource.setContent(content);
resource.setMediaType("application/json");
registry.put(url, resource);
}
代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.resource
public static void updateTextContent(String path, String contentText, Registry registry)
throws Exception {
try {
Resource resource = registry.get(path);
String mediaType = resource.getMediaType();
if (resource.getProperty(RegistryConstants.REGISTRY_LINK) != null &&
(CommonConstants.WSDL_MEDIA_TYPE.equals(mediaType) ||
CommonConstants.SCHEMA_MEDIA_TYPE.equals(mediaType))) {
String description = resource.getDescription();
Properties properties = (Properties) resource.getProperties().clone();
resource = registry.newResource();
resource.setMediaType(mediaType);
resource.setDescription(description);
resource.setProperties(properties);
}
resource.setContent(RegistryUtils.encodeString(contentText));
registry.put(path, resource);
resource.discard();
} catch (RegistryException e) {
String msg = "Could not update the content of the resource " +
path + ". Caused by: " + ((e.getCause() instanceof SQLException) ?
"" : e.getMessage());
log.error(msg, e);
throw new RegistryException(msg, e);
}
}
}
代码示例来源:origin: org.wso2.carbon.identity.governance/org.wso2.carbon.identity.recovery
/**
* Create registry resource from a challenge question model object.
*
* @param question
* @return
* @throws RegistryException
*/
private Resource createRegistryResource(ChallengeQuestion question) throws RegistryException, UnsupportedEncodingException {
byte[] questionText = question.getQuestion().getBytes("UTF-8");
String questionSetId = question.getQuestionSetId();
String questionId = question.getQuestionId();
String locale = question.getLocale();
Resource resource = new ResourceImpl();
resource.setContent(questionText);
resource.addProperty(IdentityRecoveryConstants.Questions.CHALLENGE_QUESTION_SET_ID, questionSetId);
resource.addProperty(IdentityRecoveryConstants.Questions.CHALLENGE_QUESTION_ID, questionId);
resource.addProperty(IdentityRecoveryConstants.Questions.CHALLENGE_QUESTION_LOCALE, locale); // added locale
resource.setMediaType(RegistryConstants.TAG_MEDIA_TYPE);
return resource;
}
代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.identity.entitlement
@Override
public void setPolicyData(String policyId, PolicyStoreDTO policyDataDTO) throws EntitlementException {
Registry registry = EntitlementServiceComponent.
getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId());
try {
String path = policyDataCollection + policyId;
Resource resource;
if (registry.resourceExists(path)) {
resource = registry.get(path);
} else {
resource = registry.newCollection();
}
resource.setMediaType(PDPConstants.REGISTRY_MEDIA_TYPE);
if (policyDataDTO.isSetActive()) {
resource.setProperty("active", Boolean.toString(policyDataDTO.isActive()));
}
if (policyDataDTO.isSetOrder()) {
int order = policyDataDTO.getPolicyOrder();
if (order > 0) {
resource.setProperty("order", Integer.toString(order));
}
}
registry.put(path, resource);
} catch (RegistryException e) {
log.error("Error while updating Policy data in policy store ", e);
throw new EntitlementException("Error while updating Policy data in policy store");
}
}
代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.resource
Resource resource = userRegistry.newResource();
resource.setProperty(CommonConstants.SOURCE_PROPERTY, CommonConstants.SOURCE_ADMIN_CONSOLE);
resource.setMediaType(mediaType);
resource.setDescription(description);
resource.setContent(RegistryUtils.decodeBytes(content));
代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.extensions
new RequestContext(registry, repository, versionRepository);
Resource local = requestContext.getRegistry().newResource();
local.setMediaType(xsdMediaType);
local.setProperty(CommonConstants.SOURCE_PROPERTY, CommonConstants.SOURCE_AUTO);
local.setProperties(props);
代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.governance.registry.extensions
public static void writeHistory(StatCollection currentCollection) {
try {
Registry systemRegistry;
try {
systemRegistry = currentCollection.getRegistry().getRegistryContext().getEmbeddedRegistryService()
.getGovernanceSystemRegistry(CurrentSession.getTenantId());
} catch (RegistryException ex) {
systemRegistry = currentCollection.getRegistry();
}
String resourcePath = currentCollection.getResourcePath();
Resource statResource;
String statResourcePath;
if (currentCollection.getOriginalPath().equals(resourcePath)) {
statResourcePath = getStatResourcePath(resourcePath);
}else{
statResourcePath = getStatResourcePath(currentCollection.getOriginalPath());
}
if (systemRegistry.resourceExists(statResourcePath)) {
statResource = systemRegistry.get(statResourcePath);
} else {
statResource = systemRegistry.newResource();
statResource.setMediaType("application/xml");
}
statResource.setContent(buildOMContent(statResource, currentCollection));
systemRegistry.put(statResourcePath, statResource);
} catch (Exception e) {
log.error("Failed to add lifecycle history", e);
}
}
代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl
Resource docContent = registry.newResource();
docContent.setContent(text);
docContent.setMediaType("text/plain");
registry.put(contentPath, docContent);
代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.governance.registry.extensions
private void addService(OMElement service, RequestContext context)throws RegistryException {
Resource resource = registry.newResource();
String tempNamespace = CommonUtil.derivePathFragmentFromNamespace(
CommonUtil.getServiceNamespace(service));
String path = getChrootedServiceLocation(registry, context.getRegistryContext()) + tempNamespace +
CommonUtil.getServiceName(service);
String artifactId = UUID.randomUUID().toString();
resource.setUUID(artifactId);
String content = service.toString();
resource.setContent(RegistryUtils.encodeString(content));
resource.setMediaType(RegistryConstants.SERVICE_MEDIA_TYPE);
// when saving the resource we are expecting to call the service media type handler, so
// we intentionally release the lock here.
boolean lockAlreadyAcquired = !CommonUtil.isUpdateLockAvailable();
CommonUtil.releaseUpdateLock();
try {
registry.put(path, resource);
} finally {
if (lockAlreadyAcquired) {
CommonUtil.acquireUpdateLock();
}
}
registry.addAssociation(path, RegistryUtils.getAbsolutePath(registry.getRegistryContext(),
CommonUtil.getDefinitionURL(service)), CommonConstants.DEPENDS);
registry.addAssociation(RegistryUtils.getAbsolutePath(registry.getRegistryContext(),
CommonUtil.getDefinitionURL(service)),path, CommonConstants.USED_BY);
}
代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl
/**
* Create WebApp Definition in JSON and save in the registry
*
* @param api WebApp
* @throws org.wso2.carbon.apimgt.api.APIManagementException
* if failed to generate the content and save
*/
private void createUpdateAPIDefinition(WebApp api) throws AppManagementException {
APIIdentifier identifier = api.getId();
try{
String jsonText = AppManagerUtil.createSwaggerJSONContent(api);
String resourcePath = AppManagerUtil.getAPIDefinitionFilePath(identifier.getApiName(), identifier.getVersion());
Resource resource = registry.newResource();
resource.setContent(jsonText);
resource.setMediaType("application/json");
registry.put(resourcePath, resource);
/*Set permissions to anonymous role */
AppManagerUtil.setResourcePermissions(api.getId().getProviderName(), null, null, resourcePath);
} catch (RegistryException e) {
handleException("Error while adding WebApp Definition for " + identifier.getApiName() + "-" + identifier.getVersion(), e);
} catch (AppManagementException e) {
handleException("Error while adding WebApp Definition for " + identifier.getApiName() + "-" + identifier.getVersion(), e);
}
}
内容来源于网络,如有侵权,请联系作者删除!