public ResourceContentInputStream(Resource resource) throws RegistryException { this.resource = resource; inputStream = resource.getContentStream(); }
protected List<String> getServersToDiscover(Registry registry) throws RegistryException, IOException { Resource resource = registry.get(serverIdPropertyFilePath); if (resource != null) { Properties serverProperties = new Properties(); serverProperties.load(resource.getContentStream()); String serverStr = serverProperties.getProperty(SERVERS_PROPERTY); if (serverStr != null) { String[] servers = serverStr.split(SERVER_ID_SEPARATOR); return Arrays.asList(servers); } } return Collections.emptyList(); }
private Policy loadPolicy(Resource resource) throws org.wso2.carbon.registry.api.RegistryException, XMLStreamException { InputStream in = resource.getContentStream(); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); xmlInputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", false); XMLStreamReader parser = xmlInputFactory.createXMLStreamReader(in); StAXOMBuilder builder = new StAXOMBuilder(parser); OMElement policyElement = builder.getDocumentElement(); return PolicyEngine.getPolicy(policyElement); }
private Policy loadPolicy(Resource resource) throws org.wso2.carbon.registry.api.RegistryException, XMLStreamException { InputStream in = resource.getContentStream(); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); xmlInputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", false); XMLStreamReader parser = xmlInputFactory.createXMLStreamReader(in); StAXOMBuilder builder = new StAXOMBuilder(parser); OMElement policyElement = builder.getDocumentElement(); return PolicyEngine.getPolicy(policyElement); }
private Policy loadPolicy(Resource resource) throws org.wso2.carbon.registry.api.RegistryException, XMLStreamException { InputStream in = resource.getContentStream(); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); XMLStreamReader parser = xmlInputFactory.createXMLStreamReader(in); StAXOMBuilder builder = new StAXOMBuilder(parser); OMElement policyElement = builder.getDocumentElement(); return PolicyEngine.getPolicy(policyElement); }
private Policy loadPolicy(Resource resource) throws org.wso2.carbon.registry.api.RegistryException, XMLStreamException { InputStream in = resource.getContentStream(); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); XMLStreamReader parser = xmlInputFactory.createXMLStreamReader(in); StAXOMBuilder builder = new StAXOMBuilder(parser); OMElement policyElement = builder.getDocumentElement(); return PolicyEngine.getPolicy(policyElement); }
private Policy loadPolicy(Resource resource) throws org.wso2.carbon.registry.api.RegistryException, XMLStreamException { InputStream in = resource.getContentStream(); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); XMLStreamReader parser = xmlInputFactory.createXMLStreamReader(in); StAXOMBuilder builder = new StAXOMBuilder(parser); OMElement policyElement = builder.getDocumentElement(); return PolicyEngine.getPolicy(policyElement); }
private Policy loadPolicy(Resource resource) throws org.wso2.carbon.registry.api.RegistryException, XMLStreamException { InputStream in = resource.getContentStream(); XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(in); StAXOMBuilder builder = new StAXOMBuilder(parser); OMElement policyElement = builder.getDocumentElement(); return PolicyEngine.getPolicy(policyElement); }
String customPropertyDefinitions = IOUtils.toString(registry.get(customPropertyDefinitionsResourcePath).getContentStream());
private static void loadXML(Resource resource) throws ReportingException { InputStream reportDefinitionOmStream; StAXOMBuilder stAXOMBuilder; try { reportDefinitionOmStream = resource.getContentStream(); } catch (RegistryException e) { log.error("failed to get the metadata xml", e); throw new ReportingException("failed to get the metadata xml", e); } XMLInputFactory xmlInputFactory; XMLStreamReader xmlStreamReader = null; xmlInputFactory = XMLInputFactory.newInstance(); try { xmlStreamReader = xmlInputFactory.createXMLStreamReader(reportDefinitionOmStream); stAXOMBuilder = new StAXOMBuilder(xmlStreamReader); reportsElement = stAXOMBuilder.getDocumentElement(); reportsElement.build(); } catch (XMLStreamException e) { throw new ReportingException("failed to get the metadata xml", e); } }
private void loadXML(Resource resource) throws ReportingException { InputStream reportDefinitionOmStream; StAXOMBuilder stAXOMBuilder; try { reportDefinitionOmStream = resource.getContentStream(); } catch (RegistryException e) { throw new ReportingException("failed to get the metadata xml", e); } XMLInputFactory xmlInputFactory; XMLStreamReader xmlStreamReader = null; xmlInputFactory = XMLInputFactory.newInstance(); try { xmlStreamReader = xmlInputFactory.createXMLStreamReader(reportDefinitionOmStream); stAXOMBuilder = new StAXOMBuilder(xmlStreamReader); reportsElement = stAXOMBuilder.getDocumentElement(); reportsElement.build(); } catch (XMLStreamException e) { throw new ReportingException("failed to get the metadata xml", e); } }
InputStream in = resource.getContentStream(); XMLStreamReader parser = null; XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
public static byte[] getByteContent(Resource resource, String sourceURL) throws RegistryException { try { InputStream is = null; if (sourceURL != null) { is = new URL(sourceURL).openStream(); } else { Object content = resource.getContent(); if( null == content) { //returning an empty array, rather than 'null'. return new byte[0]; } is = resource.getContentStream(); if (is == null) { if (content instanceof byte[]) { return (byte[]) content; } else if (content instanceof String) { return RegistryUtils.encodeString((String) content); } else { throw new RegistryException("Unknown type found as content " + content); } } } return readBytesFromInputSteam(is); } catch (IOException e) { throw new RegistryException("Error at indexing", e); } }
/** * Get stored custom outSequences from governanceSystem registry * * @throws org.wso2.carbon.appmgt.api.AppManagementException */ public List<String> getCustomOutSequences() throws AppManagementException { List<String> sequenceList = new ArrayList<String>(); try { UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService() .getGovernanceSystemRegistry(tenantId); if (registry.resourceExists(AppMConstants.API_CUSTOM_OUTSEQUENCE_LOCATION)) { org.wso2.carbon.registry.api.Collection outSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(AppMConstants.API_CUSTOM_OUTSEQUENCE_LOCATION); if (outSeqCollection !=null) { String[] outSeqChildPaths = outSeqCollection.getChildren(); for (int i = 0; i < outSeqChildPaths.length; i++) { Resource outSequence = registry.get(outSeqChildPaths[i]); OMElement seqElment = AppManagerUtil.buildOMElement(outSequence.getContentStream()); sequenceList.add(seqElment.getAttributeValue(new QName("name"))); } } } } catch (Exception e) { handleException("Issue is in getting custom OutSequences from the Registry", e); } return sequenceList; }
/** * Get stored custom inSequences from governanceSystem registry * * @throws org.wso2.carbon.appmgt.api.AppManagementException */ public List<String> getCustomInSequences() throws AppManagementException { List<String> sequenceList = new ArrayList<String>(); try { UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService() .getGovernanceSystemRegistry(tenantId); if (registry.resourceExists(AppMConstants.API_CUSTOM_INSEQUENCE_LOCATION)) { org.wso2.carbon.registry.api.Collection inSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(AppMConstants.API_CUSTOM_INSEQUENCE_LOCATION); if (inSeqCollection != null) { // SequenceMediatorFactory factory = new SequenceMediatorFactory(); String[] inSeqChildPaths = inSeqCollection.getChildren(); for (int i = 0; i < inSeqChildPaths.length; i++) { Resource inSequence = registry.get(inSeqChildPaths[i]); OMElement seqElment = AppManagerUtil.buildOMElement(inSequence.getContentStream()); sequenceList.add(seqElment.getAttributeValue(new QName("name"))); } } } } catch (Exception e) { handleException("Issue is in getting custom InSequences from the Registry", e); } return sequenceList; }
@Override protected Set<Action> compileAllowableActions(Set<Action> aas) { Set<Action> result = super.compileAllowableActions(aas); try { boolean status = getNode().getContentStream() != null ? true : false; setAction(result, Action.CAN_GET_CONTENT_STREAM, status); } catch (RegistryException e) { log.error("Failed to get the content stream for the node " + getNode().getId() + " " , e); setAction(result, Action.CAN_GET_CONTENT_STREAM, false); } setAction(result, Action.CAN_SET_CONTENT_STREAM, true); setAction(result, Action.CAN_DELETE_CONTENT_STREAM, true); setAction(result, Action.CAN_GET_RENDITIONS, false); return result; }
private InputStream getTemplateResource(String templateName) throws ReportingException { String localPath = "templates/"; String jrXmlPath = ReportConstants.REPORT_BASE_PATH + localPath + templateName + ".jrxml"; Registry registry = null; try { registry = ReportingTemplateComponent.getRegistryService().getConfigSystemRegistry(); } catch (RegistryException e) { throw new ReportingException(e.getMessage(), e); } Resource resource; InputStream reportDefinitionOmStream; try { resource = registry.get(jrXmlPath); reportDefinitionOmStream = resource.getContentStream(); return reportDefinitionOmStream; } catch (RegistryException e) { throw new ReportingException(templateName + " getting failed from registry", e); } }
public Icon getIcon(APIIdentifier identifier) throws AppManagementException { String artifactPath = AppMConstants.API_IMAGE_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion(); String thumbPath = artifactPath + RegistryConstants.PATH_SEPARATOR + AppMConstants.API_ICON_IMAGE; try { if (registry.resourceExists(thumbPath)) { Resource res = registry.get(thumbPath); Icon icon = new Icon(res.getContentStream(), res.getMediaType()); return icon; } } catch (RegistryException e) { handleException("Error while loading WebApp icon from the registry", e); } return null; }
/** * Initialize the google analytics publisher by reading tenants google analytics * configuration from the registry * * @param tenantDomain Tenant domain of the current tenant */ public void init(String tenantDomain) { configKey = APIConstants.GA_CONFIGURATION_LOCATION; try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); Registry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(); Resource resource = registry.get(configKey); InputStream in = resource.getContentStream(); StAXOMBuilder builder = new StAXOMBuilder(in); this.gaConfig = new GoogleAnalyticsConfig(builder.getDocumentElement()); } catch (RegistryException | XMLStreamException e) { // flow should not break. Therefore ignoring the exception log.error("Failed to retrieve google analytics configurations for tenant:" + tenantDomain); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
public ContentStream getContentStream(){ // compile data ContentStreamImpl result = new ContentStreamImpl(); result.setFileName(getName()); try { result.setLength(BigInteger.valueOf(getPropertyLength(getNode(), CMISConstants.GREG_DATA))); if(getNode().getContent() != null){ String mimeType = getNode().getProperty(CMISConstants.GREG_MIMETYPE); result.setMimeType(mimeType); //result.setMimeType(getNode().getMediaType()); } else { result.setMimeType(null); } if(getNode().getContent() != null){ InputStream inputStream = getNode().getContentStream(); result.setStream(new BufferedInputStream(inputStream)); // stream closed by consumer } else { result.setStream(null); } } catch (RegistryException e) { throw new CmisRuntimeException(e.getMessage(), e); } return result; }