当前位置: 首页>>代码示例>>Java>>正文


Java XStream.omitField方法代码示例

本文整理汇总了Java中com.thoughtworks.xstream.XStream.omitField方法的典型用法代码示例。如果您正苦于以下问题:Java XStream.omitField方法的具体用法?Java XStream.omitField怎么用?Java XStream.omitField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.thoughtworks.xstream.XStream的用法示例。


在下文中一共展示了XStream.omitField方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: replyToXml

import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
/**
 * 将回复消息对象转换成xml字符串
 *
 * @param reply 回复消息对象
 * @return 返回符合微信接口的xml字符串
 */
public String replyToXml(WeChatReply reply) {
    XStream xstream = new XStream(new XppDriver() {
        public HierarchicalStreamWriter createWriter(Writer out) {
            return new PrettyPrintWriter(out) {
                // 对所有xml节点的转换都增加CDATA标记
                boolean cdata = true;

                @SuppressWarnings("unchecked")
                public void startNode(String name, Class clazz) {
                    super.startNode(name, clazz);
                }

                protected void writeText(QuickWriter writer, String text) {
                    if (cdata) {
                        writer.write("<![CDATA[");
                        writer.write(text);
                        writer.write("]]>");
                    } else {
                        writer.write(text);
                    }
                }
            };
        }
    });
    String type = reply.getMsgType();
    if (WeChatReply.TEXT.equals(type)) {
        xstream.omitField(WeChatReply.class, "articles");
        xstream.omitField(WeChatReply.class, "articleCount");
        xstream.omitField(WeChatReply.class, "musicUrl");
        xstream.omitField(WeChatReply.class, "hQMusicUrl");
    } else if (WeChatReply.MUSIC.equals(type)) {
        xstream.omitField(WeChatReply.class, "articles");
        xstream.omitField(WeChatReply.class, "articleCount");
        xstream.omitField(WeChatReply.class, "content");
    } else if (WeChatReply.NEWS.equals(type)) {
        xstream.omitField(WeChatReply.class, "content");
        xstream.omitField(WeChatReply.class, "musicUrl");
        xstream.omitField(WeChatReply.class, "hQMusicUrl");
    }
    xstream.autodetectAnnotations(true);
    xstream.alias("xml", reply.getClass());
    xstream.alias("item", new Article().getClass());
    return xstream.toXML(reply);
}
 
开发者ID:NeilRen,项目名称:NEILREN4J,代码行数:51,代码来源:WeChatService.java

示例2: omitFields

import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
private static void omitFields(HashMap<Class, HashSet<String>> fieldMap, XStream xstream) {
	Iterator<Class> it = fieldMap.keySet().iterator();
	while (it.hasNext()) {
		Class vo = it.next();
		Iterator<String> fieldNamesIt = fieldMap.get(vo).iterator();
		while (fieldNamesIt.hasNext()) {
			xstream.omitField(vo, fieldNamesIt.next());
		}
	}
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:11,代码来源:OmittedFields.java

示例3: toXml

import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
public static String toXml(Assembly assembly) {
    if (assembly == null) {
        return null;
    }
    XStream xstream = new XStream();
    xstream.alias("assembly", Assembly.class);
    xstream.omitField(Assembly.class,"modelEncoding");

    xstream.alias("file", FileItem.class);
    xstream.alias("fileSet", FileSet.class);
    xstream.alias("containerDescriptorHandler", ContainerDescriptorHandlerConfig.class);
    xstream.alias("moduleSet", ModuleSet.class);
    xstream.alias("sources", ModuleSources.class);
    xstream.alias("binaries", ModuleBinaries.class);
    xstream.alias("dependencySet", DependencySet.class);
    xstream.alias("unpackOptions", UnpackOptions.class);
    xstream.alias("repository", Repository.class);
    xstream.alias("groupVersionAlignment", GroupVersionAlignment.class);

    registerIncludeExcludeAliases(
        xstream,
        DependencySet.class,
        ModuleSources.class,
        ModuleSet.class,
        FileSet.class,
        ModuleBinaries.class,
        UnpackOptions.class,
        Repository.class);

    registerStringAlias(xstream, Assembly.class, "componentDescriptor");
    registerStringAlias(xstream, GroupVersionAlignment.class, "exclude");
    registerStringAlias(xstream, Repository.class, "groupVersionAlignment");

    return xstream.toXML(assembly);
}
 
开发者ID:fabric8io,项目名称:fabric8-build,代码行数:36,代码来源:AssemblyPrinter.java

示例4: initXStream

import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
protected void initXStream() {

        _xStream = new XStream(null, new XppDriver(), new ClassLoaderReference(
                XStreamConfiguratorRegistryUtil.getConfiguratorsClassLoader(XStream.class.getClassLoader())));

        _xStream.omitField(HashMap.class, "cache_bitmask");

        Set<XStreamConfigurator> xStreamConfigurators = XStreamConfiguratorRegistryUtil.getXStreamConfigurators();

        if (SetUtil.isEmpty(xStreamConfigurators)) {
            return;
        }

        List<String> allowedTypeNames = new ArrayList<>();

        for (XStreamConfigurator xStreamConfigurator : xStreamConfigurators) {
            List<XStreamAlias> xStreamAliases = xStreamConfigurator.getXStreamAliases();

            if (ListUtil.isNotEmpty(xStreamAliases)) {
                for (XStreamAlias xStreamAlias : xStreamAliases) {
                    _xStream.alias(xStreamAlias.getName(), xStreamAlias.getClazz());
                }
            }

            List<XStreamConverter> xStreamConverters = xStreamConfigurator.getXStreamConverters();

            if (ListUtil.isNotEmpty(xStreamConverters)) {
                for (XStreamConverter xStreamConverter : xStreamConverters) {
                    _xStream.registerConverter(new ConverterAdapter(xStreamConverter), XStream.PRIORITY_VERY_HIGH);
                }
            }

            List<XStreamType> xStreamTypes = xStreamConfigurator.getAllowedXStreamTypes();

            if (ListUtil.isNotEmpty(xStreamTypes)) {
                for (XStreamType xStreamType : xStreamTypes) {
                    allowedTypeNames.add(xStreamType.getTypeExpression());
                }
            }
        }

        // For default permissions, first wipe than add default

        _xStream.addPermission(NoTypePermission.NONE);

        // Add permissions

        _xStream.addPermission(PrimitiveTypePermission.PRIMITIVES);
        _xStream.addPermission(XStreamStagedModelTypeHierarchyPermission.STAGED_MODELS);

        _xStream.allowTypes(_XSTREAM_DEFAULT_ALLOWED_TYPES);

        _xStream.allowTypeHierarchy(List.class);
        _xStream.allowTypeHierarchy(Map.class);
        _xStream.allowTypeHierarchy(Timestamp.class);
        _xStream.allowTypeHierarchy(Set.class);

        _xStream.allowTypes(allowedTypeNames.toArray(new String[0]));

        _xStream.allowTypesByWildcard(new String[] { "com.thoughtworks.xstream.mapper.DynamicProxyMapper*" });
    }
 
开发者ID:inofix,项目名称:ch-inofix-timetracker,代码行数:62,代码来源:BaseExportImportController.java

示例5: exportNode

import com.thoughtworks.xstream.XStream; //导入方法依赖的package包/类
/**
    * The proper method for exporting nodes.
    *
    * @param nodeUid
    * @return
    * @throws ZipFileUtilException
    * @throws FileUtilException
    * @throws IOException
    * @throws RepositoryCheckedException
    * @throws ExportToolContentException
    */
   private String exportNode(Long nodeUid) throws ZipFileUtilException, FileUtilException, IOException,
    RepositoryCheckedException, ExportToolContentException {
if (nodeUid != null) {

    String rootDir = FileUtil.createTempDirectory(PedagogicalPlannerAction.EXPORT_NODE_FOLDER_SUFFIX);
    String contentDir = FileUtil.getFullPath(rootDir, PedagogicalPlannerAction.DIR_CONTENT);
    FileUtil.createDirectory(contentDir);

    String nodeFileName = FileUtil.getFullPath(contentDir, PedagogicalPlannerAction.NODE_FILE_NAME);
    Writer nodeFile = new OutputStreamWriter(new FileOutputStream(nodeFileName),
	    PedagogicalPlannerAction.ENCODING_UTF_8);

    PedagogicalPlannerSequenceNode node = getPedagogicalPlannerDAO().getByUid(nodeUid);
    // exporting XML
    XStream designXml = new XStream(new SunUnsafeReflectionProvider());
    designXml.addPermission(AnyTypePermission.ANY);
    // do not serialize node's owner
    designXml.omitField(PedagogicalPlannerSequenceNode.class, "user");
    designXml.toXML(node, nodeFile);
    nodeFile.close();

    PedagogicalPlannerAction.log.debug("Node xml export success");

    // Copy templates' ZIP files from repository
    File templateDir = new File(contentDir, PedagogicalPlannerAction.DIR_TEMPLATES);
    exportSubnodeTemplates(node, templateDir);

    // create zip file for fckeditor unique content folder
    String targetZipFileName = PedagogicalPlannerAction.EXPORT_NODE_CONTENT_ZIP_PREFIX
	    + node.getContentFolderId() + PedagogicalPlannerAction.FILE_EXTENSION_ZIP;
    String secureDir = Configuration.get(ConfigurationKeys.LAMS_EAR_DIR) + File.separator
	    + FileUtil.LAMS_WWW_DIR + File.separator + FileUtil.LAMS_WWW_SECURE_DIR;
    String nodeContentDir = FileUtil.getFullPath(secureDir, node.getContentFolderId());

    if (!FileUtil.isEmptyDirectory(nodeContentDir, true)) {
	PedagogicalPlannerAction.log
		.debug("Create export node content target zip file. File name is " + targetZipFileName);
	ZipFileUtil.createZipFile(targetZipFileName, nodeContentDir, contentDir);
    } else {
	PedagogicalPlannerAction.log.debug("No such directory (or empty directory): " + nodeContentDir);
    }

    // zip file name with full path
    targetZipFileName = PedagogicalPlannerAction.EXPORT_NODE_ZIP_PREFIX + node.getTitle()
	    + PedagogicalPlannerAction.FILE_EXTENSION_ZIP;
    ;
    PedagogicalPlannerAction.log
	    .debug("Create export node content zip file. File name is " + targetZipFileName);
    // create zip file and return zip full file name
    return ZipFileUtil.createZipFile(targetZipFileName, contentDir, rootDir);
}
return null;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:65,代码来源:PedagogicalPlannerAction.java


注:本文中的com.thoughtworks.xstream.XStream.omitField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。