List of usage examples for org.jdom2 CDATA CDATA
public CDATA(final String string)
CDATA
node, with the supplied string value as its character content. From source file:ac.simons.syndication.utils.SyndicationContent.java
License:BSD License
public Element toElement() { final Element element = new Element("encoded", Namespace.getNamespace("content", "http://purl.org/rss/1.0/modules/content/")); element.addContent(new CDATA(content.getValue())); return element; }
From source file:ac.simons.syndication.utils.SyndicationDescription.java
License:BSD License
public Element toElement() { final Element element = new Element("description"); element.addContent(new CDATA(description.getValue())); return element; }
From source file:com.collir24.policyextractor.Extract.java
License:Apache License
private static Document buildDocument(List<ModulePermissions> modulePermissions) { Element modulePolicy = new Element("modulePolicy"); for (ModulePermissions mps : modulePermissions) { Element module = new Element("module"); module.setAttribute("name", mps.getModuleName()); Set<String> policySet = new HashSet<String>(); for (ModulePermission mp : mps.getPermissions()) { Element permRequired = new Element("permRequired"); permRequired.setAttribute("line", Integer.toString(mp.getLine())); permRequired.setAttribute("className", mp.getClassName()); for (String s : mp.getPolicy()) { Element perm = new Element("perm"); perm.setText(s);/*from ww w. jav a 2s .com*/ permRequired.addContent(perm); } module.addContent(permRequired); // TODO: say what caused the permission to be required - see key policySet.addAll(mp.getPolicy()); } CDATA policyData = new CDATA(generatePolicy(policySet)); module.addContent(policyData); modulePolicy.addContent(module); } return new Document(modulePolicy); }
From source file:com.rometools.modules.content.io.ContentModuleGenerator.java
License:Open Source License
protected Element generateCDATAElement(final String name, final String value) { final Element element = new Element(name, CONTENT_NS); final CDATA cdata = new CDATA(value); element.addContent(cdata);// w ww . jav a 2s .com return element; }
From source file:com.soulgalore.web.pagesavings.reporters.XMLReporter.java
License:Apache License
public void report(Set<SiteResult> results, Map<String, DescriptiveStatistics> statistics) { Date reportDate = new Date(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); Element root = new Element("savings"); root.setAttribute("date", "" + reportDate); Element resultsXML = new Element("results"); root.addContent(resultsXML);/*from ww w .j av a 2 s. com*/ Double totalPw = 0D; Double totalUnique = 0D; for (SiteResult siteResult : results) { totalPw += siteResult.getTotalSavings() * siteResult.getSite().getPageViews(); totalUnique += siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers(); Element site = new Element("site"); Element url = new Element("url"); Element weight = new Element("total-page-weight"); Element savingsPerPage = new Element("savings-per-page"); Element savingsForPW = new Element("savings-for-page-view"); Element savingsForUnique = new Element("savings-for-unique-browsers"); Element savingsPercentage = new Element("savings-percentage"); url.addContent(new CDATA(siteResult.getSite().getUrl())); savingsPerPage.setAttribute(READABLE, humanReadableByteCount(Math.round(siteResult.getTotalSavings()), true)); savingsPerPage.setAttribute(KB, "" + Math.round(siteResult.getTotalSavings())); savingsForPW.setAttribute(READABLE, humanReadableByteCount( Math.round(siteResult.getTotalSavings() * siteResult.getSite().getPageViews()), true)); savingsForPW.setAttribute(KB, "" + Math.round(siteResult.getTotalSavings() * siteResult.getSite().getPageViews())); savingsForUnique.setAttribute(READABLE, humanReadableByteCount( Math.round(siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers()), true)); savingsForUnique.setAttribute(KB, "" + Math.round(siteResult.getTotalSavings() * siteResult.getSite().getUniqueBrowsers())); savingsPercentage.addContent("" + Math.round(siteResult.getSavingsPercentage() * 100) / 100.0d); weight.setAttribute(READABLE, humanReadableByteCount(siteResult.getTotalSizeBytes() / 1000, true)); weight.setAttribute(KB, "" + siteResult.getTotalSizeBytes() / 1000); Element rulesSavings = new Element("rule-savings"); for (RuleResult ruleResult : siteResult.getResults()) { Element rule = new Element(ruleResult.getRule()); rule.addContent("" + ruleResult.getSavings()); rulesSavings.addContent(rule); } site.addContent(url); site.addContent(weight); site.addContent(savingsPerPage); site.addContent(savingsForPW); site.addContent(savingsForUnique); site.addContent(savingsPercentage); site.addContent(rulesSavings); resultsXML.addContent(site); } Element summary = new Element("summary"); summary.setAttribute("nrofsites", "" + results.size()); Element totalPW = new Element("total-pw"); Element totalUniqueSummary = new Element("total-unique"); totalPW.setAttribute(READABLE, humanReadableByteCount(Math.round(totalPw), true)); totalPW.setAttribute(KB, "" + Math.round(totalPw)); totalUniqueSummary.setAttribute(READABLE, humanReadableByteCount(Math.round(totalUnique), true)); totalUniqueSummary.setAttribute(KB, "" + Math.round(totalUnique)); summary.addContent(totalPW); summary.addContent(totalUniqueSummary); for (String rule : statistics.keySet()) { DescriptiveStatistics stats = statistics.get(rule); Element ruleElement = new Element(rule); Element max = new Element("max"); Element median = new Element("median"); max.addContent("" + stats.getMax()); median.addContent("" + stats.getPercentile(50)); ruleElement.addContent(max); ruleElement.addContent(median); summary.addContent(ruleElement); } resultsXML.addContent(summary); Document doc = new Document(root); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try { FileWriter writer = new FileWriter("report-" + df.format(reportDate) + ".xml"); outputter.output(doc, writer); } catch (Exception e) { } }
From source file:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelCreator.java
License:Apache License
/** * Create the entry for a specific space controller. * * @param controller//w w w. j a v a 2s .c o m * the controller to write * * @return the element for the controller */ private Element newSpaceControllerEntry(SpaceController controller) { Element controllerElement = new Element(ELEMENT_NAME_INDIVIDUAL_SPACE_CONTROLLER); controllerElement.setAttribute(ATTRIBUTE_NAME_ID, controller.getId()) .addContent(new Element(ELEMENT_NAME_NAME).addContent(controller.getName())) .addContent( new Element(ELEMENT_NAME_DESCRIPTION).addContent(new CDATA(controller.getDescription()))) .addContent(new Element(ELEMENT_NAME_SPACE_CONTROLLER_HOST_ID).addContent(controller.getHostId())) .addContent( new Element(ELEMENT_NAME_SPACE_CONTROLLER_HOST_NAME).addContent(controller.getHostName())) .addContent(new Element(ELEMENT_NAME_SPACE_CONTROLLER_HOST_CONTROL_PORT) .addContent(Integer.toString(controller.getHostControlPort()))) .addContent(new Element(ELEMENT_NAME_UUID).addContent(controller.getUuid())) .addContent(newMetadataElement(controller.getMetadata())); SpaceControllerMode mode = controller.getMode(); if (mode != null) { controllerElement.addContent(new Element(ELEMENT_NAME_SPACE_CONTROLLER_MODE).addContent(mode.name())); } addSpaceControllerConfiguration(controllerElement, controller.getConfiguration()); return controllerElement; }
From source file:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelCreator.java
License:Apache License
/** * Add a space controller configuration to the given element if there is a * configuration./*w w w . jav a 2 s . c om*/ * * @param element * the XML element to add the configuration onto * @param configuration * the possible configuration (can be {@code null}) */ private void addSpaceControllerConfiguration(Element element, SpaceControllerConfiguration configuration) { if (configuration != null) { Element configurationElement = new Element(ELEMENT_NAME_SPACE_CONTROLLER_CONFIGURATION); element.addContent(configurationElement); Set<ConfigurationParameter> parameters = configuration.getParameters(); if (!parameters.isEmpty()) { Element parametersElement = new Element( ELEMENT_NAME_SPACE_CONTROLLER_CONFIGURATION_ROOT_PARAMETERS); configurationElement.addContent(parametersElement); for (ConfigurationParameter parameter : parameters) { Element parameterElement = new Element( ELEMENT_NAME_SPACE_CONTROLLER_CONFIGURATION_INDIVIDUAL_PARAMETER); parametersElement.addContent(parameterElement); parameterElement.setAttribute(ATTRIBUTE_NAME_SPACE_CONTROLLER_CONFIGURATION_PARAMETER_NAME, parameter.getName()).addContent(new CDATA(parameter.getValue())); } } } }
From source file:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelCreator.java
License:Apache License
/** * Create the entry for a specific activity. * * @param activity/*w w w.j av a 2 s. c o m*/ * the activity to write * * @return the element for the activity */ private Element newActivityEntry(Activity activity) { Element activityElement = new Element(ELEMENT_NAME_INDIVIDUAL_ACTIVITY); activityElement.setAttribute(ATTRIBUTE_NAME_ID, activity.getId()) .addContent(new Element(ELEMENT_NAME_ACTIVITY_IDENTIFYING_NAME) .addContent(activity.getIdentifyingName())) .addContent(new Element(ELEMENT_NAME_ACTIVITY_VERSION).addContent(activity.getVersion())) .addContent(new Element(ELEMENT_NAME_NAME).addContent(activity.getName())) .addContent(new Element(ELEMENT_NAME_DESCRIPTION).addContent(new CDATA(activity.getDescription()))) .addContent(newMetadataElement(activity.getMetadata())); Date lastUploadDate = activity.getLastUploadDate(); if (lastUploadDate != null) { activityElement.setAttribute(ATTRIBUTE_NAME_LAST_UPLOAD_DATE, Long.toString(lastUploadDate.getTime())); } Date lastStartDate = activity.getLastStartDate(); if (lastStartDate != null) { activityElement.setAttribute(ATTRIBUTE_NAME_LAST_START_DATE, Long.toString(lastStartDate.getTime())); } String bundleContentHash = activity.getBundleContentHash(); if (bundleContentHash != null) { activityElement.addContent( new Element(ELEMENT_NAME_ACTIVITY_BUNDLE_CONTENT_HASH).addContent(bundleContentHash)); } addActivityDependencies(activity, activityElement); return activityElement; }
From source file:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelCreator.java
License:Apache License
/** * Create the entry for a specific live activity. * * @param liveActivity// ww w . ja v a 2s .com * the live activity to write * * @return the element for the activity */ private Element newLiveActivityEntry(LiveActivity liveActivity) { Element liveActivityElement = new Element(ELEMENT_NAME_INDIVIDUAL_LIVE_ACTIVITY); liveActivityElement.setAttribute(ATTRIBUTE_NAME_ID, liveActivity.getId()) .addContent(new Element(ELEMENT_NAME_UUID).addContent(liveActivity.getUuid())) .addContent(new Element(ELEMENT_NAME_NAME).addContent(liveActivity.getName())) .addContent( new Element(ELEMENT_NAME_DESCRIPTION).addContent(new CDATA(liveActivity.getDescription()))) .addContent(new Element(ELEMENT_NAME_LIVE_ACTIVITY_CONTROLLER).setAttribute(ATTRIBUTE_NAME_ID, liveActivity.getController().getId())) .addContent(new Element(ELEMENT_NAME_LIVE_ACTIVITY_ACTIVITY).setAttribute(ATTRIBUTE_NAME_ID, liveActivity.getActivity().getId())) .addContent(newMetadataElement(liveActivity.getMetadata())); addActivityConfiguration(liveActivityElement, liveActivity.getConfiguration()); Date lastDeployDate = liveActivity.getLastDeployDate(); if (lastDeployDate != null) { liveActivityElement.addContent(new Element(ELEMENT_NAME_LIVE_ACTIVITY_LAST_DEPLOY_DATE) .addContent(Long.toString(lastDeployDate.getTime()))); } return liveActivityElement; }
From source file:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelCreator.java
License:Apache License
/** * Add an activity configuration to the given element if there is a * configuration./*from w w w . ja v a 2s . c o m*/ * * @param element * the XML element to add the configuration onto * @param configuration * the possible configuration (can be {@code null}) */ private void addActivityConfiguration(Element element, ActivityConfiguration configuration) { if (configuration != null) { Element configurationElement = new Element(ELEMENT_NAME_ACTIVITY_CONFIGURATION); element.addContent(configurationElement); Set<ConfigurationParameter> parameters = configuration.getParameters(); if (!parameters.isEmpty()) { Element parametersElement = new Element(ELEMENT_NAME_ACTIVITY_CONFIGURATION_ROOT_PARAMETERS); configurationElement.addContent(parametersElement); for (ConfigurationParameter parameter : parameters) { Element parameterElement = new Element( ELEMENT_NAME_ACTIVITY_CONFIGURATION_INDIVIDUAL_PARAMETER); parametersElement.addContent(parameterElement); parameterElement .setAttribute(ATTRIBUTE_NAME_ACTIVITY_CONFIGURATION_PARAMETER_NAME, parameter.getName()) .addContent(new CDATA(parameter.getValue())); } } } }