List of usage examples for javax.xml.stream XMLInputFactory setProperty
public abstract void setProperty(java.lang.String name, Object value) throws java.lang.IllegalArgumentException;
From source file:org.wso2.carbon.governance.generic.services.ManageGenericArtifactService.java
public String addArtifact(String key, String info, String lifecycleAttribute) throws RegistryException { RegistryUtils.recordStatistics(key, info, lifecycleAttribute); Registry registry = getGovernanceUserRegistry(); if (RegistryUtils.isRegistryReadOnly(registry.getRegistryContext())) { return null; }/*from w ww.j a v a 2s.c o m*/ try { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, true); XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(info)); GenericArtifactManager manager = new GenericArtifactManager(registry, key); GenericArtifact artifact = manager .newGovernanceArtifact(new StAXOMBuilder(reader).getDocumentElement()); // want to save original content, so set content here artifact.setContent(info.getBytes()); artifact.setAttribute("resource.source", "AdminConsole"); manager.addGenericArtifact(artifact); if (lifecycleAttribute != null) { String lifecycle = artifact.getAttribute(lifecycleAttribute); if (lifecycle != null) { artifact.attachLifecycle(lifecycle); } } return RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + artifact.getPath(); } catch (Exception e) { String msg = "Unable to add artifact. "; if (e instanceof RegistryException) { throw (RegistryException) e; } else if (e instanceof OMException) { msg += "Unexpected character found in input-field name."; log.error(msg, e); throw new RegistryException(msg, e); } throw new RegistryException( msg + (e.getCause() instanceof SQLException ? "" : e.getCause().getMessage()), e); } }
From source file:org.wso2.carbon.governance.generic.services.ManageGenericArtifactService.java
public ArtifactsBean listArtifacts(String key, String criteria) { RegistryUtils.recordStatistics(key, criteria); UserRegistry governanceRegistry = (UserRegistry) getGovernanceUserRegistry(); ArtifactsBean bean = new ArtifactsBean(); try {//from ww w. ja v a 2 s . c om final GovernanceArtifactConfiguration configuration = loadAndFindGovernanceArtifactConfiguration(key, getRootRegistry()); GenericArtifactManager manager = new GenericArtifactManager(governanceRegistry, configuration.getMediaType(), configuration.getArtifactNameAttribute(), configuration.getArtifactNamespaceAttribute(), configuration.getArtifactElementRoot(), configuration.getArtifactElementNamespace(), configuration.getPathExpression(), configuration.getRelationshipDefinitions()); final GenericArtifact referenceArtifact; if (criteria != null) { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, true); XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(criteria)); referenceArtifact = manager.newGovernanceArtifact(new StAXOMBuilder(reader).getDocumentElement()); } else { referenceArtifact = null; } bean.setNames(configuration.getNamesOnListUI()); bean.setTypes(configuration.getTypesOnListUI()); bean.setKeys(configuration.getKeysOnListUI()); String[] expressions = configuration.getExpressionsOnListUI(); String[] keys = configuration.getKeysOnListUI(); List<GovernanceArtifact> artifacts = new LinkedList<GovernanceArtifact>(); artifacts.addAll( Arrays.asList(manager.findGenericArtifacts(getFieldsList(referenceArtifact, configuration)))); List<ArtifactBean> artifactBeans = new LinkedList<ArtifactBean>(); for (GovernanceArtifact artifact : artifacts) { int kk = 0; ArtifactBean artifactBean = new ArtifactBean(); List<String> paths = new ArrayList<String>(); List<String> values = new ArrayList<String>(); String path = RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + ((GenericArtifactImpl) artifact).getArtifactPath(); artifactBean.setPath(path); for (int i = 0; i < expressions.length; i++) { if (expressions[i] != null) { if (expressions[i].contains("@{storagePath}") && ((GenericArtifactImpl) artifact).getArtifactPath() != null) { paths.add(RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + GovernanceUtils.getPathFromPathExpression(expressions[i], artifact, ((GenericArtifactImpl) artifact).getArtifactPath())); } else { if ("link".equals(bean.getTypes()[i])) { paths.add(GovernanceUtils.getPathFromPathExpression(expressions[i], artifact, configuration.getPathExpression())); } else { paths.add(RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + GovernanceUtils.getPathFromPathExpression(expressions[i], artifact, configuration.getPathExpression())); } } } else { paths.add(""); } } artifactBean.setValuesB(paths.toArray(new String[paths.size()])); for (String keyForValue : keys) { if (keyForValue != null) { values.add(artifact.getAttribute(keyForValue)); } else { values.add(""); } } artifactBean.setValuesA(values.toArray(new String[values.size()])); artifactBean.setCanDelete(governanceRegistry.getUserRealm().getAuthorizationManager() .isUserAuthorized(governanceRegistry.getUserName(), path, ActionConstants.DELETE)); artifactBean.setLCName(((GenericArtifactImpl) artifact).getLcName()); artifactBean.setLCState(((GenericArtifactImpl) artifact).getLcState()); artifactBean.setCreatedDate(governanceRegistry .get(((GenericArtifactImpl) artifact).getArtifactPath()).getCreatedTime()); artifactBean.setLastUpdatedDate(governanceRegistry .get(((GenericArtifactImpl) artifact).getArtifactPath()).getLastModified()); artifactBean.setCreatedBy(governanceRegistry.get(((GenericArtifactImpl) artifact).getArtifactPath()) .getAuthorUserName()); artifactBean.setLastUpdatedBy(governanceRegistry .get(((GenericArtifactImpl) artifact).getArtifactPath()).getLastUpdaterUserName()); artifactBeans.add(artifactBean); } bean.setArtifacts(artifactBeans.toArray(new ArtifactBean[artifactBeans.size()])); } catch (RuntimeException e) { throw e; } catch (Exception e) { log.error("An error occurred while obtaining the list of artifacts.", e); } return bean; }
From source file:org.wso2.carbon.governance.generic.services.ManageGenericArtifactService.java
public String editArtifact(String path, String key, String info, String lifecycleAttribute) throws RegistryException { RegistryUtils.recordStatistics(path, key, info, lifecycleAttribute); Registry registry = getGovernanceUserRegistry(); if (RegistryUtils.isRegistryReadOnly(registry.getRegistryContext())) { return null; }// w w w.ja v a 2 s. com try { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, true); XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(info)); GovernanceArtifactConfiguration configuration = loadAndFindGovernanceArtifactConfiguration(key, getRootRegistry()); GenericArtifactManager manager = new GenericArtifactManager(registry, key); GenericArtifact artifact = manager .newGovernanceArtifact(new StAXOMBuilder(reader).getDocumentElement()); String currentPath; if (path != null && path.length() > 0) { currentPath = path.substring(RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH.length()); } else { currentPath = GovernanceUtils.getPathFromPathExpression(configuration.getPathExpression(), artifact); } if (registry.resourceExists(currentPath)) { GovernanceArtifact oldArtifact = GovernanceUtils.retrieveGovernanceArtifactByPath(registry, currentPath); if (!(oldArtifact instanceof GovernanceArtifact)) { String msg = "The updated path is occupied by a non-generic artifact. path: " + currentPath + "."; log.error(msg); throw new Exception(msg); } artifact.setId(oldArtifact.getId()); // want to save original content artifact.setContent(info.getBytes()); manager.updateGenericArtifact(artifact); } else { manager.addGenericArtifact(artifact); } if (lifecycleAttribute != null && !lifecycleAttribute.equals("null")) { String lifecycle = artifact.getAttribute(lifecycleAttribute); artifact.attachLifecycle(lifecycle); } return RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + artifact.getPath(); } catch (Exception e) { String msg = "Unable to edit artifact. "; if (e instanceof RegistryException) { throw (RegistryException) e; } else if (e instanceof OMException) { msg += "Unexpected character found in input-field name."; log.error(msg, e); throw new RegistryException(msg, e); } throw new RegistryException( msg + (e.getCause() instanceof SQLException ? "" : e.getCause().getMessage()), e); } }
From source file:org.wso2.carbon.governance.metadata.provider.util.Util.java
public static OMElement buildOMElement(byte[] content) throws MetadataException { XMLStreamReader parser;/*from w w w.j av a 2 s . com*/ try { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, new Boolean(true)); parser = factory.createXMLStreamReader(new StringReader(RegistryUtils.decodeBytes(content))); } catch (Exception e) { String msg = "Error in initializing the parser to build the OMElement."; log.error(msg, e); throw new MetadataException("", e); } //create the builder StAXOMBuilder builder = new StAXOMBuilder(parser); //get the root element (in this case the envelope) return builder.getDocumentElement(); }
From source file:org.wso2.carbon.localentry.service.LocalEntryAdmin.java
private OMElement nonCoalescingStringToOm(String xmlStr) throws XMLStreamException { StringReader strReader = new StringReader(xmlStr); XMLInputFactory xmlInFac = XMLInputFactory.newInstance(); //Non-Coalescing parsing xmlInFac.setProperty("javax.xml.stream.isCoalescing", false); XMLStreamReader parser = xmlInFac.createXMLStreamReader(strReader); StAXOMBuilder builder = new StAXOMBuilder(parser); return builder.getDocumentElement(); }
From source file:org.wso2.carbon.localentry.ui.client.LocalEntryAdminClient.java
public static OMElement nonCoalescingStringToOm(String xmlStr) throws XMLStreamException { StringReader strReader = new StringReader(xmlStr); XMLInputFactory xmlInFac = XMLInputFactory.newInstance(); //Non-Coalescing parsing xmlInFac.setProperty("javax.xml.stream.isCoalescing", false); XMLStreamReader parser = xmlInFac.createXMLStreamReader(strReader); StAXOMBuilder builder = new StAXOMBuilder(parser); return builder.getDocumentElement(); }
From source file:org.wso2.carbon.mediation.configadmin.ConfigAdmin.java
/** * Get the current Synapse configuration serialized as an string * * @return return XML configuration serialized in to a string * @throws org.apache.axis2.AxisFault if an error occurs *//* w w w . j a va2 s.c o m*/ public String getConfiguration() throws AxisFault { final Lock lock = getLock(); try { lock.lock(); // ConfigurationFactoryAndSerializerFinder might not have been initialized // and hence we need to call the getInstance to load the factories and serializers ConfigurationFactoryAndSerializerFinder.getInstance(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); XMLConfigurationSerializer.serializeConfiguration(getSynapseConfiguration(), stream); XMLInputFactory factory = XMLInputFactory.newInstance(); if (factory.isPropertySupported(PROP_REPORT_CDATA)) { factory.setProperty(PROP_REPORT_CDATA, Boolean.TRUE); } ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(stream.toByteArray()); org.wso2.carbon.mediation.configadmin.util.XMLPrettyPrinter xmlPrettyPrinter = new org.wso2.carbon.mediation.configadmin.util.XMLPrettyPrinter( byteArrayInputStream); return xmlPrettyPrinter.xmlFormatWithComments(); } catch (XMLStreamException e) { handleException("Error serializing the Synapse configuration : Error " + e.getMessage(), e); } catch (Exception e) { handleException("Error serializing the Synapse configuration : Error " + e.getMessage(), e); } finally { lock.unlock(); } return ""; }
From source file:org.wso2.carbon.mediation.library.util.LocalEntryUtil.java
public static OMElement nonCoalescingStringToOm(String xmlStr) throws XMLStreamException { StringReader strReader = new StringReader(xmlStr); XMLInputFactory xmlInFac = XMLInputFactory.newInstance(); // Non-Coalescing parsing xmlInFac.setProperty("javax.xml.stream.isCoalescing", false); XMLStreamReader parser = xmlInFac.createXMLStreamReader(strReader); StAXOMBuilder builder = new StAXOMBuilder(parser); return builder.getDocumentElement(); }
From source file:pl.hycom.pip.messanger.pipeline.PipelineManager.java
@Override public void afterPropertiesSet() throws Exception { XMLInputFactory xif = XMLInputFactory.newFactory(); xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); XMLStreamReader xsr = xif//w ww . j ava 2s . c o m .createXMLStreamReader(new StreamSource(getClass().getResourceAsStream(pipelineFileURL))); pipeline = (Pipeline) JAXBContext.newInstance(Pipeline.class).createUnmarshaller().unmarshal(xsr); }
From source file:source.YahooAnswersStreamParser.java
public YahooAnswersStreamParser(String fileName, boolean bDoCleanUp) throws IOException, XMLStreamException { mFile = new File(fileName); mDoCleanUp = bDoCleanUp;// w w w. j a v a 2 s .com final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, true); InputStream is = CompressUtils.createInputStream(fileName); mReader = factory.createXMLStreamReader(new InvalidXmlCharFilter(new InputStreamReader(is, "UTF-8"))); mNextDoc = fetchNext(); }