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

The following examples show how to use com.thoughtworks.xstream.XStream#alias() . 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 File: SerializingObject2XML.java    From maven-framework-project with MIT License 6 votes vote down vote up
@Test
public void test() {
	
	XStream xstream = new XStream();
	//XStream xstream = new XStream(new DomDriver()); // does not require XPP3 library
	//XStream xstream = new XStream(new StaxDriver()); // does not require XPP3 library starting with Java 6
	
	xstream.alias("person", Person.class);
	xstream.alias("phonenumber", PhoneNumber.class);
	
	Person joe = new Person("Joe", "Walnes");
	joe.setPhone(new PhoneNumber(123, "1234-456"));
	joe.setFax(new PhoneNumber(123, "9999-999"));
	
	String xml = xstream.toXML(joe);
	
	System.out.println(xml);
}
 
Example 2
Source File: GlossaryItemManager.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * load a list of glossaryItem from glossary.xml - File
 * 
 * @param glossaryFile
 * @return list with GlossaryItem's
 */
@SuppressWarnings("unchecked")
private ArrayList<GlossaryItem> loadGlossaryItemListFromFile(VFSLeaf glossaryFile) {
    ArrayList<GlossaryItem> glossaryItemList = new ArrayList<GlossaryItem>();
    if (glossaryFile == null) {
        return new ArrayList<GlossaryItem>();
    }
    XStream xstream = XStreamHelper.createXStreamInstance();
    xstream.alias(XML_GLOSSARY_ITEM_NAME, GlossaryItem.class);
    Object glossObj = XStreamHelper.readObject(xstream, glossaryFile.getInputStream());
    if (glossObj instanceof ArrayList) {
        ArrayList<GlossaryItem> glossItemsFromFile = (ArrayList<GlossaryItem>) glossObj;
        glossaryItemList.addAll(glossItemsFromFile);
    } else {
        log.error("The Glossary-XML-File " + glossaryFile.toString() + " seems not to be correct!", null);
    }

    Collections.sort(glossaryItemList);
    return glossaryItemList;
}
 
Example 3
Source File: AnalysisFraction.java    From ET_Redux with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param xstream
 */
public void customizeXstream(XStream xstream) {

    xstream.registerConverter(new AnalysisFractionXMLConverter());
    xstream.registerConverter(new MineralStandardModelXMLConverter());

    xstream.registerConverter(new InitialPbModelETXMLConverter());
    xstream.registerConverter(new ValueModelXMLConverter());
    xstream.registerConverter(new MeasuredRatioModelXMLConverter());

    // alias necessary to elide fully qualified name in xml8
    xstream.alias("AnalysisFraction", AnalysisFraction.class);
    xstream.alias("MeasuredRatioModel", MeasuredRatioModel.class);
    xstream.alias("InitialPbModelET", InitialPbModelET.class);
    xstream.alias("ValueModel", ValueModel.class);

    setClassXMLSchemaURL();
}
 
Example 4
Source File: GatfTestGeneratorUtil.java    From gatf with Apache License 2.0 5 votes vote down vote up
public static String getConfigStr(GatfConfiguration configuration)
{
	XStream xstream = new XStream(new DomDriver("UTF-8"));
       XStream.setupDefaultSecurity(xstream);
       xstream.allowTypes(new Class[]{GatfConfiguration.class});
	xstream.processAnnotations(new Class[]{GatfConfiguration.class});
	xstream.alias("testPaths", String[].class);
	xstream.alias("testPath", String.class);
	xstream.alias("soapWsdlKeyPairs", String[].class);
	xstream.alias("soapWsdlKeyPair", String.class);
	xstream.alias("string", String.class);
	
	return xstream.toXML(configuration);
}
 
Example 5
Source File: Registry.java    From jease with GNU General Public License v3.0 5 votes vote down vote up
private static void init(String resource) throws Exception {
	XStream xstream = new XStream();
	xstream.alias("jease", List.class);
	xstream.alias("component", Component.class);
	Enumeration<URL> urls = Registry.class.getClassLoader().getResources(
			resource);
	while (urls.hasMoreElements()) {
		InputStream url = urls.nextElement().openStream();
		for (Component component : (List<Component>) xstream.fromXML(url)) {
			components.put(component.domain, component);
		}
		url.close();
	}
	initDomainTypes(components.keySet());
}
 
Example 6
Source File: ConfigDescriptionReader.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void registerAliases(XStream xstream) {
    xstream.alias("config-descriptions", List.class);
    xstream.alias("config-description", ConfigDescription.class);
    xstream.alias("config-description-ref", NodeAttributes.class);
    xstream.alias("parameter", ConfigDescriptionParameter.class);
    xstream.alias("parameter-group", ConfigDescriptionParameterGroup.class);
    xstream.alias("options", NodeList.class);
    xstream.alias("option", NodeValue.class);
    xstream.alias("filter", List.class);
    xstream.alias("criteria", FilterCriteria.class);
}
 
Example 7
Source File: PhysicalConstantsModel.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
@Override
protected void customizeXstream(XStream xstream) {
    xstream.registerConverter(new ValueModelXMLConverter());
    xstream.registerConverter(new PhysicalConstantsModelXMLConverter());
    xstream.registerConverter(new ValueModelReferencedXMLConverter());

    xstream.alias("PhysicalConstantsModel", PhysicalConstantsModel.class);
    xstream.alias("ValueModelReferenced", ValueModelReferenced.class);
    xstream.alias("ValueModel", ValueModel.class);

    setClassXMLSchemaURL("URI_PhysicalConstantsModelXMLSchema");
}
 
Example 8
Source File: ShardTableRuleFactoryBean.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void main(final String[] args) {
	final XStream xstream = new XStream(new DomDriver());
	xstream.alias("routers", List.class);
	xstream.alias("router", Entity.class);
	List<Entity> rules = new ArrayList<Entity>();
	final File file = new File("E:\\eclipseworkspace\\SFbestFramework\\src\\test\\resources\\spring\\routers.xml");

	rules = (List<Entity>) xstream.fromXML(file);
	System.out.println(rules);
}
 
Example 9
Source File: DefaultSchemaManager.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
protected static XStream createXStream() {
    XStream xstream = new XStream(new DomDriver("UTF-8"));
    xstream.alias("schema", PersistedSchema.class);
    xstream.alias("schemas", PersistedSchemas.class);
    xstream.addImplicitCollection(PersistedSchemas.class, "list");
    xstream.aliasField("names", PersistedSchema.class, "schemas");
    xstream.useAttributeFor(PersistedSchemas.class, "version");   
    return xstream;
}
 
Example 10
Source File: XMLBeanUtils.java    From wish-pay with Apache License 2.0 5 votes vote down vote up
/**
 * 获取XStream对象
 *
 * @param clazzMap 别名-类名映射Map
 * @return XStream对象
 */
public static XStream getXStreamObject(Map<String, Class> clazzMap) {
    XStream xstream = new XStream();
    for (Iterator it = clazzMap.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry<String, Class> m = (Map.Entry<String, Class>) it.next();
        xstream.alias(m.getKey(), m.getValue());
    }
    return xstream;
}
 
Example 11
Source File: EnviarLoteRpsResposta.java    From nfse with 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 12
Source File: MorphologicalServiceLocalImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<String> getFlexions(String partOfSpeech, String word) {
    XStream xstream = XStreamHelper.createXStreamInstance();
    File replyFile = new File(PATH_TO_MS_REPLY_XML);
    xstream.alias("msreply", FlexionReply.class);
    xstream.alias("wordform", String.class);
    Object msReply = XStreamHelper.readObject(xstream, replyFile);
    FlexionReply flexionReply = (FlexionReply) msReply;
    ArrayList<String> stemWithWordforms = flexionReply.getStem();
    return stemWithWordforms;
}
 
Example 13
Source File: DefaultDataSourceService.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public List<DriverTemplate> getDriverTemplates() {
    XStream xstream = new XStream(new DomDriver());        
    xstream.alias("driver", DriverTemplate.class);
    xstream.alias("drivers", DriverTemplates.class);
    xstream.addImplicitCollection(DriverTemplates.class, "list");
    InputStream input = getClass().getResourceAsStream("/driver-templates.xml");
    /*
    if (input == null) {
        throw new Exception("Cannot find 'driver-templates.xml' file in classpath");
    }
    */

    return ((DriverTemplates) xstream.fromXML(input)).getList();
}
 
Example 14
Source File: JavaXStreamConfig.java    From depan with Apache License 2.0 5 votes vote down vote up
@Override
public void config(XStream xstream) {
  xstream.alias("java-field", FieldElement.class);
  xstream.alias("java-interface", InterfaceElement.class);
  xstream.alias("java-method", MethodElement.class);
  xstream.alias("java-package", PackageElement.class);
  xstream.alias("java-type", TypeElement.class);
  xstream.alias("java-relation", JavaRelation.class);

  xstream.useAttributeFor(TypeElement.class, "fullyQualifiedName");
  xstream.aliasAttribute(TypeElement.class, "fullyQualifiedName", "name");
}
 
Example 15
Source File: BlogArtefactDetailsController.java    From olat with Apache License 2.0 5 votes vote down vote up
BlogArtefactDetailsController(final UserRequest ureq, final WindowControl wControl, final BlogArtefact artefact, final boolean readOnlyMode) {
    super(ureq, wControl);
    mainVC = createVelocityContainer("post");

    final EPFrontendManager ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean(EPFrontendManager.class);
    final VFSContainer artefactContainer = ePFMgr.getArtefactContainer(artefact);
    final VFSLeaf itemXml = (VFSLeaf) artefactContainer.resolve(BlogArtefact.BLOG_FILE_NAME);
    if (itemXml != null) {
        final InputStream in = itemXml.getInputStream();

        final XStream xstream = XStreamHelper.createXStreamInstance();
        xstream.alias("item", Item.class);
        final Item item = (Item) xstream.fromXML(in);
        FileUtils.closeSafely(in);

        String content = item.getContent();
        if (!StringHelper.containsNonWhitespace(content)) {
            content = item.getDescription();
        }
        String filteredText = FilterFactory.getHtmlTagAndDescapingFilter().filter(content);
        filteredText = Formatter.truncate(filteredText, 50);
        mainVC.contextPut("filteredText", filteredText);
        mainVC.contextPut("readOnlyMode", readOnlyMode);

        mainVC.contextPut("item", item);
        mainVC.contextPut("helper", new ItemHelper(""));

        // Add date component
        if (item.getDate() != null) {
            DateComponentFactory.createDateComponentWithYear("dateComp", item.getDate(), mainVC);
        }
    }

    putInitialPanel(mainVC);
}
 
Example 16
Source File: XmlSerializer.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public XmlSerializer(ClassLoader loader, Map<String, String> deserializingClassRenames) {
    this.deserializingClassRenames = deserializingClassRenames;
    xstream = new XStream() {
        @Override
        protected MapperWrapper wrapMapper(MapperWrapper next) {
            return XmlSerializer.this.wrapMapperForNormalUsage( super.wrapMapper(next) );
        }
    };

    XStream.setupDefaultSecurity(xstream);
    xstream.allowTypesByWildcard(new String[] {
           "**"
    });

    if (loader!=null) {
        xstream.setClassLoader(loader);
    }
    
    xstream.registerConverter(newCustomJavaClassConverter(), XStream.PRIORITY_NORMAL);
    
    // list as array list is default
    xstream.alias("map", Map.class, LinkedHashMap.class);
    xstream.alias("set", Set.class, LinkedHashSet.class);
    
    xstream.registerConverter(new StringKeyMapConverter(xstream.getMapper()), /* priority */ 10);
    xstream.alias("MutableMap", MutableMap.class);
    xstream.alias("MutableSet", MutableSet.class);
    xstream.alias("MutableList", MutableList.class);
    
    // Needs an explicit MutableSet converter!
    // Without it, the alias for "set" seems to interfere with the MutableSet.map field, so it gets
    // a null field on deserialization.
    xstream.registerConverter(new MutableSetConverter(xstream.getMapper()));
    
    xstream.aliasType("ImmutableList", ImmutableList.class);
    xstream.registerConverter(new ImmutableListConverter(xstream.getMapper()));
    xstream.registerConverter(new ImmutableSetConverter(xstream.getMapper()));
    xstream.registerConverter(new ImmutableMapConverter(xstream.getMapper()));

    xstream.registerConverter(new EnumCaseForgivingConverter());
    xstream.registerConverter(new Inet4AddressConverter());
    
    // See ObjectWithDefaultStringImplConverter (and its usage) for why we want to auto-detect 
    // annotations (usages of this is in the camp project, so we can't just list it statically
    // here unfortunately).
    xstream.autodetectAnnotations(true);
}
 
Example 17
Source File: RelationDisplayDocXStreamConfig.java    From depan with Apache License 2.0 4 votes vote down vote up
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(RELATION_DISPLAY_INFO_TAG, RelationDisplayDocument.class);
}
 
Example 18
Source File: EdgeMatcherDocXStreamConfig.java    From depan with Apache License 2.0 4 votes vote down vote up
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(EDGE_MATCHER_INFO_TAG, GraphEdgeMatcherDescriptor.class);
}
 
Example 19
Source File: LayoutPlanDocXStreamConfig.java    From depan with Apache License 2.0 4 votes vote down vote up
@Override
public void config(XStream xstream) {
  xstream.setMode(XStream.NO_REFERENCES);
  xstream.alias(LAYOUT_PLAN_INFO_TAG, LayoutPlanDocument.class);
}
 
Example 20
Source File: XMLToMapXstream.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void deserialize_xml_to_hashmap() {

	String xmlAsMap = "<map>\n <entry>\n <int>1</int>\n <com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n <id>1</id>\n <name>Woodlawn super club</name>\n <address>Fort Atkinson</address>\n <outer-class>\n <restaurantByKey reference=\"../../../..\"/>\n </outer-class>\n </com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n </entry>\n <entry>\n <int>2</int>\n <com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n <id>2</id>\n <name>Sammy&apos;s</name>\n <address>Fort Atkinson</address>\n <outer-class reference=\"../../../entry/com.levelup.java.xml.XMLToMapXstream_-Restaurant/outer-class\"/>\n </com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n </entry>\n <entry>\n <int>3</int>\n <com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n <id>3</id>\n <name>ColdSpring Inn</name>\n <address>Cold Spring</address>\n <outer-class reference=\"../../../entry/com.levelup.java.xml.XMLToMapXstream_-Restaurant/outer-class\"/>\n </com.levelup.java.xml.XMLToMapXstream_-Restaurant>\n </entry>\n</map>\n";

	XStream xStream = new XStream();
	xStream.alias("map", java.util.Map.class);

	@SuppressWarnings("unchecked")
	Map<Integer, Restaurant> resturantConverted = (Map<Integer, Restaurant>) xStream
			.fromXML(xmlAsMap);

	assertThat(resturantConverted, hasKey(new Integer("1")));

}