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

The following examples show how to use com.thoughtworks.xstream.XStream#ignoreUnknownElements() . 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
Source Project: CoreModule   File: XmlUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 将一个xml流转换为bean实体类
 *
 * @param type
 * @param is
 * @return
 */
@SuppressWarnings("unchecked")
public synchronized static <T> T toBean(Class<T> type, InputStream is) {
    XStream xmStream = new XStream(new DomDriver());
    // 设置可忽略为在javabean类中定义的界面属性
    xmStream.ignoreUnknownElements();
    xmStream.processAnnotations(type);
    T obj = null;
    try {
        obj = (T) xmStream.fromXML(is);
    } catch (Exception e) {
        Logger.log("===解析xml发生异常:" + e.getMessage());
    } finally {
        FileUtils.closeIO(is);
    }
    return obj;
}
 
Example 2
private <T> T getSpec(URL file) {
    try {
        XStream xstream = new XStream(new DomDriver());
        xstream.autodetectAnnotations(true);
        xstream.processAnnotations(Bit.class);
        xstream.processAnnotations(BitField.class);
        xstream.processAnnotations(Characteristic.class);
        xstream.processAnnotations(Enumeration.class);
        xstream.processAnnotations(Enumerations.class);
        xstream.processAnnotations(Field.class);
        xstream.processAnnotations(InformativeText.class);
        xstream.processAnnotations(Service.class);
        xstream.processAnnotations(Value.class);
        xstream.processAnnotations(Reserved.class);
        xstream.processAnnotations(Examples.class);
        xstream.processAnnotations(CharacteristicAccess.class);
        xstream.processAnnotations(Characteristics.class);
        xstream.processAnnotations(Properties.class);
        xstream.ignoreUnknownElements();
        xstream.setClassLoader(Characteristic.class.getClassLoader());
        return (T) xstream.fromXML(file);
    } catch (Exception e) {
        logger.error("Could not read file: " + file, e);
    }
    return null;
}
 
Example 3
public FlashCardCollection deserializeFileCards(CardFile cardFile) {
    File metaDataFile = getMetaDataFile(cardFile);

    if (metaDataFile == null || !metaDataFile.isFile())
        return null;

    try {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(metaDataFile));
        XStream xStream = new XStream();
        xStream.ignoreUnknownElements();
        return (FlashCardCollection) xStream.fromXML(bis);
    } catch (Throwable e) {
        e.printStackTrace();
    }

    return null;
}
 
Example 4
Source Project: openmeetings   File: WbConverter.java    License: Apache License 2.0 6 votes vote down vote up
public static List<?> loadWmlFile(String hash) {
	String name = OmFileHelper.getName(hash, EXTENSION_WML);
	File file = new File(OmFileHelper.getUploadWmlDir(), name);
	log.debug("filepathComplete: {}", file);

	XStream xstream = new XStream(new XppDriver());
	xstream.setMode(XStream.NO_REFERENCES);
	xstream.addPermission(NoTypePermission.NONE);
	xstream.addPermission(NullPermission.NULL);
	xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
	xstream.allowTypeHierarchy(List.class);
	xstream.allowTypeHierarchy(String.class);
	xstream.ignoreUnknownElements();
	try (InputStream is = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(is, UTF_8))) {
		return (List<?>) xstream.fromXML(reader);
	} catch (Exception err) {
		log.error("loadWmlFile", err);
	}
	return new ArrayList<>();
}
 
Example 5
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 6
Source Project: nfse   File: GerarNFSeResposta.java    License: MIT License 5 votes vote down vote up
public static GerarNFSeResposta toPojo(String xml) {
  XStream xstream = new XStream();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.autodetectAnnotations(true);
  xstream.ignoreUnknownElements();
  xstream.alias("GerarNfseResposta", GerarNFSeResposta.class);
  xstream.alias("Nfse", NFSe.class);
  GerarNFSeResposta gerarNfseResposta = (GerarNFSeResposta) xstream.fromXML(xml);
  return gerarNfseResposta;
}
 
Example 7
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 8
Source Project: nfse   File: EnviarLoteRpsResposta.java    License: MIT License 5 votes vote down vote up
public static EnviarLoteRpsResposta toPojo(String xml) {
  XStream xstream = new XStream();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.autodetectAnnotations(true);
  xstream.ignoreUnknownElements();
  xstream.alias("EnviarLoteRpsResposta", EnviarLoteRpsResposta.class);
  EnviarLoteRpsResposta enviarLoteRpsResposta = (EnviarLoteRpsResposta) xstream.fromXML(xml);
  return enviarLoteRpsResposta;
}
 
Example 9
Source Project: nfse   File: CompNFSe.java    License: MIT License 5 votes vote down vote up
public static CompNFSe toPojo(String xml) {
  XStream xstream = new XStream();
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.autodetectAnnotations(true);
  xstream.ignoreUnknownElements();
  xstream.alias("CompNfse", CompNFSe.class);
  xstream.alias("Nfse", NFSe.class);
  CompNFSe compNfse = (CompNFSe) xstream.fromXML(xml);
  return compNfse;
}
 
Example 10
Source Project: wish-pay   File: WxUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 从xml里获取对象
 *
 * @param xml
 * @param tClass
 * @return
 */
public static Object getObjectFromXML(String xml, Class tClass) {
    //将从API返回的XML数据映射到Java对象
    XStream xStreamForResponseData = new XStream();
    xStreamForResponseData.alias("xml", tClass);
    xStreamForResponseData.ignoreUnknownElements();//暂时忽略掉一些新增的字段
    return xStreamForResponseData.fromXML(xml);
}
 
Example 11
Source Project: wechat-core   File: MessageUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static <T> T xml2Message(String xml, Class<T> clazz) {
    XStream xstream = newXStreamInstance();
    //先忽略未知的元素,防止从xml转换成对象时报错
    xstream.ignoreUnknownElements();
    xstream.processAnnotations(clazz);
    return (T) xstream.fromXML(xml);
}
 
Example 12
@Override
public void registerAliases(XStream xstream) {
    xstream.alias("marketplace", Marketplace.class);
    xstream.addImplicitArray(Marketplace.class, "categories");
    xstream.alias("category", Category.class);
    xstream.addImplicitArray(Category.class, "nodes");
    xstream.alias("node", Node.class);
    xstream.aliasAttribute(Node.class, "id", "id");
    xstream.aliasAttribute(Node.class, "name", "name");

    // ignore what we do not know
    xstream.ignoreUnknownElements();
}
 
Example 13
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 14
Source Project: Digital   File: Circuit.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a proper configured XStream instance
 *
 * @return the XStream instance
 */
public static XStream getxStream() {
    XStream xStream = new XStreamValid();
    xStream.alias("attributes", ElementAttributes.class);
    xStream.alias("visualElement", VisualElement.class);
    xStream.alias("wire", Wire.class);
    xStream.alias("circuit", Circuit.class);
    xStream.alias("intFormat", IntFormat.class);
    xStream.alias("barrelShifterMode", BarrelShifterMode.class);
    xStream.alias("direction", LeftRightFormat.class);
    xStream.alias("rotation", Rotation.class);
    xStream.aliasAttribute(Rotation.class, "rotation", "rotation");
    xStream.alias("language", Language.class);
    xStream.aliasAttribute(Language.class, "name", "name");
    xStream.alias("vector", Vector.class);
    xStream.aliasAttribute(Vector.class, "x", "x");
    xStream.aliasAttribute(Vector.class, "y", "y");
    xStream.alias("value", InValue.class);
    xStream.aliasAttribute(InValue.class, "value", "v");
    xStream.aliasAttribute(InValue.class, "highZ", "z");
    xStream.addImplicitCollection(ElementAttributes.class, "attributes");
    xStream.alias("data", DataField.class);
    xStream.registerConverter(new DataFieldConverter());
    xStream.alias("testData", TestCaseDescription.class);
    xStream.alias("inverterConfig", InverterConfig.class);
    xStream.addImplicitCollection(InverterConfig.class, "inputs");
    xStream.alias("storedRoms", ROMManger.class);
    xStream.addImplicitCollection(ROMManger.class, "roms");
    xStream.alias("appType", Application.Type.class);
    xStream.ignoreUnknownElements();
    xStream.alias("shape", CustomShapeDescription.class);
    xStream.alias("pin", CustomShapeDescription.Pin.class);
    xStream.alias("circle", CustomShapeDescription.CircleHolder.class);
    xStream.alias("line", CustomShapeDescription.LineHolder.class);
    xStream.alias("poly", CustomShapeDescription.PolygonHolder.class);
    xStream.alias("text", CustomShapeDescription.TextHolder.class);
    xStream.alias("polygon", Polygon.class);
    xStream.alias("shapeType", CustomCircuitShapeType.class);
    xStream.alias("transform", TransformHolder.class);
    xStream.registerConverter(new PolygonConverter());
    return xStream;
}