public static String getResourceContent(Resource tempResource) throws RegistryException { if (tempResource.getContent() instanceof String) { return (String) tempResource.getContent(); } else if (tempResource.getContent() instanceof byte[]) { return RegistryUtils.decodeBytes((byte[]) tempResource.getContent()); } return null; }
private static String convertContentToString(Resource resource) throws RegistryException { if (resource.getContent() instanceof String) { return RegistryUtils.decodeBytes(((String) resource.getContent()).getBytes()); } else if (resource.getContent() instanceof byte[]) { return RegistryUtils.decodeBytes((byte[]) resource.getContent()); } return RegistryUtils.decodeBytes("".getBytes()); }
private List<String> getVersionsOfPackage(String packageLocation) throws RegistryException { List<String> versions = new ArrayList<String>(); String versionsLocation = packageLocation + BPELConstants.BPEL_PACKAGE_VERSIONS; // If a new addition of a process fails to deploy there there will not be a collection called // version if (configRegistry.resourceExists(versionsLocation)) { Resource versionsResource = configRegistry.get(versionsLocation); // The above registry resource we retrieve only contains set of child collections. // So we can directly cast the returned object to a string array. String[] children = (String[]) versionsResource.getContent(); for (String child : children) { versions.add(child.substring(child.lastIndexOf("/") + 1)); } Collections.sort(versions, Utils.BY_VERSION); } return versions; }
private static String buildOMContent(Resource resource, StatCollection currentCollection) throws Exception { String content = null; String property = resource.getProperty(REGISTRY_LIFECYCLE_HISTORY_ORDER); int newOrder = 0; if (property != null) { newOrder = Integer.parseInt(property) + 1; } resource.setProperty(REGISTRY_LIFECYCLE_HISTORY_ORDER, "" + newOrder); if (resource.getContent() != null) { if (resource.getContent() instanceof String) { content = (String) resource.getContent(); } else if (resource.getContent() instanceof byte[]) { content = RegistryUtils.decodeBytes((byte[]) resource.getContent()); } } if (content == null) { content = buildInitialOMElement().toString(); } return addNewContentElement(content, currentCollection, newOrder); }
/** * @param policyId * @param finder * @return * @throws EntitlementException */ public synchronized AbstractPolicy readPolicy(String policyId, PolicyFinder finder) throws EntitlementException { Resource resource = store.getPolicy(policyId, PDPConstants.ENTITLEMENT_POLICY_PAP); if (resource != null) { try { String policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); return PAPPolicyReader.getInstance(null).getPolicy(policy); } catch (RegistryException e) { log.error("Error while parsing entitlement policy", e); throw new EntitlementException("Error while loading entitlement policy"); } } return null; }
/** * @param policyId * @param finder * @return * @throws EntitlementException */ public synchronized AbstractPolicy readPolicy(String policyId, PolicyFinder finder) throws EntitlementException { Resource resource = store.getPolicy(policyId, PDPConstants.ENTITLEMENT_POLICY_PAP); if (resource != null) { try { String policy = new String((byte[]) resource.getContent(), Charset.forName("UTF-8")); return PAPPolicyReader.getInstance(null).getPolicy(policy); } catch (RegistryException e) { log.error("Error while parsing entitlement policy", e); throw new EntitlementException("Error while loading entitlement policy"); } } return null; }
public Object jsGet_content() throws CarbonException { try { Object result = this.resource.getContent(); String mediaType = this.resource.getMediaType(); if (result instanceof byte[]) { //if mediaType is xml related one, we return an e4x xml object if(mediaType.matches(".*[\\/].*[xX][mM][lL].*")) { return context.newObject(this, "XML", new Object[]{new String((byte[]) result)}); } return new String((byte[]) result); } else if (result instanceof String[]) { return new NativeArray((String[])result); } else { return Context.toObject(result, this); } } catch (RegistryException e) { throw new CarbonException("Registry Exception while reading content property", e); } }
public List<BPELPackageInfo> getBPELPackages() throws Exception { List<BPELPackageInfo> bpelPackages = new ArrayList<BPELPackageInfo>(); try { if (configRegistry.resourceExists(BPELConstants.REG_PATH_OF_BPEL_PACKAGES)) { Resource parentCollection = configRegistry.get( BPELConstants.REG_PATH_OF_BPEL_PACKAGES); // The above registry resource we retrieve only contains set of child collections. // So we can directly cast the returned object to a string array. String[] children = (String[]) parentCollection.getContent(); for (int i = children.length - 1; i >= 0; i--) { bpelPackages.add(getBPELPackageInfo(children[i])); } return sortByPackageName(bpelPackages); } } catch (RegistryException re) { handleExceptionWithRollback("Unable to get BPEL Packages from Repository.", re); } return null; }
public ProfilesBean getUserProfile(String path) throws RegistryException,UserStoreException{ Registry registry = getConfigSystemRegistry(); Resource resource = registry.get(path); String contentString = (String)resource.getContent(); ProfilesBean profbean = new ProfilesBean(); profbean.setMainDataString(contentString); // profilebean.calculatevalues(); return profbean; } }
public static String getLifecycleConfiguration(String name, Registry registry) throws RegistryException, XMLStreamException { String path = getContextRoot() + name; Resource resource; if (lifeCycleExists(name, registry)) { resource = registry.get(path); return RegistryUtils.decodeBytes((byte[])resource.getContent()); } return null; } public static String getLifecycleConfigurationVersion(String name, Registry registry) throws RegistryException, XMLStreamException {
/** * Create a challenge question object from the registry resource * * @param resource * @return */ private ChallengeQuestion createChallengeQuestion(Resource resource) throws RegistryException { ChallengeQuestion challengeQuestion = null; byte[] resourceContent = (byte[]) resource.getContent(); String questionText = new String(resourceContent, Charset.forName("UTF-8")); String questionSetId = resource.getProperty(IdentityRecoveryConstants.Questions.CHALLENGE_QUESTION_SET_ID); String questionId = resource.getProperty(IdentityRecoveryConstants.Questions.CHALLENGE_QUESTION_ID); String questionLocale = resource.getProperty(IdentityRecoveryConstants.Questions.CHALLENGE_QUESTION_LOCALE); if (questionSetId != null) { if (IdentityUtil.isBlank(questionLocale)) { questionLocale = LOCALE_EN_US; } challengeQuestion = new ChallengeQuestion(questionSetId, questionId, questionText, questionLocale); } return challengeQuestion; }
public SAMLSSOServiceProviderDO[] getServiceProviders() throws IdentityException { SAMLSSOServiceProviderDO[] serviceProvidersList = new SAMLSSOServiceProviderDO[0]; try { if (registry.resourceExists(IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS)) { String[] providers = (String[]) registry.get( IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS).getContent(); if (providers != null) { serviceProvidersList = new SAMLSSOServiceProviderDO[providers.length]; for (int i = 0; i < providers.length; i++) { serviceProvidersList[i] = resourceToObject(registry.get(providers[i])); } } } } catch (RegistryException e) { log.error("Error reading Service Providers from Registry", e); throw IdentityException.error("Error reading Service Providers from Registry", e); } return serviceProvidersList; }
public SAMLSSOServiceProviderDO[] getServiceProviders() throws IdentityException { SAMLSSOServiceProviderDO[] serviceProvidersList = new SAMLSSOServiceProviderDO[0]; try { if (registry.resourceExists(IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS)) { String[] providers = (String[]) registry.get( IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS).getContent(); if (providers != null) { serviceProvidersList = new SAMLSSOServiceProviderDO[providers.length]; for (int i = 0; i < providers.length; i++) { serviceProvidersList[i] = resourceToObject(registry.get(providers[i])); } } } } catch (RegistryException e) { log.error("Error reading Service Providers from Registry", e); throw IdentityException.error("Error reading Service Providers from Registry", e); } return serviceProvidersList; }
public SAMLSSOServiceProviderDO[] getServiceProviders() throws IdentityException { SAMLSSOServiceProviderDO[] serviceProvidersList = new SAMLSSOServiceProviderDO[0]; try { if (registry.resourceExists(IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS)) { String[] providers = (String[]) registry.get( IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS).getContent(); if (providers != null) { serviceProvidersList = new SAMLSSOServiceProviderDO[providers.length]; for (int i = 0; i < providers.length; i++) { serviceProvidersList[i] = resourceToObject(registry.get(providers[i])); } } } } catch (RegistryException e) { log.error("Error reading Service Providers from Registry", e); throw IdentityException.error("Error reading Service Providers from Registry", e); } return serviceProvidersList; }
/** * This method is used to get rxt data. * * @param userRegistry userRegistry. * @return * @throws RegistryException */ public static Map<String, List<String>> getRxtData(UserRegistry userRegistry) throws RegistryException { String[] paths = getRxtPathLists(userRegistry); Map<String, List<String>> RxtDetails = new ConcurrentHashMap<>(); for (String path : paths) { String rxtContent = RegistryUtils.decodeBytes((byte[]) userRegistry.get(path).getContent()); RxtUnboundedEntryBean rxtUnboundedEntryBean = getRxtUnboundedEntries(rxtContent); String mediaType = rxtUnboundedEntryBean.getMediaType(); List<String> unboundedFields = rxtUnboundedEntryBean.getFields(); if (mediaType != null && unboundedFields.size() > 0) { RxtDetails.put(rxtUnboundedEntryBean.getMediaType(), rxtUnboundedEntryBean.getFields()); } } return RxtDetails; }
public static String getTextContent(String path, Registry registry) throws Exception { try { if (path != null && path.contains("..")) { path = FilenameUtils.normalize(path); } Resource resource = registry.get(path); byte[] content = (byte[]) resource.getContent(); String contentString = ""; if (content != null) { contentString = RegistryUtils.decodeBytes(content); } resource.discard(); return contentString; } catch (RegistryException e) { String msg = "Could not get the content of the resource " + path + ". Caused by: " + ((e.getCause() instanceof SQLException) ? "" : e.getMessage()); log.error(msg, e); throw new RegistryException(msg, e); } }
private void preparePut(String path, RequestContext requestContext) throws RegistryException { Resource resource = requestContext.getResource(); if (resource instanceof Collection) { filesystemManager.createDirectory(path); } else { Object content = resource.getContent(); if (content instanceof String) { filesystemManager.createOrUpdateFile(path, RegistryUtils.encodeString(((String)content))); } else { filesystemManager.createOrUpdateFile(path, (byte[])content); } //resource.setContent(""); } }
public void put(RequestContext requestContext) throws RegistryException { if (!CommonUtil.isUpdateLockAvailable()) { return; } CommonUtil.acquireUpdateLock(); try { SchemaValidator validator = new SchemaValidator(); Resource resource = requestContext.getResource(); Object resourceContent = resource.getContent(); if (resourceContent instanceof byte[]) { InputStream in = new ByteArrayInputStream((byte[]) resourceContent); validator.validate(in, resource); } resource.setContentStream(null); // requestContext.getRegistry().put(resource.getPath() ,resource); } finally { CommonUtil.releaseUpdateLock(); } }
public void importResource(RequestContext requestContext) throws RegistryException { if (!CommonUtil.isUpdateLockAvailable()) { return; } CommonUtil.acquireUpdateLock(); try { SchemaValidator validator = new SchemaValidator(); Resource resource = requestContext.getResource(); Object resourceContent = resource.getContent(); if (resourceContent instanceof byte[]) { InputStream in = new ByteArrayInputStream((byte[]) resourceContent); validator.validate(in, resource); } resource.setContentStream(null); // requestContext.getRegistry().put(resource.getPath() ,resource); } finally { CommonUtil.releaseUpdateLock(); } }
private OMElement setEndpoint(Registry registry, String definitionURL, OMElement serviceInfoElement) throws RegistryException { Association[] associations = registry.getAssociations(definitionURL, CommonConstants.DEPENDS); for (Association association: associations) { String targetPath = association.getDestinationPath(); if (registry.resourceExists(targetPath)) { Resource targetResource = registry.get(targetPath); if (CommonConstants.ENDPOINT_MEDIA_TYPE.equals(targetResource.getMediaType())) { byte[] sourceContent = (byte[]) targetResource.getContent(); if (sourceContent == null) { return serviceInfoElement; } String endpointUrl = EndpointUtils.deriveEndpointFromContent(RegistryUtils.decodeBytes(sourceContent)); try { serviceInfoElement = EndpointUtils.addEndpointToService(serviceInfoElement, endpointUrl, ""); } catch (RegistryException e){} } } } return serviceInfoElement; }