當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。