Search in sources :

Example 1 with XppReader

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

the class ProtocolParser method parseReferrers.

@NotNull
public static List<PyDebugValue> parseReferrers(final String text, final PyFrameAccessor frameAccessor) throws PyDebuggerException {
    final List<PyDebugValue> values = new LinkedList<>();
    final XppReader reader = openReader(text, false);
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        if (reader.getNodeName().equals("var")) {
            PyDebugValue value = parseValue(reader, frameAccessor);
            value.setId(readString(reader, "id", null));
            values.add(value);
        } else if (reader.getNodeName().equals("for")) {
        //TODO
        } else {
            throw new PyDebuggerException("Expected <var> or <for>, found " + reader.getNodeName());
        }
        reader.moveUp();
    }
    return values;
}
Also used : XppReader(com.thoughtworks.xstream.io.xml.XppReader) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with XppReader

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

the class ProtocolParser method parseValues.

@NotNull
public static List<PyDebugValue> parseValues(final String text, final PyFrameAccessor frameAccessor) throws PyDebuggerException {
    final List<PyDebugValue> values = new LinkedList<>();
    final XppReader reader = openReader(text, false);
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        values.add(parseValue(reader, frameAccessor));
        reader.moveUp();
    }
    return values;
}
Also used : XppReader(com.thoughtworks.xstream.io.xml.XppReader) LinkedList(java.util.LinkedList) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with XppReader

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

the class ProtocolParser method parseIo.

public static PyIo parseIo(final String text) throws PyDebuggerException {
    final XppReader reader = openReader(text, true);
    reader.moveDown();
    if (!"io".equals(reader.getNodeName())) {
        throw new PyDebuggerException("Expected <io>, found " + reader.getNodeName());
    }
    final String s = readString(reader, "s", "");
    final int ctx = readInt(reader, "ctx", 1);
    return new PyIo(s, ctx);
}
Also used : XppReader(com.thoughtworks.xstream.io.xml.XppReader)

Example 4 with XppReader

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

the class ProtocolParser method parseArrayValues.

public static ArrayChunk parseArrayValues(final String text, final PyFrameAccessor frameAccessor) throws PyDebuggerException {
    final XppReader reader = openReader(text, false);
    ArrayChunkBuilder result = new ArrayChunkBuilder();
    if (reader.hasMoreChildren()) {
        reader.moveDown();
        if (!"array".equals(reader.getNodeName())) {
            throw new PyDebuggerException("Expected <array> at first node, found " + reader.getNodeName());
        }
        String slice = readString(reader, "slice", null);
        result.setSlicePresentation(slice);
        result.setRows(readInt(reader, "rows", null));
        result.setColumns(readInt(reader, "cols", null));
        result.setFormat("%" + readString(reader, "format", null));
        result.setType(readString(reader, "type", null));
        result.setMax(readString(reader, "max", null));
        result.setMin(readString(reader, "min", null));
        result.setValue(new PyDebugValue(slice, null, null, null, false, false, false, false, frameAccessor));
        reader.moveUp();
    }
    if ("headerdata".equals(reader.peekNextChild())) {
        parseArrayHeaderData(reader, result);
    }
    Object[][] data = parseArrayValues(reader, frameAccessor);
    result.setData(data);
    return result.createArrayChunk();
}
Also used : XppReader(com.thoughtworks.xstream.io.xml.XppReader)

Example 5 with XppReader

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

the class TestCswTransformProvider method testUnmarshalOtherSchema.

@Test
public void testUnmarshalOtherSchema() throws Exception {
    InputTransformer mockInputTransformer = mock(InputTransformer.class);
    when(mockInputManager.getTransformerByProperty(TransformerManager.SCHEMA, OTHER_SCHEMA)).thenReturn(mockInputTransformer);
    when(mockInputTransformer.transform(any(InputStream.class))).thenReturn(getMetacard());
    // XppReader is not namespace aware so it will read the XML and ignore the namespaces
    // WstxReader is namespace aware. It may fail for XML fragments.
    HierarchicalStreamReader reader = new XppReader(new StringReader(getRecord()), XmlPullParserFactory.newInstance().newPullParser());
    CswTransformProvider provider = new CswTransformProvider(null, mockInputManager);
    UnmarshallingContext context = new TreeUnmarshaller(null, null, null, null);
    context.put(CswConstants.TRANSFORMER_LOOKUP_KEY, TransformerManager.SCHEMA);
    context.put(CswConstants.TRANSFORMER_LOOKUP_VALUE, OTHER_SCHEMA);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    provider.unmarshal(reader, context);
    // Verify the context arguments were set correctly
    verify(mockInputManager, times(1)).getTransformerByProperty(captor.capture(), captor.capture());
    String outputSchema = captor.getValue();
    assertThat(outputSchema, is(OTHER_SCHEMA));
}
Also used : InputStream(java.io.InputStream) XppReader(com.thoughtworks.xstream.io.xml.XppReader) StringReader(java.io.StringReader) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) UnmarshallingContext(com.thoughtworks.xstream.converters.UnmarshallingContext) Matchers.anyString(org.mockito.Matchers.anyString) InputTransformer(ddf.catalog.transform.InputTransformer) TreeUnmarshaller(com.thoughtworks.xstream.core.TreeUnmarshaller) Test(org.junit.Test)

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