org.wso2.carbon.registry.core.Resource.setContent()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(16.3k)|赞(0)|评价(0)|浏览(84)

本文整理了Java中org.wso2.carbon.registry.core.Resource.setContent方法的一些代码示例,展示了Resource.setContent的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resource.setContent方法的具体详情如下:
包路径:org.wso2.carbon.registry.core.Resource
类名称:Resource
方法名:setContent

Resource.setContent介绍

暂无

代码示例

代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.mashup.javascript.hostobjects.registry

public void jsSet_content(Object content) throws CarbonException {
  if (content instanceof String) {
    try {
      this.resource.setContent((String) content);
    } catch (RegistryException e) {
      throw new CarbonException("Registry Exception while setting content property", e);
    }
  } else if (content instanceof XML) {
    try {
      this.resource.setContent(((XML)content).getAxiomFromXML());
    } catch (RegistryException e) {
      throw new CarbonException("Registry Exception while setting content property", e);
    }
  } else {
    throw new CarbonException("Invalid property type for content");
  }
}

代码示例来源: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.registry/org.wso2.carbon.registry.extensions

public void importResource(RequestContext requestContext) throws RegistryException {
  validateUpdateInProgress();
  try {
    URL sourceURL = new URL(requestContext.getSourceURL());
    InputStream inputStream = sourceURL.openStream();
    try {
      requestContext.getResource().setContent(IOUtils.toByteArray(inputStream));
    } finally {
      inputStream.close();
    }
  } catch (MalformedURLException e) {
    throw new RegistryException("Unable to connect to URL", e);
  } catch (IOException e) {
    throw new RegistryException("Unable to download URL content", e);
  }
  put(requestContext);
}

代码示例来源:origin: org.wso2.carbon.business-process/org.wso2.carbon.bpel

private void addLatestArchiveToRegistryCollection(BPELDeploymentContext bpelDeploymentContext)
    throws FileNotFoundException, RegistryException {
  Resource latestBPELArchive = configRegistry.newResource();
  FileInputStream stream = new FileInputStream(bpelDeploymentContext.getBpelArchive());
  latestBPELArchive.setContent(stream);
  configRegistry.put(BPELPackageRepositoryUtils.
          getBPELPackageArchiveResourcePath(bpelDeploymentContext.getBpelPackageName()),
      latestBPELArchive);
}

代码示例来源:origin: org.wso2.carbon.identity.framework/org.wso2.carbon.security.mgt

private void persistPolicy(AxisService service, OMElement policy, String policyID) throws RegistryException {
  //Registry registryToLoad = SecurityServiceHolder.getRegistryService().getConfigSystemRegistry();
  Resource resource = registry.newResource();
  resource.setContent(policy.toString());
  String servicePath = getRegistryServicePath(service);
  String policyResourcePath = servicePath + RegistryResources.POLICIES + policyID;
  registry.put(policyResourcePath, resource);
}

代码示例来源:origin: org.wso2.carbon.identity/org.wso2.carbon.security.mgt

private void persistPolicy(AxisService service, OMElement policy, String policyID) throws RegistryException {
  //Registry registryToLoad = SecurityServiceHolder.getRegistryService().getConfigSystemRegistry();
  Resource resource = registry.newResource();
  resource.setContent(policy.toString());
  String servicePath = getRegistryServicePath(service);
  String policyResourcePath = servicePath + RegistryResources.POLICIES + policyID;
  registry.put(policyResourcePath, resource);
}

代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.governance.registry.extensions

protected void doCopy(RequestContext requestContext, String resourcePath, String newPath)
    throws RegistryException {
  if (requestContext.getResource() instanceof Collection) {
    Registry registry = requestContext.getRegistry();
    Object content = registry.get(
        (String) parameterMap.get(MAPPINGS_RESOURCE)).getContent();
    String contentString = getContentString(content);
    int startingIndex = Integer.parseInt((String) parameterMap.get(STARTING_INDEX));
    Map<String, String> conversions = new HashMap<String, String>();
    for (String mapping : contentString.split("\n")) {
      String[] mappings = mapping.split("\r")[0].split(",");
      conversions.put(mappings[startingIndex - 1].trim(), mappings[startingIndex].trim());
    }
    registry.put(newPath, registry.get(resourcePath));
    for (String path : ((Collection)requestContext.getResource()).getChildren()) {
      String temp = RegistryConstants.PATH_SEPARATOR +
          RegistryUtils.getResourceName(path);
      Resource resource = registry.get(resourcePath + temp);
      String string = getContentString(resource.getContent());
      for (Map.Entry<String, String> e : conversions.entrySet()) {
        string = string.replace(e.getKey(), e.getValue());
      }
      resource.setContent(string);
      registry.put(newPath + temp, resource);
    }
  }
}

代码示例来源:origin: wso2/carbon-identity-framework

private void persistPolicy(AxisService service, OMElement policy, String policyID) throws RegistryException {
  //Registry registryToLoad = SecurityServiceHolder.getRegistryService().getConfigSystemRegistry();
  Resource resource = registry.newResource();
  resource.setContent(policy.toString());
  String servicePath = getRegistryServicePath(service);
  String policyResourcePath = servicePath + RegistryResources.POLICIES + policyID;
  registry.put(policyResourcePath, resource);
}

代码示例来源: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

private void saveTiers(Collection<Tier> tiers) throws AppManagementException {
  OMFactory fac = OMAbstractFactory.getOMFactory();
  OMElement root = fac.createOMElement(AppMConstants.POLICY_ELEMENT);
  OMElement assertion = fac.createOMElement(AppMConstants.ASSERTION_ELEMENT);
  try {
    Resource resource = registry.newResource();
    for (Tier tier : tiers) {
      String policy = new String(tier.getPolicyContent());
      assertion.addChild(AXIOMUtil.stringToOM(policy));
      // if (tier.getDescription() != null && !"".equals(tier.getDescription())) {
      //     resource.setProperty(AppMConstants.TIER_DESCRIPTION_PREFIX + tier.getName(),
      //              tier.getDescription());
      //  }
    }
    //resource.setProperty(AppMConstants.TIER_DESCRIPTION_PREFIX + AppMConstants.UNLIMITED_TIER,
    //        AppMConstants.UNLIMITED_TIER_DESC);
    root.addChild(assertion);
    resource.setContent(root.toString());
    registry.put(AppMConstants.API_TIER_LOCATION, resource);
  } catch (XMLStreamException e) {
    handleException("Error while constructing tier policy file", e);
  } catch (RegistryException e) {
    handleException("Error while saving tier configurations to the registry", e);
  }
}

代码示例来源:origin: org.apache.stratos/org.apache.stratos.throttling.manager

/**
   * Load throttling rules
   *
   * @throws Exception, if loading the throttling rules failed.
   */
  public static void loadThrottlingRules() throws Exception {
    UserRegistry systemRegistry = getSuperTenantGovernanceSystemRegistry();
    if (systemRegistry.resourceExists(StratosConstants.THROTTLING_RULES_PATH)) {
      return;
    }
    String throttlingRuleFile = CarbonUtils.getCarbonConfigDirPath() +
        File.separator + THROTTLING_RULE_FILE;
    byte[] content = CarbonUtils.getBytesFromFile(new File(throttlingRuleFile));
    Resource ruleResource = systemRegistry.newResource();
    ruleResource.setContent(content);
    systemRegistry.put(StratosConstants.THROTTLING_RULES_PATH, ruleResource);
  }
}

代码示例来源: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.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.commons/org.wso2.carbon.reporting.template.core

public void saveMetadata
    () throws ReportingException {
  try {
    RegistryService registryService = ReportingTemplateComponent.getRegistryService();
    Registry registry = registryService.getConfigSystemRegistry();
    registry.beginTransaction();
    Resource reportFilesResource = registry.newResource();
    reportFilesResource.setContent(reportsElement.toString());
    String location = ReportConstants.REPORT_META_DATA_PATH + ReportConstants.METADATA_FILE_NAME;
    registry.put(location, reportFilesResource);
    registry.commitTransaction();
  } catch (RegistryException e) {
    throw new ReportingException("Exception occured in loading the meta-data of reports", e);
  }
}

代码示例来源:origin: org.wso2.carbon.appmgt/org.wso2.carbon.appmgt.impl

public boolean subscribeMobileApp(String userId, String appId) throws AppManagementException {
  String path = "users/" + userId + "/subscriptions/mobileapp/" + appId;
  Resource resource = null;
  boolean isSubscribed = false;
  try {
    UserRegistry sysRegistry = ServiceReferenceHolder.getInstance().getRegistryService()
        .getGovernanceSystemRegistry(tenantId);
    if (!sysRegistry.resourceExists(path)) {
      resource = sysRegistry.newResource();
      resource.setContent("");
      sysRegistry.put(path, resource);
      isSubscribed = true;
    }
  } catch (org.wso2.carbon.registry.api.RegistryException e) {
    handleException("Error occurred while adding subscription registry resource for mobileapp with id :" +
        appId, e);
  }
  return isSubscribed;
}

代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.jcr

public Property setProperty(String s, double v) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
    RegistryJCRItemOperationUtil.checkRetentionPolicy(registrySession,getPath());
    RegistryJCRItemOperationUtil.checkRetentionHold(registrySession, getPath());

    registrySession.sessionPending();
    validatePropertyModifyPrivilege(s);

    Resource res = null;
    try {
      res = registrySession.getUserRegistry().newResource();
      res.setContent(String.valueOf(v));
      res.setProperty("registry.jcr.property.type", "double");
      registrySession.getUserRegistry().put(nodePath + "/" + s, res);
      property = new RegistryProperty(nodePath + "/" + s, registrySession, s,v);

    } catch (RegistryException e) {
      String msg = "failed to resolve the path of the given node or violation of repository syntax " + this;
      log.debug(msg);
      throw new RepositoryException(msg, e);
    }
    isModified = true;
//        property.setValue(v);
    return property;
  }

代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.jcr

public Property setProperty(String s, long l) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
  RegistryJCRItemOperationUtil.checkRetentionPolicy(registrySession,getPath());
  RegistryJCRItemOperationUtil.checkRetentionHold(registrySession, getPath());
  registrySession.sessionPending();
  validatePropertyModifyPrivilege(s);
  Resource res = null;
  try {
    res = registrySession.getUserRegistry().newResource();
    res.setContent(String.valueOf(l));
    res.setProperty("registry.jcr.property.type", "long");
    registrySession.getUserRegistry().put(nodePath + "/" + s, res);
    property = new RegistryProperty(nodePath + "/" + s, registrySession, s,l);
  } catch (RegistryException e) {
    String msg = "failed to resolve the path of the given node or violation of repository syntax " + this;
    log.debug(msg);
    throw new RepositoryException(msg, e);
  }
  isModified = true;
  return property;
}

代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.jcr

public Property setProperty(String s, boolean b) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
    RegistryJCRItemOperationUtil.checkRetentionPolicy(registrySession,getPath());
    RegistryJCRItemOperationUtil.checkRetentionHold(registrySession, getPath());

    registrySession.sessionPending();
    validatePropertyModifyPrivilege(s);

    Resource res = null;
    try {
      res = registrySession.getUserRegistry().newResource();
      res.setContent(String.valueOf(b));
      res.setProperty("registry.jcr.property.type", "boolean");
      registrySession.getUserRegistry().put(nodePath + "/" + s, res);
      property = new RegistryProperty(nodePath + "/" + s, registrySession, s,b);

    } catch (RegistryException e) {
      String msg = "failed to resolve the path of the given node or violation of repository syntax " + this;
      log.debug(msg);
      throw new RepositoryException(msg, e);
    }

    isModified = true;
//        property.setValue(b);
    return property;
  }

代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.jcr

public Property setProperty(String s, BigDecimal bigDecimal) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
  RegistryJCRItemOperationUtil.checkRetentionPolicy(registrySession,getPath());
  RegistryJCRItemOperationUtil.checkRetentionHold(registrySession, getPath());
  registrySession.sessionPending();
  validatePropertyModifyPrivilege(s);
  if (bigDecimal != null) {
    Resource res = null;
    try {
      res = registrySession.getUserRegistry().newResource();
      res.setContent(bigDecimal.toString());
      res.setProperty("registry.jcr.property.type", "big_decimal");
      registrySession.getUserRegistry().put(nodePath + "/" + s, res);
      property = new RegistryProperty(nodePath + "/" + s, registrySession, s,bigDecimal);
    } catch (RegistryException e) {
      String msg = "failed to resolve the path of the given node or violation of repository syntax " + this;
      log.debug(msg);
      throw new RepositoryException(msg, e);
    }
    isModified = true;
    return property;
  } else {
    isModified = true;
    return null;
  }
}

代码示例来源: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);
  }
}

相关文章