Example usage for javax.xml.stream XMLStreamReader getLocalName

List of usage examples for javax.xml.stream XMLStreamReader getLocalName

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamReader getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the (local) name of the current event.

Usage

From source file:org.deegree.services.controller.OGCFrontController.java

private static boolean isSOAPRequest(XMLStreamReader xmlStream) {
    String ns = xmlStream.getNamespaceURI();
    String localName = xmlStream.getLocalName();
    return ("http://schemas.xmlsoap.org/soap/envelope/".equals(ns)
            || "http://www.w3.org/2003/05/soap-envelope".equals(ns)) && "Envelope".equals(localName);
}

From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java

private void writeTemplateElement(XMLStreamWriter writer, XMLStreamReader inStream,
        Map<String, String> varToValue) throws XMLStreamException {

    if (inStream.getEventType() != XMLStreamConstants.START_ELEMENT) {
        throw new XMLStreamException("Input stream does not point to a START_ELEMENT event.");
    }//  w w w  . j  av  a  2s.  c om
    int openElements = 0;
    boolean firstRun = true;
    while (firstRun || openElements > 0) {
        firstRun = false;
        int eventType = inStream.getEventType();

        switch (eventType) {
        case CDATA: {
            writer.writeCData(inStream.getText());
            break;
        }
        case CHARACTERS: {
            String s = new String(inStream.getTextCharacters(), inStream.getTextStart(),
                    inStream.getTextLength());
            // TODO optimize
            for (String param : varToValue.keySet()) {
                String value = varToValue.get(param);
                s = s.replace(param, value);
            }
            writer.writeCharacters(s);

            break;
        }
        case END_ELEMENT: {
            writer.writeEndElement();
            openElements--;
            break;
        }
        case START_ELEMENT: {
            if (inStream.getNamespaceURI() == "" || inStream.getPrefix() == DEFAULT_NS_PREFIX
                    || inStream.getPrefix() == null) {
                writer.writeStartElement(inStream.getLocalName());
            } else {
                if (writer.getNamespaceContext().getPrefix(inStream.getPrefix()) == "") {
                    // TODO handle special cases for prefix binding, see
                    // http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/javax/xml/namespace/NamespaceContext.html#getNamespaceURI(java.lang.String)
                    writer.setPrefix(inStream.getPrefix(), inStream.getNamespaceURI());
                }
                writer.writeStartElement(inStream.getPrefix(), inStream.getLocalName(),
                        inStream.getNamespaceURI());
            }
            // copy all namespace bindings
            for (int i = 0; i < inStream.getNamespaceCount(); i++) {
                String nsPrefix = inStream.getNamespacePrefix(i);
                String nsURI = inStream.getNamespaceURI(i);
                writer.writeNamespace(nsPrefix, nsURI);
            }

            // copy all attributes
            for (int i = 0; i < inStream.getAttributeCount(); i++) {
                String localName = inStream.getAttributeLocalName(i);
                String nsPrefix = inStream.getAttributePrefix(i);
                String value = inStream.getAttributeValue(i);
                String nsURI = inStream.getAttributeNamespace(i);
                if (nsURI == null) {
                    writer.writeAttribute(localName, value);
                } else {
                    writer.writeAttribute(nsPrefix, nsURI, localName, value);
                }
            }

            openElements++;
            break;
        }
        default: {
            break;
        }
        }
        if (openElements > 0) {
            inStream.next();
        }
    }
}

From source file:org.deegree.services.wfs.WebFeatureService.java

@Override
public void doXML(XMLStreamReader xmlStream, HttpServletRequest request, HttpResponseBuffer response,
        List<FileItem> multiParts) throws ServletException, IOException {

    LOG.debug("doXML");
    Version requestVersion = null;/*from  w  ww  . j  a  v a2s.co  m*/
    try {
        String requestName = xmlStream.getLocalName();
        WFSRequestType requestType = getRequestTypeByName(requestName);

        // check if requested version is supported and offered (except for GetCapabilities)
        requestVersion = getVersion(XMLStreamUtils.getAttributeValue(xmlStream, "version"));
        if (requestType != WFSRequestType.GetCapabilities) {
            requestVersion = checkVersion(requestVersion);

            // needed for CITE 1.1.0 compliance
            String serviceAttr = XMLStreamUtils.getAttributeValue(xmlStream, "service");
            if (serviceAttr != null && !("WFS".equals(serviceAttr) || "".equals(serviceAttr))) {
                throw new OWSException("Wrong service attribute: '" + serviceAttr + "' -- must be 'WFS'.",
                        INVALID_PARAMETER_VALUE, "service");
            }
        }

        if (disableBuffering) {
            response.disableBuffering();
        }

        switch (requestType) {
        case CreateStoredQuery:
            CreateStoredQueryXMLAdapter createStoredQueryAdapter = new CreateStoredQueryXMLAdapter();
            createStoredQueryAdapter.setRootElement(new XMLAdapter(xmlStream).getRootElement());
            CreateStoredQuery createStoredQuery = createStoredQueryAdapter.parse();
            storedQueryHandler.doCreateStoredQuery(createStoredQuery, response);
            break;
        case DescribeFeatureType:
            DescribeFeatureTypeXMLAdapter describeFtAdapter = new DescribeFeatureTypeXMLAdapter();
            describeFtAdapter.setRootElement(new XMLAdapter(xmlStream).getRootElement());
            DescribeFeatureType describeFt = describeFtAdapter.parse();
            Format format = determineFormat(requestVersion, describeFt.getOutputFormat(), "outputFormat");
            format.doDescribeFeatureType(describeFt, response, false);
            break;
        case DropStoredQuery:
            DropStoredQueryXMLAdapter dropStoredQueryAdapter = new DropStoredQueryXMLAdapter();
            dropStoredQueryAdapter.setRootElement(new XMLAdapter(xmlStream).getRootElement());
            DropStoredQuery dropStoredQuery = dropStoredQueryAdapter.parse();
            storedQueryHandler.doDropStoredQuery(dropStoredQuery, response);
            break;
        case DescribeStoredQueries:
            DescribeStoredQueriesXMLAdapter describeStoredQueriesAdapter = new DescribeStoredQueriesXMLAdapter();
            describeStoredQueriesAdapter.setRootElement(new XMLAdapter(xmlStream).getRootElement());
            DescribeStoredQueries describeStoredQueries = describeStoredQueriesAdapter.parse();
            storedQueryHandler.doDescribeStoredQueries(describeStoredQueries, response);
            break;
        case GetCapabilities:
            GetCapabilitiesXMLAdapter getCapabilitiesAdapter = new GetCapabilitiesXMLAdapter();
            getCapabilitiesAdapter.setRootElement(new XMLAdapter(xmlStream).getRootElement());
            GetCapabilities wfsRequest = getCapabilitiesAdapter.parse(requestVersion);
            doGetCapabilities(wfsRequest, response);
            break;
        case GetFeature:
            GetFeatureXMLAdapter getFeatureAdapter = new GetFeatureXMLAdapter();
            getFeatureAdapter.setRootElement(new XMLAdapter(xmlStream).getRootElement());
            GetFeature getFeature = getFeatureAdapter.parse();
            format = determineFormat(requestVersion, getFeature.getPresentationParams().getOutputFormat(),
                    "outputFormat");
            format.doGetFeature(getFeature, response);
            break;
        case GetFeatureWithLock:
            checkTransactionsEnabled(requestName);
            GetFeatureWithLockXMLAdapter getFeatureWithLockAdapter = new GetFeatureWithLockXMLAdapter();
            getFeatureWithLockAdapter.setRootElement(new XMLAdapter(xmlStream).getRootElement());
            GetFeatureWithLock getFeatureWithLock = getFeatureWithLockAdapter.parse();
            format = determineFormat(requestVersion,
                    getFeatureWithLock.getPresentationParams().getOutputFormat(), "outputFormat");
            format.doGetFeature(getFeatureWithLock, response);
            break;
        case GetGmlObject:
            GetGmlObjectXMLAdapter getGmlObjectAdapter = new GetGmlObjectXMLAdapter();
            getGmlObjectAdapter.setRootElement(new XMLAdapter(xmlStream).getRootElement());
            GetGmlObject getGmlObject = getGmlObjectAdapter.parse();
            format = determineFormat(requestVersion, getGmlObject.getOutputFormat(), "outputFormat");
            format.doGetGmlObject(getGmlObject, response);
            break;
        case GetPropertyValue:
            GetPropertyValueXMLAdapter getPropertyValueAdapter = new GetPropertyValueXMLAdapter();
            getPropertyValueAdapter.setRootElement(new XMLAdapter(xmlStream).getRootElement());
            GetPropertyValue getPropertyValue = getPropertyValueAdapter.parse();
            format = determineFormat(requestVersion, getPropertyValue.getPresentationParams().getOutputFormat(),
                    "outputFormat");
            format.doGetPropertyValue(getPropertyValue, response);
            break;
        case ListStoredQueries:
            ListStoredQueriesXMLAdapter listStoredQueriesAdapter = new ListStoredQueriesXMLAdapter();
            listStoredQueriesAdapter.setRootElement(new XMLAdapter(xmlStream).getRootElement());
            ListStoredQueries listStoredQueries = listStoredQueriesAdapter.parse();
            storedQueryHandler.doListStoredQueries(listStoredQueries, response);
            break;
        case LockFeature:
            checkTransactionsEnabled(requestName);
            LockFeatureXMLAdapter lockFeatureAdapter = new LockFeatureXMLAdapter();
            lockFeatureAdapter.setRootElement(new XMLAdapter(xmlStream).getRootElement());
            LockFeature lockFeature = lockFeatureAdapter.parse();
            lockFeatureHandler.doLockFeature(lockFeature, response);
            break;
        case Transaction:
            checkTransactionsEnabled(requestName);
            TransactionXmlReader transactionReader = new TransactionXmlReaderFactory().createReader(xmlStream);
            Transaction transaction = transactionReader.read(xmlStream);
            new TransactionHandler(this, service, transaction, idGenMode).doTransaction(response);
            break;
        default:
            throw new RuntimeException("Internal error: Unhandled request '" + requestName + "'.");
        }
    } catch (OWSException e) {
        LOG.debug(e.getMessage(), e);
        sendServiceException(requestVersion, e, response);
    } catch (XMLParsingException e) {
        LOG.trace("Stack trace:", e);
        sendServiceException(requestVersion, new OWSException(e.getMessage(), INVALID_PARAMETER_VALUE),
                response);
    } catch (MissingParameterException e) {
        LOG.trace("Stack trace:", e);
        sendServiceException(requestVersion, new OWSException(e), response);
    } catch (InvalidParameterValueException e) {
        LOG.trace("Stack trace:", e);
        sendServiceException(requestVersion, new OWSException(e), response);
    } catch (Throwable e) {
        LOG.trace("Stack trace:", e);
        sendServiceException(requestVersion, new OWSException(e.getMessage(), NO_APPLICABLE_CODE), response);
    }
}

From source file:org.deegree.services.wps.WPService.java

@Override
public void doXML(XMLStreamReader xmlStream, HttpServletRequest request, HttpResponseBuffer response,
        List<FileItem> multiParts) throws ServletException, IOException {

    LOG.trace("doXML invoked");

    try {/*from  w w w  . ja  va  2s. c  o m*/
        WPSRequestType requestType = getRequestTypeByName(xmlStream.getLocalName());

        // check if requested version is supported and offered (except for GetCapabilities)
        Version requestVersion = getVersion(xmlStream.getAttributeValue(null, "version"));
        if (requestType != WPSRequestType.GetCapabilities) {
            checkVersion(requestVersion);
        }

        switch (requestType) {
        case GetCapabilities:
            GetCapabilitiesXMLAdapter getCapabilitiesAdapter = new GetCapabilitiesXMLAdapter();
            getCapabilitiesAdapter.load(xmlStream);
            GetCapabilities getCapabilitiesRequest = getCapabilitiesAdapter.parse100();
            doGetCapabilities(getCapabilitiesRequest, response);
            break;
        case DescribeProcess:
            DescribeProcessRequestXMLAdapter describeProcessAdapter = new DescribeProcessRequestXMLAdapter();
            describeProcessAdapter.load(xmlStream);
            DescribeProcessRequest describeProcessRequest = describeProcessAdapter.parse100();
            doDescribeProcess(describeProcessRequest, response);
            break;
        case Execute:
            // TODO switch to StaX-based parsing
            ExecuteRequestXMLAdapter executeAdapter = new ExecuteRequestXMLAdapter(
                    processManager.getProcesses(), storageManager);
            executeAdapter.load(xmlStream);
            ExecuteRequest executeRequest = executeAdapter.parse100();
            doExecute(executeRequest, response);
            break;
        case GetOutput:
        case GetResponseDocument:
            String msg = "Request type '" + requestType.name() + "' is only support as KVP request.";
            throw new OWSException(msg, OWSException.OPERATION_NOT_SUPPORTED);
        }
    } catch (OWSException e) {
        sendServiceException(e, response);
    } catch (XMLStreamException e) {
        LOG.debug(e.getMessage());
    } catch (UnknownCRSException e) {
        LOG.debug(e.getMessage());
    }
}

From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java

Pair<Graphic, Continuation<Graphic>> parseGraphic(XMLStreamReader in) throws XMLStreamException {
    in.require(START_ELEMENT, null, "Graphic");

    Graphic base = new Graphic();
    Continuation<Graphic> contn = null;

    while (!(in.isEndElement() && in.getLocalName().equals("Graphic"))) {
        in.nextTag();/*from  w  w  w.j  a  v  a2  s .  c  om*/

        if (in.getLocalName().equals("Mark")) {
            final Pair<Mark, Continuation<Mark>> pair = parseMark(in);

            if (pair != null) {
                base.mark = pair.first;
                if (pair.second != null) {
                    contn = new Continuation<Graphic>(contn) {
                        @Override
                        public void updateStep(Graphic base, Feature f, XPathEvaluator<Feature> evaluator) {
                            pair.second.evaluate(base.mark, f, evaluator);
                        }
                    };
                }
            }
        } else if (in.getLocalName().equals("ExternalGraphic")) {
            try {
                final Triple<BufferedImage, String, Continuation<List<BufferedImage>>> p = parseExternalGraphic(
                        in);
                if (p.third != null) {
                    contn = new Continuation<Graphic>(contn) {
                        @Override
                        public void updateStep(Graphic base, Feature f, XPathEvaluator<Feature> evaluator) {
                            LinkedList<BufferedImage> list = new LinkedList<BufferedImage>();
                            p.third.evaluate(list, f, evaluator);
                            base.image = list.poll();
                        }
                    };
                } else {
                    base.image = p.first;
                    base.imageURL = p.second;
                }
            } catch (IOException e) {
                LOG.debug("Stack trace", e);
                LOG.warn("External graphic could not be loaded. Location: line '{}' column '{}' of file '{}'.",
                        new Object[] { in.getLocation().getLineNumber(), in.getLocation().getColumnNumber(),
                                in.getLocation().getSystemId() });
            }
        } else if (in.getLocalName().equals("Opacity")) {
            contn = context.parser.updateOrContinue(in, "Opacity", base, new Updater<Graphic>() {
                public void update(Graphic obj, String val) {
                    obj.opacity = Double.parseDouble(val);
                }
            }, contn).second;
        } else if (in.getLocalName().equals("Size")) {
            contn = context.parser.updateOrContinue(in, "Size", base, new Updater<Graphic>() {
                public void update(Graphic obj, String val) {
                    obj.size = Double.parseDouble(val);
                }
            }, contn).second;
        } else if (in.getLocalName().equals("Rotation")) {
            contn = context.parser.updateOrContinue(in, "Rotation", base, new Updater<Graphic>() {
                public void update(Graphic obj, String val) {
                    obj.rotation = Double.parseDouble(val);
                }
            }, contn).second;
        } else if (in.getLocalName().equals("AnchorPoint")) {
            while (!(in.isEndElement() && in.getLocalName().equals("AnchorPoint"))) {
                in.nextTag();

                if (in.getLocalName().equals("AnchorPointX")) {
                    contn = context.parser.updateOrContinue(in, "AnchorPointX", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.anchorPointX = Double.parseDouble(val);
                        }
                    }, contn).second;
                } else if (in.getLocalName().equals("AnchorPointY")) {
                    contn = context.parser.updateOrContinue(in, "AnchorPointY", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.anchorPointY = Double.parseDouble(val);
                        }
                    }, contn).second;
                } else if (in.isStartElement()) {
                    Location loc = in.getLocation();
                    LOG.error("Found unknown element '{}' at line {}, column {}, skipping.",
                            new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() });
                    skipElement(in);
                }
            }
        } else if (in.getLocalName().equals("Displacement")) {
            while (!(in.isEndElement() && in.getLocalName().equals("Displacement"))) {
                in.nextTag();

                if (in.getLocalName().equals("DisplacementX")) {
                    contn = context.parser.updateOrContinue(in, "DisplacementX", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.displacementX = Double.parseDouble(val);
                        }
                    }, contn).second;
                } else if (in.getLocalName().equals("DisplacementY")) {
                    contn = context.parser.updateOrContinue(in, "DisplacementY", base, new Updater<Graphic>() {
                        public void update(Graphic obj, String val) {
                            obj.displacementY = Double.parseDouble(val);
                        }
                    }, contn).second;
                } else if (in.isStartElement()) {
                    Location loc = in.getLocation();
                    LOG.error("Found unknown element '{}' at line {}, column {}, skipping.",
                            new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() });
                    skipElement(in);
                }
            }
        } else if (in.isStartElement()) {
            Location loc = in.getLocation();
            LOG.error("Found unknown element '{}' at line {}, column {}, skipping.",
                    new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() });
            skipElement(in);
        }
    }
    in.require(END_ELEMENT, null, "Graphic");

    return new Pair<Graphic, Continuation<Graphic>>(base, contn);
}

From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java

private Pair<Mark, Continuation<Mark>> parseMark(XMLStreamReader in) throws XMLStreamException {
    in.require(START_ELEMENT, null, "Mark");

    Mark base = new Mark();
    Continuation<Mark> contn = null;

    in.nextTag();/*  w w  w  . j a  v  a  2s  .c  o m*/

    while (!(in.isEndElement() && in.getLocalName().equals("Mark"))) {
        if (in.isEndElement()) {
            in.nextTag();
        }

        if (in.getLocalName().equals("WellKnownName")) {
            String wkn = in.getElementText();
            try {
                base.wellKnown = SimpleMark.valueOf(wkn.toUpperCase());
            } catch (IllegalArgumentException e) {
                LOG.warn("Specified unsupported WellKnownName of '{}', using square instead.", wkn);
                base.wellKnown = SimpleMark.SQUARE;
            }
        } else
            sym: if (in.getLocalName().equals("OnlineResource") || in.getLocalName().equals("InlineContent")) {
                LOG.debug("Loading mark from external file.");
                Triple<InputStream, String, Continuation<StringBuffer>> pair = getOnlineResourceOrInlineContent(
                        in);
                if (pair == null) {
                    in.nextTag();
                    break sym;
                }
                InputStream is = pair.first;
                in.nextTag();

                in.require(START_ELEMENT, null, "Format");
                String format = in.getElementText();
                in.require(END_ELEMENT, null, "Format");

                in.nextTag();
                if (in.getLocalName().equals("MarkIndex")) {
                    base.markIndex = Integer.parseInt(in.getElementText());
                }

                if (is != null) {
                    try {
                        java.awt.Font font = null;
                        if (format.equalsIgnoreCase("ttf")) {
                            font = createFont(TRUETYPE_FONT, is);
                        }
                        if (format.equalsIgnoreCase("type1")) {
                            font = createFont(TYPE1_FONT, is);
                        }

                        if (format.equalsIgnoreCase("svg")) {
                            base.shape = ShapeHelper.getShapeFromSvg(is, pair.second);
                        }

                        if (font == null && base.shape == null) {
                            LOG.warn("Mark was not loaded, because the format '{}' is not supported.", format);
                            break sym;
                        }

                        if (font != null && base.markIndex >= font.getNumGlyphs() - 1) {
                            LOG.warn("The font only contains {} glyphs, but the index given was {}.",
                                    font.getNumGlyphs(), base.markIndex);
                            break sym;
                        }

                        base.font = font;
                    } catch (FontFormatException e) {
                        LOG.debug("Stack trace:", e);
                        LOG.warn("The file was not a valid '{}' file: '{}'", format, e.getLocalizedMessage());
                    } catch (IOException e) {
                        LOG.debug("Stack trace:", e);
                        LOG.warn("The file could not be read: '{}'.", e.getLocalizedMessage());
                    } finally {
                        closeQuietly(is);
                    }
                }
            } else if (in.getLocalName().equals("Fill")) {
                final Pair<Fill, Continuation<Fill>> fill = context.fillParser.parseFill(in);
                base.fill = fill.first;
                if (fill.second != null) {
                    contn = new Continuation<Mark>(contn) {
                        @Override
                        public void updateStep(Mark base, Feature f, XPathEvaluator<Feature> evaluator) {
                            fill.second.evaluate(base.fill, f, evaluator);
                        }
                    };
                }
            } else if (in.getLocalName().equals("Stroke")) {
                final Pair<Stroke, Continuation<Stroke>> stroke = context.strokeParser.parseStroke(in);
                base.stroke = stroke.first;
                if (stroke.second != null) {
                    contn = new Continuation<Mark>(contn) {
                        @Override
                        public void updateStep(Mark base, Feature f, XPathEvaluator<Feature> evaluator) {
                            stroke.second.evaluate(base.stroke, f, evaluator);
                        }
                    };
                }
            } else if (in.isStartElement()) {
                Location loc = in.getLocation();
                LOG.error("Found unknown element '{}' at line {}, column {}, skipping.",
                        new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() });
                skipElement(in);
            }
    }

    in.require(END_ELEMENT, null, "Mark");

    return new Pair<Mark, Continuation<Mark>>(base, contn);
}

From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java

private Triple<BufferedImage, String, Continuation<List<BufferedImage>>> parseExternalGraphic(
        final XMLStreamReader in) throws IOException, XMLStreamException {
    // TODO color replacement

    in.require(START_ELEMENT, null, "ExternalGraphic");

    String format = null;//from   w w  w  .j a v  a 2 s  .  c  om
    BufferedImage img = null;
    String url = null;
    Triple<InputStream, String, Continuation<StringBuffer>> pair = null;
    Continuation<List<BufferedImage>> contn = null; // needs to be list to be updateable by reference...

    while (!(in.isEndElement() && in.getLocalName().equals("ExternalGraphic"))) {
        in.nextTag();

        if (in.getLocalName().equals("Format")) {
            format = in.getElementText();
        } else if (in.getLocalName().equals("OnlineResource") || in.getLocalName().equals("InlineContent")) {
            pair = getOnlineResourceOrInlineContent(in);
        } else if (in.isStartElement()) {
            Location loc = in.getLocation();
            LOG.error("Found unknown element '{}' at line {}, column {}, skipping.",
                    new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() });
            skipElement(in);
        }
    }

    try {
        if (pair != null) {
            if (pair.first != null && format != null && (format.toLowerCase().indexOf("svg") == -1)) {
                img = ImageIO.read(pair.first);
            }
            url = pair.second;

            final Continuation<StringBuffer> sbcontn = pair.third;

            if (pair.third != null) {
                final LinkedHashMap<String, BufferedImage> cache = new LinkedHashMap<String, BufferedImage>(
                        256) {
                    private static final long serialVersionUID = -6847956873232942891L;

                    @Override
                    protected boolean removeEldestEntry(Map.Entry<String, BufferedImage> eldest) {
                        return size() > 256; // yeah, hardcoded max size... TODO
                    }
                };
                contn = new Continuation<List<BufferedImage>>() {
                    @Override
                    public void updateStep(List<BufferedImage> base, Feature f,
                            XPathEvaluator<Feature> evaluator) {
                        StringBuffer sb = new StringBuffer();
                        sbcontn.evaluate(sb, f, evaluator);
                        String file = sb.toString();
                        if (cache.containsKey(file)) {
                            base.add(cache.get(file));
                            return;
                        }
                        try {
                            BufferedImage i;
                            if (context.location != null) {
                                i = ImageIO.read(context.location.resolve(file));
                            } else {
                                i = ImageIO.read(resolve(file, in));
                            }
                            base.add(i);
                            cache.put(file, i);
                        } catch (MalformedURLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                };
            }
        }
    } finally {
        if (pair != null) {
            try {
                pair.first.close();
            } catch (Exception e) {
                LOG.trace("Stack trace when closing input stream:", e);
            }
        }
    }

    return new Triple<BufferedImage, String, Continuation<List<BufferedImage>>>(img, url, contn);
}

From source file:org.deegree.style.se.parser.GraphicSymbologyParser.java

private Triple<InputStream, String, Continuation<StringBuffer>> getOnlineResourceOrInlineContent(
        XMLStreamReader in) throws XMLStreamException {
    if (in.getLocalName().equals("OnlineResource")) {
        String str = in.getAttributeValue(XLNNS, "href");

        if (str == null) {
            Continuation<StringBuffer> contn = context.parser.updateOrContinue(in, "OnlineResource",
                    new StringBuffer(), SBUPDATER, null).second;
            return new Triple<InputStream, String, Continuation<StringBuffer>>(null, null, contn);
        }/* w  w w .  java2  s .c om*/

        String strUrl = null;
        try {
            URL url;
            if (context.location != null) {
                url = context.location.resolveToUrl(str);
            } else {
                url = resolve(str, in);
            }
            strUrl = url.toExternalForm();
            LOG.debug("Loading from URL '{}'", url);
            in.nextTag();
            return new Triple<InputStream, String, Continuation<StringBuffer>>(url.openStream(), strUrl, null);
        } catch (IOException e) {
            LOG.debug("Stack trace:", e);
            LOG.warn("Could not retrieve content at URL '{}'.", str);
            return null;
        }
    } else if (in.getLocalName().equals("InlineContent")) {
        String format = in.getAttributeValue(null, "encoding");
        if (format.equalsIgnoreCase("base64")) {
            ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decodeBase64(in.getElementText()));
            return new Triple<InputStream, String, Continuation<StringBuffer>>(bis, null, null);
        }
        // if ( format.equalsIgnoreCase( "xml" ) ) {
        // // TODO
        // }
    } else if (in.isStartElement()) {
        Location loc = in.getLocation();
        LOG.error("Found unknown element '{}' at line {}, column {}, skipping.",
                new Object[] { in.getLocalName(), loc.getLineNumber(), loc.getColumnNumber() });
        skipElement(in);
    }

    return null;
}

From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java

private void readSyncBody(final XMLStreamReader reader) throws XMLStreamException {
    boolean continueSyncBody = true;
    do {//from w  ww .  j  av  a 2s. c o  m

        int next = reader.nextTag();
        String name = reader.getLocalName();

        switch (next) {
        case XMLEvent.START_ELEMENT:
            switch (getKey(name)) {
            case STATUS:
                readStatus(reader);
                break;
            case ADD:
                readAdd(reader, new DMMeta());
                break;
            case COPY:
                readCopy(reader);
                break;
            case DELETE:
                readDelete(reader);
                break;
            case GET:
                readGet(reader);
                break;
            case REPLACE:
                readReplace(reader, new DMMeta());
                break;
            case EXEC:
                readExec(reader, new DMMeta());
                break;
            case SEQUENCE:
                readSequence(reader);
                break;
            case ATOMIC:
                readAtomic(reader);
                break;
            case FINAL:
                readFinal(reader);
                break;
            case ALERT:
                readAlert(reader);
                break;
            default:
                break;
            }
            break;
        case XMLEvent.END_ELEMENT:
            continueSyncBody = false;
            break;
        default:
            break;
        }
    } while (continueSyncBody);
}

From source file:org.eclipse.koneki.protocols.omadm.client.basic.DMBasicSession.java

private void readGet(final XMLStreamReader reader) throws XMLStreamException {
    reader.nextTag();/* w w w  .j  a  va2  s.c  o m*/

    // CmdID
    final String cmdID = reader.getElementText();
    reader.nextTag();

    // Meta?
    if (reader.getLocalName().equals("Meta")) { //$NON-NLS-1$
        jumpToEndTag(reader, "Meta"); //$NON-NLS-1$
        reader.nextTag();
    }

    // Item+
    boolean continueGet = true;
    do {
        switch (reader.getEventType()) {
        case XMLStreamReader.START_ELEMENT:
            // Performs the get command
            final DMItem item = readItem(reader, new DMMeta());
            reader.nextTag();
            final Status status = this.commandHandler.get(item.getTargetURI());
            final DMNode results = status.getResult();
            if (results != null) {
                this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Get", item.getTargetURI(), null, //$NON-NLS-1$
                        String.valueOf(status.getCode()), results.getFormat(), results.getType(), results.getData());
            } else {
                this.statusManager.putStatus(this.currentServerMsgID, cmdID, "Get", item.getTargetURI(), null, //$NON-NLS-1$
                        String.valueOf(status.getCode()));
            }

            // Fire get event
            for (final ProtocolListener messageListener : this.protocolLinsteners) {
                messageListener.get(item.getTargetURI(), status);
            }
            break;
        case XMLStreamReader.END_ELEMENT:
            continueGet = false;
            break;
        default:
            break;
        }
    } while (continueGet);
}