Search in sources :

Example 6 with XppReader

use of com.thoughtworks.xstream.io.xml.XppReader in project ddf by codice.

the class GmlGeometryConverter method marshal.

@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    Geometry geometry = (Geometry) value;
    GMLWriter gmlWriter = new GMLWriter();
    String gmlXml = gmlWriter.write(geometry);
    // Copy the GML XML into the writer
    XmlPullParser parser = null;
    try {
        parser = XppFactory.createDefaultParser();
        new HierarchicalStreamCopier().copy(new XppReader(new StringReader(gmlXml), parser), writer);
    } catch (XmlPullParserException e) {
        LOGGER.debug(ERROR_SERIALIZING_MSG, e);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GMLWriter(com.vividsolutions.jts.io.gml2.GMLWriter) XppReader(com.thoughtworks.xstream.io.xml.XppReader) XmlPullParser(org.xmlpull.v1.XmlPullParser) StringReader(java.io.StringReader) HierarchicalStreamCopier(com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 7 with XppReader

use of com.thoughtworks.xstream.io.xml.XppReader in project ddf by codice.

the class XStreamAttributeCopier method copyXml.

/**
     * Copies the entire XML element {@code reader} is currently at into {@code writer} and returns
     * a new reader ready to read the copied element. After the call, {@code reader} will be at the
     * end of the element that was copied.
     * <p>
     * If {@code attributeMap} is provided, the attributes will be added to the copy.
     *
     * @param reader       the reader currently at the XML element you want to copy
     * @param writer       the writer that the element will be copied into
     * @param attributeMap the map of attribute names to values that will be added as attributes of
     *                     the copy, may be null
     * @return a new reader ready to read the copied element
     * @throws ConversionException if a parser to use for the new reader can't be created
     */
public static HierarchicalStreamReader copyXml(HierarchicalStreamReader reader, StringWriter writer, Map<String, String> attributeMap) {
    copyElementWithAttributes(reader, new CompactWriter(writer, new NoNameCoder()), attributeMap);
    XmlPullParser parser;
    try {
        parser = XmlPullParserFactory.newInstance().newPullParser();
    } catch (XmlPullParserException e) {
        throw new ConversionException("Unable to create XmlPullParser, cannot parse XML.", e);
    }
    try {
        // encoding will be used which will not always work
        return new XppReader(new InputStreamReader(IOUtils.toInputStream(writer.toString(), StandardCharsets.UTF_8.name())), parser);
    } catch (IOException e) {
        LOGGER.debug("Unable create reader with UTF-8 encoding, Exception {}", e);
        return new XppReader(new InputStreamReader(IOUtils.toInputStream(writer.toString())), parser);
    }
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) CompactWriter(com.thoughtworks.xstream.io.xml.CompactWriter) InputStreamReader(java.io.InputStreamReader) XppReader(com.thoughtworks.xstream.io.xml.XppReader) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) NoNameCoder(com.thoughtworks.xstream.io.naming.NoNameCoder)

Example 8 with XppReader

use of com.thoughtworks.xstream.io.xml.XppReader in project intellij-community by JetBrains.

the class OfflineViewParseUtil method parse.

public static Map<String, Set<OfflineProblemDescriptor>> parse(final String problems) {
    final TObjectIntHashMap<String> fqName2IdxMap = new TObjectIntHashMap<>();
    final Map<String, Set<OfflineProblemDescriptor>> package2Result = new THashMap<>();
    final XppReader reader = new XppReader(new StringReader(problems));
    try {
        while (reader.hasMoreChildren()) {
            //problem
            reader.moveDown();
            final OfflineProblemDescriptor descriptor = new OfflineProblemDescriptor();
            boolean added = false;
            while (reader.hasMoreChildren()) {
                reader.moveDown();
                if (SmartRefElementPointerImpl.ENTRY_POINT.equals(reader.getNodeName())) {
                    descriptor.setType(reader.getAttribute(SmartRefElementPointerImpl.TYPE_ATTR));
                    final String fqName = reader.getAttribute(SmartRefElementPointerImpl.FQNAME_ATTR);
                    descriptor.setFQName(fqName);
                    if (!fqName2IdxMap.containsKey(fqName)) {
                        fqName2IdxMap.put(fqName, 0);
                    }
                    int idx = fqName2IdxMap.get(fqName);
                    descriptor.setProblemIndex(idx);
                    fqName2IdxMap.put(fqName, idx + 1);
                }
                if (DESCRIPTION.equals(reader.getNodeName())) {
                    descriptor.setDescription(reader.getValue());
                }
                if (LINE.equals(reader.getNodeName())) {
                    descriptor.setLine(Integer.parseInt(reader.getValue()));
                }
                if (MODULE.equals(reader.getNodeName())) {
                    descriptor.setModule(reader.getValue());
                }
                if (HINTS.equals(reader.getNodeName())) {
                    while (reader.hasMoreChildren()) {
                        reader.moveDown();
                        List<String> hints = descriptor.getHints();
                        if (hints == null) {
                            hints = new ArrayList<>();
                            descriptor.setHints(hints);
                        }
                        hints.add(reader.getAttribute("value"));
                        reader.moveUp();
                    }
                }
                if (PACKAGE.equals(reader.getNodeName())) {
                    appendDescriptor(package2Result, reader.getValue(), descriptor);
                    added = true;
                }
                while (reader.hasMoreChildren()) {
                    reader.moveDown();
                    if (PACKAGE.equals(reader.getNodeName())) {
                        appendDescriptor(package2Result, reader.getValue(), descriptor);
                        added = true;
                    }
                    reader.moveUp();
                }
                reader.moveUp();
            }
            if (!added)
                appendDescriptor(package2Result, "", descriptor);
            reader.moveUp();
        }
    } finally {
        reader.close();
    }
    return package2Result;
}
Also used : Set(java.util.Set) THashSet(gnu.trove.THashSet) OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) THashMap(gnu.trove.THashMap) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) XppReader(com.thoughtworks.xstream.io.xml.XppReader) StringReader(java.io.StringReader)

Example 9 with XppReader

use of com.thoughtworks.xstream.io.xml.XppReader in project intellij-community by JetBrains.

the class ProtocolParser method parseCallSignature.

public static PySignature parseCallSignature(String payload) throws PyDebuggerException {
    final XppReader reader = openReader(payload, true);
    reader.moveDown();
    if (!"call_signature".equals(reader.getNodeName())) {
        throw new PyDebuggerException("Expected <call_signature>, found " + reader.getNodeName());
    }
    final String file = readString(reader, "file", "");
    final String name = readString(reader, "name", "");
    PySignature signature = new PySignature(file, name);
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        if ("arg".equals(reader.getNodeName())) {
            signature.addArgument(readString(reader, "name", ""), readString(reader, "type", ""));
        } else if ("return".equals(reader.getNodeName())) {
            signature.addReturnType(readString(reader, "type", ""));
        } else {
            throw new PyDebuggerException("Expected <arg> or <return>, found " + reader.getNodeName());
        }
        reader.moveUp();
    }
    return signature;
}
Also used : XppReader(com.thoughtworks.xstream.io.xml.XppReader)

Example 10 with XppReader

use of com.thoughtworks.xstream.io.xml.XppReader in project intellij-community by JetBrains.

the class ProtocolParser method parseValue.

@NotNull
public static PyDebugValue parseValue(final String text, final PyFrameAccessor frameAccessor) throws PyDebuggerException {
    final XppReader reader = openReader(text, true);
    reader.moveDown();
    return parseValue(reader, frameAccessor);
}
Also used : XppReader(com.thoughtworks.xstream.io.xml.XppReader) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XppReader (com.thoughtworks.xstream.io.xml.XppReader)19 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)6 InputStreamReader (java.io.InputStreamReader)6 InputStream (java.io.InputStream)5 StringReader (java.io.StringReader)5 Test (org.junit.Test)5 UnmarshallingContext (com.thoughtworks.xstream.converters.UnmarshallingContext)4 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 NotNull (org.jetbrains.annotations.NotNull)4 Matchers.anyString (org.mockito.Matchers.anyString)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)4 TreeUnmarshaller (com.thoughtworks.xstream.core.TreeUnmarshaller)3 HierarchicalStreamCopier (com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier)3 InputTransformer (ddf.catalog.transform.InputTransformer)3 XmlPullParser (org.xmlpull.v1.XmlPullParser)3 XStream (com.thoughtworks.xstream.XStream)2 ConversionException (com.thoughtworks.xstream.converters.ConversionException)2 Metacard (ddf.catalog.data.Metacard)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2