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);
}
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations