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.deegree.services.wfs.WebFeatureService.java

private OWSMetadataProvider initMetadataProvider(DeegreeServicesMetadataType serviceMetadata,
        DeegreeWFS jaxbConfig) throws ResourceInitException {
    OWSMetadataProvider provider = null;
    provider = workspace.getResource(OWSMetadataProviderProvider.class,
            getMetadata().getIdentifier().getId() + "_metadata");

    if (provider == null) {
        ServiceIdentification serviceId = MetadataUtils
                .convertFromJAXB(serviceMetadata.getServiceIdentification());
        if (serviceId.getTitles().isEmpty()) {
            serviceId.setTitles(Collections.singletonList(new LanguageString("deegree 3 WFS", null)));
        }/*from   w ww . j av a  2s . c  o m*/
        if (serviceId.getAbstracts().isEmpty()) {
            serviceId.setAbstracts(Collections.singletonList(new LanguageString("deegree 3 WFS", null)));
        }
        ServiceProvider serviceProvider = MetadataUtils.convertFromJAXB(serviceMetadata.getServiceProvider());

        if (serviceProvider.getProviderName() == null) {
            serviceProvider.setProviderName("deegree organization");
        }
        if (serviceProvider.getProviderSite() == null) {
            serviceProvider.setProviderSite("http://www.deegree.org");
        }

        List<DatasetMetadata> ftMetadata = new ArrayList<DatasetMetadata>();
        String metadataUrlTemplate = jaxbConfig.getMetadataURLTemplate();
        if (metadataUrlTemplate == null) {
            // use local CSW (if running)
            List<ResourceIdentifier<OWS>> owss = workspace.getResourcesOfType(OWSProvider.class);
            for (ResourceIdentifier<OWS> id : owss) {
                OWS o = workspace.getResource(OWSProvider.class, id.getId());
                if (o != null) {
                    ImplementationMetadata<?> md = ((OWSProvider) o.getMetadata().getProvider())
                            .getImplementationMetadata();
                    for (String s : md.getImplementedServiceName()) {
                        if (s.equalsIgnoreCase("csw")) {
                            metadataUrlTemplate = OGCFrontController.getHttpGetURL();
                            if (!metadataUrlTemplate.endsWith("?")) {
                                metadataUrlTemplate = metadataUrlTemplate + "?";
                            }
                            metadataUrlTemplate += "service=CSW&request=GetRecordById&version=2.0.2&outputSchema=http://www.isotc211.org/2005/gmd&elementSetName=full&id=${metadataSetId}";
                        }
                    }
                }
            }
        }

        for (FeatureTypeMetadata ftMd : jaxbConfig.getFeatureTypeMetadata()) {
            // TODO
            List<LanguageString> titles = null;
            // TODO
            List<LanguageString> abstracts = null;
            // TODO
            List<Pair<List<LanguageString>, CodeType>> keywords = null;
            final List<MetadataUrl> metadataUrls = new ArrayList<MetadataUrl>();
            final String url = getMetadataURL(metadataUrlTemplate, ftMd);
            if (url != null) {
                metadataUrls.add(new MetadataUrl(url, null, null));
            }
            try {
                DatasetMetadata dsMd = new DatasetMetadata(ftMd.getName(), titles, abstracts, keywords,
                        metadataUrls, null, null, null, null);
                ftMetadata.add(dsMd);
            } catch (Throwable t) {
                t.printStackTrace();
            }

        }

        Map<String, List<OMElement>> wfsVersionToExtendedCaps = new HashMap<String, List<OMElement>>();
        List<ExtendedCapabilities> extendedCapConfigs = jaxbConfig.getExtendedCapabilities();
        if (extendedCapConfigs != null) {
            for (ExtendedCapabilities extendedCapConfig : extendedCapConfigs) {
                Element extendedCaps = extendedCapConfig.getAny();
                DOMSource domSource = new DOMSource(extendedCaps);
                XMLStreamReader xmlStream;
                try {
                    xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(domSource);
                } catch (Exception t) {
                    throw new ResourceInitException("Error extracting extended capabilities: " + t.getMessage(),
                            t);
                }
                OMElement omEl = new XMLAdapter(xmlStream).getRootElement();
                for (String wfsVersion : extendedCapConfig.getWfsVersions()) {
                    if (wfsVersionToExtendedCaps.containsKey(wfsVersion)) {
                        String msg = "Multiple ExtendedCapabilities sections for WFS version: " + wfsVersion
                                + ".";
                        throw new ResourceInitException(msg);
                    }
                    wfsVersionToExtendedCaps.put(wfsVersion, Collections.singletonList(omEl));
                }
            }
        }
        provider = new DefaultOWSMetadataProvider(serviceId, serviceProvider, wfsVersionToExtendedCaps,
                ftMetadata, Collections.<String, String>emptyMap(), null);
    }
    return provider;
}

From source file:org.deegree.services.wms.controller.WMSController.java

@Override
public void init(DeegreeServicesMetadataType serviceMetadata, DeegreeServiceControllerType mainConfig,
        Object controllerConf) {// ww  w .  jav  a  2 s.  co  m

    identification = convertFromJAXB(serviceMetadata.getServiceIdentification());
    provider = convertFromJAXB(serviceMetadata.getServiceProvider());

    NamespaceBindings nsContext = new NamespaceBindings();
    nsContext.addNamespace("wms", "http://www.deegree.org/services/wms");

    conf = (DeegreeWMS) controllerConf;

    if (conf.getExtendedCapabilities() != null) {
        this.extendedCaps = new HashMap<String, List<OMElement>>();
        List<OMElement> caps = new ArrayList<OMElement>(conf.getExtendedCapabilities().size());
        extendedCaps.put("default", caps);
        for (ExtendedCapabilities extendedCapsConf : conf.getExtendedCapabilities()) {
            DOMSource domSource = new DOMSource(extendedCapsConf.getAny());
            XMLStreamReader xmlStream;
            try {
                xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(domSource);
            } catch (Exception t) {
                throw new ResourceInitException("Error extracting extended capabilities: " + t.getMessage(), t);
            }
            caps.add(new XMLAdapter(xmlStream).getRootElement());
        }
    }

    try {
        addSupportedImageFormats(conf);

        if (conf.getFeatureInfoFormats() != null) {
            for (GetFeatureInfoFormat t : conf.getFeatureInfoFormats().getGetFeatureInfoFormat()) {
                if (t.getFile() != null) {
                    featureInfoManager.addOrReplaceFormat(t.getFormat(),
                            metadata.getLocation().resolveToFile(t.getFile()).toString());
                } else if (t.getXSLTFile() != null) {
                    XSLTFile xsltFile = t.getXSLTFile();
                    GMLVersion version = GMLVersion.valueOf(xsltFile.getGmlVersion().toString());
                    featureInfoManager.addOrReplaceXsltFormat(t.getFormat(),
                            metadata.getLocation().resolveToUrl(xsltFile.getValue()), version, workspace);
                } else if (t.getSerializer() != null) {
                    Serializer serializer = t.getSerializer();

                    FeatureInfoSerializer featureInfoSerializer;
                    try {
                        Class<?> clazz = workspace.getModuleClassLoader().loadClass(serializer.getJavaClass());
                        featureInfoSerializer = clazz.asSubclass(FeatureInfoSerializer.class).newInstance();
                    } catch (ClassNotFoundException e) {
                        throw new IllegalArgumentException("Couldn't find serializer class", e);
                    } catch (ClassCastException e) {
                        throw new IllegalArgumentException(
                                "Configured serializer class doesn't implement FeatureInfoSerializer", e);
                    }

                    featureInfoManager.addOrReplaceCustomFormat(t.getFormat(), featureInfoSerializer);
                } else {
                    throw new IllegalArgumentException("Unknown GetFeatureInfoFormat");
                }
            }
        }

        // if ( pi.getImageFormat() != null ) {
        // for ( ImageFormat f : pi.getImageFormat() ) {
        // instantiateSerializer( imageSerializers, f.getFormat(), f.getClazz(), ImageSerializer.class );
        // }
        // }

        final org.deegree.services.jaxb.wms.DeegreeWMS.SupportedVersions versions = conf.getSupportedVersions();
        if (versions == null) {
            ArrayList<String> vs = new ArrayList<String>();
            vs.add("1.1.1");
            vs.add("1.3.0");
            validateAndSetOfferedVersions(vs);
        } else {
            validateAndSetOfferedVersions(versions.getVersion());
        }

        for (Version v : offeredVersions) {
            if (v.equals(VERSION_111)) {
                controllers.put(VERSION_111, new WMSController111());
            }
            if (v.equals(VERSION_130)) {
                controllers.put(VERSION_130, new WMSController130());
            }
        }

        Iterator<Version> iter = controllers.keySet().iterator();
        while (iter.hasNext()) {
            highestVersion = iter.next();
        }

        ServiceConfigurationType sc = conf.getServiceConfiguration();
        service = new MapService(sc, workspace);

        // after the service knows what layers are available:
        handleMetadata(conf.getMetadataURLTemplate(), conf.getMetadataStoreId());

        String configId = getMetadata().getIdentifier().getId();
        metadataProvider = workspace.getResource(OWSMetadataProviderProvider.class, configId + "_metadata");
    } catch (Exception e) {
        throw new ResourceInitException(e.getMessage(), e);
    }

}

From source file:org.deegree.services.wms.SldStyleBuilder.java

private void handleExternalSld(File file, String namedLayer, String layerName, Map<String, String> map,
        Map<String, Pair<File, URL>> legends, Map<String, Boolean> glgUrls) throws Throwable {
    LOG.info("Parsing SLD style file unavailable from style stores.");
    XMLInputFactory fac = XMLInputFactory.newInstance();
    FileInputStream is = new FileInputStream(file);
    try {//from w  w w.j  av a2s.c om
        XMLStreamReader in = fac.createXMLStreamReader(file.toURI().toURL().toString(), is);
        Pair<LinkedList<Filter>, LinkedList<StyleRef>> parsedStyles = getStyles(in, namedLayer, map);
        for (StyleRef s : parsedStyles.second) {
            if (!s.isResolved()) {
                continue;
            }
            registry.put(layerName, s.getStyle(), false);
            Pair<File, URL> p = legends.get(s.getName());
            if (p != null && p.first != null) {
                s.getStyle().setLegendFile(p.first);
            } else if (p != null) {
                s.getStyle().setLegendURL(p.second);
            }
            s.getStyle().setPrefersGetLegendGraphicUrl(
                    glgUrls.get(s.getStyle().getName()) != null && glgUrls.get(s.getStyle().getName()));
        }
    } finally {
        closeQuietly(is);
    }
}

From source file:org.deegree.services.wms.StyleRegistry.java

Style loadNoImport(String layerName, File file, boolean legend) {
    XMLInputFactory fac = XMLInputFactory.newInstance();
    FileInputStream in = null;/*  ww  w .  j  a  v a 2  s .  c o m*/
    try {

        LOG.debug("Trying to load{} style from '{}'", legend ? "" : " legend", file);
        in = new FileInputStream(file);
        Style sty = SymbologyParser.INSTANCE.parse(fac.createXMLStreamReader(file.toString(), in));

        if (legend) {
            monitoredLegendFiles.put(file, new Pair<Long, String>(file.lastModified(), layerName));
        } else {
            monitoredFiles.put(file, new Pair<Long, String>(file.lastModified(), layerName));
        }
        return sty;
    } catch (FileNotFoundException e) {
        LOG.info("Style file '{}' for layer '{}' could not be found: '{}'",
                new Object[] { file, layerName, e.getLocalizedMessage() });
    } catch (XMLStreamException e) {
        LOG.trace("Stack trace:", e);
        LOG.info("Style file '{}' for layer '{}' could not be loaded: '{}'",
                new Object[] { file, layerName, e.getLocalizedMessage() });
    } finally {
        closeQuietly(in);
    }
    return null;
}

From source file:org.deegree.services.wps.input.EmbeddedComplexInput.java

@Override
public InputStream getValueAsBinaryStream() {

    XMLStreamReader xmlStream = null;
    String textValue = null;//from  w ww. j  a v a  2 s .c  om
    try {
        try {
            xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(store.getInputStream());
        } catch (Throwable t) {
            throw new RuntimeException(t.getMessage());
        }
        XMLStreamUtils.skipStartDocument(xmlStream);
        textValue = xmlStream.getElementText();
    } catch (XMLStreamException e) {
        LOG.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage());
    } finally {
        if (xmlStream != null) {
            try {
                xmlStream.close();
            } catch (XMLStreamException e) {
                // nothing to do
            }
        }
    }

    ByteArrayInputStream is = null;

    if ("base64".equals(getEncoding())) {
        LOG.debug("Performing base64 decoding of embedded ComplexInput: " + textValue);
        is = new ByteArrayInputStream(Base64.decodeBase64(textValue));
    } else {
        LOG.warn("Unsupported encoding '" + getEncoding() + "'.");
        is = new ByteArrayInputStream(textValue.getBytes());
    }

    return is;
}

From source file:org.deegree.services.wps.input.EmbeddedComplexInput.java

@Override
public XMLStreamReader getValueAsXMLStream() throws XMLStreamException {
    XMLStreamReader xmlReader = null;
    try {// ww  w  . j  av a  2  s  .c o m
        xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(store.getInputStream());
    } catch (Throwable t) {
        throw new RuntimeException(t.getMessage());
    }
    XMLStreamUtils.skipStartDocument(xmlReader);
    XMLStreamUtils.nextElement(xmlReader);
    return xmlReader;
}

From source file:org.deegree.services.wps.input.EmbeddedComplexInput.java

public XMLStreamReader getComplexDataAsXMLStream() throws XMLStreamException {
    XMLStreamReader xmlReader = null;
    try {//w w  w.j  a v  a2  s .  c  o  m
        xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(store.getInputStream());
    } catch (Throwable t) {
        throw new RuntimeException(t.getMessage());
    }
    XMLStreamUtils.skipStartDocument(xmlReader);
    return xmlReader;
}

From source file:org.deegree.services.wps.provider.jrxml.contentprovider.Utils.java

public static ProcessletInputs getInputs(String parameterId, String mimeType, String schema,
        InputStream complexInput) throws IOException, XMLStreamException, FactoryConfigurationError {
    List<ProcessletInput> inputs = new ArrayList<ProcessletInput>();
    ProcessletInputs in = new ProcessletInputs(inputs);

    ComplexInputDefinition definition = new ComplexInputDefinition();
    definition.setTitle(getAsLanguageStringType(parameterId));
    definition.setIdentifier(getAsCodeType(parameterId));
    ComplexFormatType format = new ComplexFormatType();

    format.setEncoding("UTF-8");
    format.setMimeType(mimeType);/*from w w w . ja  v  a  2s. co m*/
    format.setSchema(schema);
    definition.setDefaultFormat(format);
    definition.setMaxOccurs(BigInteger.valueOf(1));
    definition.setMinOccurs(BigInteger.valueOf(0));

    File f = File.createTempFile("tmpStore", "");
    StreamBufferStore store = new StreamBufferStore(1024, f);

    XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(complexInput);
    XMLStreamWriter xmlWriter = null;
    try {
        xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(store);
        if (xmlReader.getEventType() == START_DOCUMENT) {
            xmlReader.nextTag();
        }
        XMLAdapter.writeElement(xmlWriter, xmlReader);
    } finally {
        try {
            xmlReader.close();
        } catch (XMLStreamException e) {
            // nothing to do
        }
        try {
            xmlWriter.close();
        } catch (XMLStreamException e) {
            // nothing to do
        }
        IOUtils.closeQuietly(store);
    }

    ComplexInputImpl mapProcesslet = new EmbeddedComplexInput(definition, new LanguageString("title", "ger"),
            new LanguageString("summary", "ger"), format, store);

    inputs.add(mapProcesslet);
    return in;
}

From source file:org.deegree.style.persistence.se.SeStyleStoreBuilder.java

@Override
public StyleStore build() {
    InputStream in = null;//from   www  . j a v  a 2 s  .  c o  m
    XMLStreamReader reader = null;
    try {
        in = metadata.getLocation().getAsStream();
        XMLInputFactory fac = XMLInputFactory.newInstance();
        reader = fac.createXMLStreamReader(in);
        SymbologyParser parser = new SymbologyParser(metadata.getLocation());
        Style style = parser.parse(reader);
        return new SEStyleStore(style, metadata);
    } catch (Exception e) {
        throw new ResourceInitException("Could not read SE style file.", e);
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (XMLStreamException e) {
            // eat it
        }
        closeQuietly(in);
    }
}

From source file:org.deegree.style.persistence.se.SEStyleStoreProvider.java

@Override
public SEStyleStore create(URL configUrl) throws ResourceInitException {
    InputStream in = null;//  www. j  a  v  a2  s. com
    XMLStreamReader reader = null;
    try {
        in = configUrl.openStream();
        XMLInputFactory fac = XMLInputFactory.newInstance();
        reader = fac.createXMLStreamReader(configUrl.toExternalForm(), in);
        Style style = SymbologyParser.INSTANCE.parse(reader);
        return new SEStyleStore(style);
    } catch (Throwable e) {
        throw new ResourceInitException("Could not read SE style file.", e);
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (XMLStreamException e) {
            // eat it
        }
        closeQuietly(in);
    }
}