Example usage for javax.xml.stream XMLInputFactory newInstance

List of usage examples for javax.xml.stream XMLInputFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.stream XMLInputFactory newInstance.

Prototype

public static XMLInputFactory newInstance() throws FactoryConfigurationError 

Source Link

Document

Creates a new instance of the factory in exactly the same manner as the #newFactory() method.

Usage

From source file:org.openvpms.tools.data.loader.DataLoaderTestCase.java

/**
 * Loads a file.//from   www.  j  ava2s .c o  m
 *
 * @param loader the loader
 * @param file   the file to load
 * @throws Exception for any error
 */
private void load(DataLoader loader, String file) throws Exception {
    InputStream stream = getClass().getResourceAsStream(file);
    assertNotNull(stream);
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader reader = factory.createXMLStreamReader(stream);
    loader.load(reader, file);
}

From source file:ca.efendi.datafeeds.messaging.FtpSubscriptionMessageListener.java

private void parse(FtpSubscription ftpSubscription, final InputStream is) throws XMLStreamException {
    final XMLInputFactory factory = XMLInputFactory.newInstance();
    factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, true);
    factory.setProperty(XMLInputFactory.IS_COALESCING, true);
    final XMLStreamReader reader = factory.createXMLStreamReader(is, "UTF-8");
    CJProduct product = null;//from  ww w  .  j a v  a 2  s. co m
    String tagContent = null;
    //final ServiceContext serviceContext = new ServiceContext();

    //ServiceContext serviceContext = ServiceContextFactory.getInstance(
    //        BlogsEntry.class.getName(), actionRequest);

    //serviceContext.setScopeGroupId(20159);
    while (reader.hasNext()) {
        final int event = reader.next();
        switch (event) {
        case XMLStreamConstants.START_ELEMENT:
            //tagContent = "";
            if ("product".equals(reader.getLocalName())) {
                product = _cjProductLocalService.createCJProduct(0);
            }
            break;
        case XMLStreamConstants.CHARACTERS:
            //tagContent += reader.getText().trim();
            tagContent = reader.getText().trim();
            break;
        case XMLStreamConstants.END_ELEMENT:
            switch (reader.getLocalName()) {
            case "product":
                try {

                    _log.warn("refreshing document...");
                    _cjProductLocalService.refresh(ftpSubscription, product);
                } catch (final SystemException e) {
                    _log.error(e);
                } catch (final PortalException e) {
                    _log.error(e);
                }
                break;
            case "programname":
                product.setProgramName(tagContent);
                break;
            case "programurl":
                product.setProgramUrl(tagContent);
                break;
            case "catalogname":
                product.setCatalogName(tagContent);
                break;
            case "lastupdated":
                product.setLastUpdated(tagContent);
                break;
            case "name":
                product.setName(tagContent);
                break;
            case "keywords":
                product.setKeywords(tagContent);
                break;
            case "description":
                product.setDescription(tagContent);
                break;
            case "sku":
                product.setSku(tagContent);
                break;
            case "manufacturer":
                product.setManufacturer(tagContent);
                break;
            case "manufacturerid":
                product.setManufacturerId(tagContent);
                break;
            case "currency":
                product.setCurrency(tagContent);
                break;
            case "price":
                product.setPrice(tagContent);
                break;
            case "buyurl":
                product.setBuyUrl(tagContent);
                break;
            case "impressionurl":
                product.setImpressionUrl(tagContent);
                break;
            case "imageurl":
                product.setImageUrl(tagContent);
                break;
            case "instock":
                product.setInStock(tagContent);
                break;
            }
            break;
        case XMLStreamConstants.START_DOCUMENT:
            break;
        }
    }
}

From source file:com.qcadoo.model.internal.classconverter.ModelXmlToClassConverterImpl.java

private void defineClasses(final Map<String, CtClass> ctClasses, final InputStream stream)
        throws XMLStreamException, ModelXmlCompilingException, NotFoundException {
    XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(stream);

    while (reader.hasNext() && reader.next() > 0) {
        if (isTagStarted(reader, TAG_MODEL)) {
            String pluginIdentifier = getPluginIdentifier(reader);
            String modelName = getStringAttribute(reader, L_NAME);
            String className = ClassNameUtils.getFullyQualifiedClassName(pluginIdentifier, modelName);

            if (ctClasses.containsKey(className)) {
                parse(reader, ctClasses.get(className), pluginIdentifier);
            }/*  w  w  w  .  j  a v  a2  s  .  c  o  m*/
        }
    }

    reader.close();
}

From source file:edu.harvard.i2b2.crc.axis2.QueryService.java

/**
 * Function constructs OMElement for the given String
 * //from w w  w .  jav  a 2s  .co m
 * @param xmlString
 * @return OMElement
 * @throws XMLStreamException
 */
private OMElement buildOMElementFromString(String xmlString) throws XMLStreamException {
    XMLInputFactory xif = XMLInputFactory.newInstance();
    StringReader strReader = new StringReader(xmlString);
    XMLStreamReader reader = xif.createXMLStreamReader(strReader);
    StAXOMBuilder builder = new StAXOMBuilder(reader);
    OMElement element = builder.getDocumentElement();
    return element;
}

From source file:org.openvpms.tools.data.loader.StaxArchetypeDataLoader.java

/**
 * Return the XMLReader for the specified file
 *
 * @param file the file/*w w w . j  a  v a 2  s .  c  o m*/
 * @return XMLStreamReader
 * @throws FileNotFoundException if the file cannot be found
 * @throws XMLStreamException if the file cannot be read
 */
private XMLStreamReader getReader(File file) throws FileNotFoundException, XMLStreamException {
    FileInputStream stream = new FileInputStream(file);
    XMLInputFactory factory = XMLInputFactory.newInstance();

    return factory.createXMLStreamReader(stream);
}

From source file:edu.harvard.i2b2.eclipse.plugins.analysis.ontologyMessaging.OntServiceDriver.java

/**
 * Function to convert Ont requestVdo to OMElement
 * //  w  w  w .  ja va  2  s  .com
 * @param requestVdo   String requestVdo to send to Ont web service
 * @return An OMElement containing the Ont web service requestVdo
 */
public static OMElement getOntPayLoad(String requestVdo) throws Exception {
    OMElement lineItem = null;
    try {
        StringReader strReader = new StringReader(requestVdo);
        XMLInputFactory xif = XMLInputFactory.newInstance();
        XMLStreamReader reader = xif.createXMLStreamReader(strReader);

        StAXOMBuilder builder = new StAXOMBuilder(reader);
        lineItem = builder.getDocumentElement();
    } catch (FactoryConfigurationError e) {
        log.error(e.getMessage());
        throw new Exception(e);
    }
    return lineItem;
}

From source file:edu.harvard.i2b2.crc.dao.setfinder.querybuilder.temporal.TemporalPanelCellQueryItem.java

private OMElement buildOMElement(RequestMessageType requestMessageType, String requestXml)
        throws XMLStreamException, JAXBUtilException {
    StringWriter strWriter = new StringWriter();
    edu.harvard.i2b2.crc.datavo.i2b2message.ObjectFactory hiveof = new edu.harvard.i2b2.crc.datavo.i2b2message.ObjectFactory();
    jaxbUtil.marshaller(hiveof.createRequest(requestMessageType), strWriter);

    //insert request
    String msgBody = "<message_body/>";
    String xmlrequest = strWriter.toString();
    int index = xmlrequest.indexOf(msgBody);
    if (index >= 0) {
        xmlrequest = xmlrequest.substring(0, index) + "<message_body>" + requestXml + "</message_body>"
                + xmlrequest.substring(index + msgBody.length() + 1);
    }/* ww  w. ja  v  a  2  s.co m*/

    StringReader strReader = new StringReader(xmlrequest);
    XMLInputFactory xif = XMLInputFactory.newInstance();
    XMLStreamReader reader = xif.createXMLStreamReader(strReader);
    StAXOMBuilder builder = new StAXOMBuilder(reader);
    OMElement request = builder.getDocumentElement();
    return request;
}

From source file:com.conx.logistics.kernel.bpm.impl.jbpm.core.mock.BPMGuvnorUtil.java

public List<String> getAllProcessesInPackage(String pkgName) {
    List<String> processes = new ArrayList<String>();
    String assetsURL = getGuvnorProtocol() + "://" + getGuvnorHost() + "/" + getGuvnorSubdomain()
            + "/rest/packages/" + pkgName + "/assets/";

    try {/*from w  w  w .jav a2 s  .co m*/
        XMLInputFactory factory = XMLInputFactory.newInstance();
        XMLStreamReader reader = factory.createXMLStreamReader(getInputStreamForURL(assetsURL, "GET"));

        String format = "";
        String title = "";
        while (reader.hasNext()) {
            int next = reader.next();
            if (next == XMLStreamReader.START_ELEMENT) {
                if ("format".equals(reader.getLocalName())) {
                    format = reader.getElementText();
                }
                if ("title".equals(reader.getLocalName())) {
                    title = reader.getElementText();
                }
                if ("asset".equals(reader.getLocalName())) {
                    if (format.equals(EXT_BPMN) || format.equals(EXT_BPMN2)) {
                        processes.add(title);
                        title = "";
                        format = "";
                    }
                }
            }
        }
        // last one
        if (format.equals(EXT_BPMN) || format.equals(EXT_BPMN2)) {
            processes.add(title);
        }
    } catch (Exception e) {
        logger.error("Error finding processes in package: " + e.getMessage());
    }
    return processes;
}

From source file:fr.gael.dhus.server.http.webapp.search.controller.SearchController.java

void xmlToJson(InputStream xmlInput, OutputStream jsonOutput) throws XMLStreamException {
    JsonXMLConfig config = new JsonXMLConfigBuilder().autoArray(true).autoPrimitive(false).fieldPrefix("")
            .contentField("content").build();

    XMLEventReader reader = XMLInputFactory.newInstance().createXMLEventReader(xmlInput);
    XMLEventWriter writer = new JsonXMLOutputFactory(config).createXMLEventWriter(jsonOutput);

    writer.add(reader);//from   w w  w . j  a  v  a 2s  .  c o  m

    reader.close();
    writer.close();
}

From source file:com.funtl.framework.smoke.core.modules.act.service.ActProcessService.java

/**
 * ??/*from  w w  w  .j ava  2s .com*/
 *
 * @param procDefId
 * @throws UnsupportedEncodingException
 * @throws XMLStreamException
 */
@Transactional(readOnly = false)
public org.activiti.engine.repository.Model convertToModel(String procDefId)
        throws UnsupportedEncodingException, XMLStreamException {

    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
            .processDefinitionId(procDefId).singleResult();
    InputStream bpmnStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),
            processDefinition.getResourceName());
    XMLInputFactory xif = XMLInputFactory.newInstance();
    InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
    XMLStreamReader xtr = xif.createXMLStreamReader(in);
    BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

    BpmnJsonConverter converter = new BpmnJsonConverter();
    ObjectNode modelNode = converter.convertToJson(bpmnModel);
    org.activiti.engine.repository.Model modelData = repositoryService.newModel();
    modelData.setKey(processDefinition.getKey());
    modelData.setName(processDefinition.getResourceName());
    modelData.setCategory(processDefinition.getCategory());//.getDeploymentId());
    modelData.setDeploymentId(processDefinition.getDeploymentId());
    modelData.setVersion(Integer.parseInt(
            String.valueOf(repositoryService.createModelQuery().modelKey(modelData.getKey()).count() + 1)));

    ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
    modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName());
    modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, modelData.getVersion());
    modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription());
    modelData.setMetaInfo(modelObjectNode.toString());

    repositoryService.saveModel(modelData);

    repositoryService.addModelEditorSource(modelData.getId(), modelNode.toString().getBytes("utf-8"));

    return modelData;
}