Java Code Examples for com.thoughtworks.xstream.XStream#setMode()

The following examples show how to use com.thoughtworks.xstream.XStream#setMode() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
   public Collection<Object> query() {
	try {
		if (new File(filename).exists()) {
			XStream xstream = new XStream(new DomDriver());
			xstream.setMode(XStream.ID_REFERENCES);
			FileReader reader = new FileReader(filename);
			Object r = xstream.fromXML(reader);
			clearObjects();
			if (r instanceof Collection) {
			    @SuppressWarnings("unchecked")
                   Collection<Object> c = (Collection<Object>) r;
			    objects.addAll(c);
			} else {
			    objects.add(r);
			}
			reader.close();
		}
		return objects;
	} catch (Exception e) {
		throw new RuntimeException(e.getMessage(), e);
	}
}
 
Example 2
Source Project: depan   File: ViewDocXStreamConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);

  xstream.alias(VIEW_PREFS, ViewPreferences.class);

  converter = ViewDocumentConverter.configXStream(xstream);
  EdgeReferenceConverter.configXStream(xstream, converter);
  NodeReferenceConverter.configXStream(xstream, converter);

  CameraPosConverter.configXStream(xstream);
  CameraDirConverter.configXStream(xstream);
  GraphModelReferenceConverter.configXStream(xstream);
  Point2DConverter.configXStream(xstream);
  ViewExtensionConverter.configXStream(xstream);
}
 
Example 3
public static XStream getInstance() {
  XStream xstream = new XStream(new PureJavaReflectionProvider(), new XppDriver() {

    @Override
    public HierarchicalStreamWriter createWriter(Writer out) {
      return new PrettyPrintWriter(out, getNameCoder()) {
        protected String PREFIX_CDATA = "<![CDATA[";
        protected String SUFFIX_CDATA = "]]>";
        protected String PREFIX_MEDIA_ID = "<MediaId>";
        protected String SUFFIX_MEDIA_ID = "</MediaId>";

        @Override
        protected void writeText(QuickWriter writer, String text) {
          if (text.startsWith(this.PREFIX_CDATA) && text.endsWith(this.SUFFIX_CDATA)) {
            writer.write(text);
          } else if (text.startsWith(this.PREFIX_MEDIA_ID) && text.endsWith(this.SUFFIX_MEDIA_ID)) {
            writer.write(text);
          } else {
            super.writeText(writer, text);
          }

        }

        @Override
        public String encodeNode(String name) {
          //防止将_转换成__
          return name;
        }
      };
    }
  });

  xstream.ignoreUnknownElements();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.addPermission(NullPermission.NULL);
  xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
  xstream.setClassLoader(Thread.currentThread().getContextClassLoader());
  return xstream;
}
 
Example 4
public static XStream getInstance() {
  XStream xstream = new XStream(new XppDriver() {

    @Override
    public HierarchicalStreamWriter createWriter(Writer out) {
      return new PrettyPrintWriter(out, getNameCoder()) {
        protected String PREFIX_CDATA = "<![CDATA[";
        protected String SUFFIX_CDATA = "]]>";
        protected String PREFIX_MEDIA_ID = "<MediaId>";
        protected String SUFFIX_MEDIA_ID = "</MediaId>";
        @Override
        protected void writeText(QuickWriter writer, String text) {
          if (text.startsWith(PREFIX_CDATA) && text.endsWith(SUFFIX_CDATA)) {
            writer.write(text);
          } else if (text.startsWith(PREFIX_MEDIA_ID) && text.endsWith(SUFFIX_MEDIA_ID)) {
            writer.write(text);
          } else {
            super.writeText(writer, text);
          }

        }
      };
    }
  });
  xstream.ignoreUnknownElements();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.addPermission(NullPermission.NULL);
  xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
  return xstream;
}
 
Example 5
Source Project: depan   File: GraphDocXStreamConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(GRAPH_INFO_TAG, GraphDocument.class);

  GraphModelConverter.configXStream(xstream);
  EdgeConverter.configXStream(xstream);
}
 
Example 6
Source Project: nfse   File: ConsultarLoteRpsResposta.java    License: MIT License 5 votes vote down vote up
public static ConsultarLoteRpsResposta toPojo(String xml) {
  XStream xstream = new XStream();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.autodetectAnnotations(true);
  xstream.ignoreUnknownElements();
  xstream.alias("ConsultarLoteRpsResposta", ConsultarLoteRpsResposta.class);
  xstream.alias("Nfse", Nfse.class);
  ConsultarLoteRpsResposta gerarNfseResposta = (ConsultarLoteRpsResposta) xstream.fromXML(xml);
  return gerarNfseResposta;
}
 
Example 7
public static String serialise(ProjectSlackNotificationsBean project){
	XStream xstream = new XStream(new JsonHierarchicalStreamDriver());
       xstream.setMode(XStream.NO_REFERENCES);
       xstream.alias("projectSlacknotificationConfig", ProjectSlackNotificationsBean.class);
       /* For some reason, the items are coming back as "@name" and "@value"
        * so strip those out with a regex.
        */
	return xstream.toXML(project);
}
 
Example 8
public static String toXML(Object obj, boolean excludeEncryptedFields) throws Exception {
	XStream xstream = new XStream();
	if (excludeEncryptedFields) {
		OmittedFields.omitFields(xstream);
	}
	xstream.setMode(XStream.ID_REFERENCES);
	return xstream.toXML(obj);
}
 
Example 9
private static void assertXmlOutputEqual(Object actual, Object expected) {
    XStream xStream = new XStream();
    xStream.setMode(XStream.NO_REFERENCES);
    xStream.aliasSystemAttribute(null, "class"); // we only care about the content (but not internal attributes)
    xStream.aliasSystemAttribute(null, "resolves-to");
    String actualXml = xStream.toXML(actual);
    String expectedXml = xStream.toXML(expected);

    Truth.assertThat(actualXml).isEqualTo(expectedXml);
}
 
Example 10
Source Project: jease   File: XStreamFile.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reads collection from XML-File.
 */
public Collection<Object> read() {
	try {
		XStream xstream = new XStream(new DomDriver());
		xstream.setMode(XStream.ID_REFERENCES);
		FileReader reader = new FileReader(filename);
		List<Object> objects = (List<Object>) xstream.fromXML(reader);
		reader.close();
		return objects;
	} catch (IOException e) {
		throw new RuntimeException(e.getMessage(), e);
	}
}
 
Example 11
public static SuccessResponse successFromXML (final String xml) {
    XStream xStreamInstance = new XStream();
    xStreamInstance.setMode(XStream.NO_REFERENCES);
    xStreamInstance.autodetectAnnotations(false);
    xStreamInstance.alias("response", SuccessResponse.class);
    xStreamInstance.alias("row", Row.class);
    xStreamInstance.alias("cells", HashMap.class);
    xStreamInstance.alias("roi", Integer.class);
    xStreamInstance.registerConverter(new AmforeasMapConverter());
    xStreamInstance.addImplicitCollection(SuccessResponse.class, "rows", Row.class);
    return (SuccessResponse) xStreamInstance.fromXML(xml);
}
 
Example 12
public XStreamDashboardPersister() {
	this.file = getUserDashboard(getUserId());

	xstream = new XStream(new DomDriver(UTF_8.name()));
	xstream.setMode(XStream.NO_REFERENCES);
	xstream.addPermission(NoTypePermission.NONE);
	xstream.addPermission(NullPermission.NULL);
	xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
	xstream.allowTypesByWildcard(new String[] {"org.apache.openmeetings.web.**"});
	xstream.allowTypeHierarchy(ArrayList.class);
	xstream.alias("dashboard", UserDashboard.class);
}
 
Example 13
public static ErrorResponse errorFromXML (final String xml) {
    XStream xStreamInstance = new XStream();
    xStreamInstance.setMode(XStream.NO_REFERENCES);
    xStreamInstance.autodetectAnnotations(false);
    xStreamInstance.alias("response", ErrorResponse.class);
    return (ErrorResponse) xStreamInstance.fromXML(xml);
}
 
Example 14
Source Project: depan   File: RemapTaskDocXStreamConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(REMAP_INFO_TAG, MigrationTask.class);
}
 
Example 15
public static XStream createXStream() {
	XStream xstream = new XStream(new DomDriver("UTF-8"));
	xstream.setMode(XStream.NO_REFERENCES);
	xstream.alias("favorite", FavoriteEntry.class);
	return xstream;
}
 
Example 16
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(RELATION_DISPLAY_INFO_TAG, RelationDisplayDocument.class);
}
 
Example 17
Source Project: depan   File: NodeKindDocXStreamConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(NODE_KIND_INFO_TAG, NodeKindDocument.class);
}
 
Example 18
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(
      CONTEXTUAL_FILTER_DOCUMENT_INFO_TAG, ContextualFilterDocument.class);
}
 
Example 19
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(EDGE_DISPLAY_INFO_TAG, EdgeDisplayDocument.class);
}
 
Example 20
/**
 * Get configured xstream object.
 * @return {@link XStream}
 */
private XStream getXStream() {

    final XStream xStream = new XStream(new DomDriver());
    xStream.addPermission(AnyTypePermission.ANY);
    xStream.setMode(XStream.NO_REFERENCES);

    return xStream;

}