List of usage examples for javax.xml.bind Marshaller JAXB_ENCODING
String JAXB_ENCODING
To view the source code for javax.xml.bind Marshaller JAXB_ENCODING.
Click Source Link
From source file:org.tinymediamanager.core.movie.connector.MovieToMpNfoConnector.java
static void writeNfoFiles(Movie movie, MovieToMpNfoConnector mp, List<MovieNfoNaming> nfoNames) { String nfoFilename = ""; List<MediaFile> newNfos = new ArrayList<>(1); for (MovieNfoNaming name : nfoNames) { try {// ww w .j ava2 s .c om nfoFilename = movie.getNfoFilename(name); if (nfoFilename.isEmpty()) { continue; } Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dat = formatter.format(new Date()); String comment = "<!-- created on " + dat + " - tinyMediaManager " + Globals.settings.getVersion() + " -->\n"; m.setProperty("com.sun.xml.internal.bind.xmlHeaders", comment); // w = new FileWriter(nfoFilename); Writer w = new StringWriter(); m.marshal(mp, w); StringBuilder sb = new StringBuilder(w.toString()); w.close(); // on windows make windows conform linebreaks if (SystemUtils.IS_OS_WINDOWS) { sb = new StringBuilder(sb.toString().replaceAll("(?<!\r)\n", "\r\n")); } Path f = movie.getPathNIO().resolve(nfoFilename); Utils.writeStringToFile(f, sb.toString()); MediaFile mf = new MediaFile(f); mf.gatherMediaInformation(true); // force to update filedate newNfos.add(mf); } catch (Exception e) { LOGGER.error("setData " + movie.getPathNIO().resolve(nfoFilename), e); MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, movie, "message.nfo.writeerror", new String[] { e.getLocalizedMessage() })); } } if (newNfos.size() > 0) { movie.removeAllMediaFiles(MediaFileType.NFO); movie.addToMediaFiles(newNfos); } }
From source file:org.tinymediamanager.core.movie.connector.MovieToXbmcNfoConnector.java
static void writeNfoFiles(Movie movie, MovieToXbmcNfoConnector xbmc, List<MovieNfoNaming> nfoNames) { String nfoFilename = ""; List<MediaFile> newNfos = new ArrayList<>(1); for (MovieNfoNaming name : nfoNames) { try {//from ww w. j a va2s . c om nfoFilename = movie.getNfoFilename(name); if (nfoFilename.isEmpty()) { continue; } Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dat = formatter.format(new Date()); String comment = "<!-- created on " + dat + " - tinyMediaManager " + Globals.settings.getVersion() + " -->\n"; m.setProperty("com.sun.xml.internal.bind.xmlHeaders", comment); // w = new FileWriter(nfoFilename); Writer w = new StringWriter(); m.marshal(xbmc, w); StringBuilder sb = new StringBuilder(w.toString()); w.close(); // on windows make windows conform linebreaks if (SystemUtils.IS_OS_WINDOWS) { sb = new StringBuilder(sb.toString().replaceAll("(?<!\r)\n", "\r\n")); } Path f = movie.getPathNIO().resolve(nfoFilename); Utils.writeStringToFile(f, sb.toString()); MediaFile mf = new MediaFile(f); mf.gatherMediaInformation(true); // force to update filedate newNfos.add(mf); } catch (Exception e) { LOGGER.error("setData " + movie.getPathNIO().resolve(nfoFilename), e); MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, movie, "message.nfo.writeerror", new String[] { ":", e.getLocalizedMessage() })); } } if (newNfos.size() > 0) { movie.removeAllMediaFiles(MediaFileType.NFO); movie.addToMediaFiles(newNfos); } }
From source file:org.tinymediamanager.core.tvshow.connector.TvShowEpisodeToXbmcNfoConnector.java
/** * Sets the data.//from ww w . ja v a2 s .co m * * @param tvShowEpisodes * the tv show episodes */ public static void setData(List<TvShowEpisode> tvShowEpisodes) { boolean multiEpisode = tvShowEpisodes.size() > 1 ? true : false; if (context == null) { MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, tvShowEpisodes.get(0), "message.nfo.writeerror", new String[] { ":", "Context is null" })); return; } if (tvShowEpisodes.size() == 0) { return; } TvShowEpisode episode = tvShowEpisodes.get(0); MediaFile mf = episode.getBiggestMediaFile(MediaFileType.VIDEO); if (mf == null) { return; // no video file? } String nfoFilename = mf.getBasename() + ".nfo"; if (episode.isDisc()) { nfoFilename = "VIDEO_TS.nfo"; // FIXME: BluRay? } File nfoFile = new File(episode.getPath(), nfoFilename); // parse out all episodes from the nfo List<TvShowEpisodeToXbmcNfoConnector> xbmcConnectors = parseNfo(nfoFile); // process all episodes StringBuilder outputXml = new StringBuilder(); for (int i = 0; i < tvShowEpisodes.size(); i++) { episode = tvShowEpisodes.get(i); List<Object> unsupportedTags = new ArrayList<>(); // look in all parsed NFOs for this episode TvShowEpisodeToXbmcNfoConnector xbmc = null; for (TvShowEpisodeToXbmcNfoConnector con : xbmcConnectors) { if (String.valueOf(episode.getEpisode()).equals(con.episode) && String.valueOf(episode.getSeason()).equals(con.season)) { xbmc = con; break; } } if (xbmc == null) { // create a new connector xbmc = new TvShowEpisodeToXbmcNfoConnector(); } else { // store all unsupported tags for (Object obj : xbmc.actors) { // ugly hack for invalid xml structure if (!(obj instanceof Actor)) { unsupportedTags.add(obj); } } } xbmc.setTitle(episode.getTitle()); xbmc.setShowtitle(episode.getTvShow().getTitle()); xbmc.setRating(episode.getRating()); xbmc.setVotes(episode.getVotes()); xbmc.setSeason(String.valueOf(episode.getSeason())); xbmc.setEpisode(String.valueOf(episode.getEpisode())); xbmc.setDisplayseason(String.valueOf(episode.getDisplaySeason())); xbmc.setDisplayepisode(String.valueOf(episode.getDisplayEpisode())); xbmc.setPlot(episode.getPlot()); xbmc.setAired(episode.getFirstAiredFormatted()); xbmc.setPremiered(episode.getFirstAiredFormatted()); if (StringUtils.isNotEmpty(episode.getTvShow().getProductionCompany())) { xbmc.studio = Arrays.asList(episode.getTvShow().getProductionCompany().split("\\s*[,\\/]\\s*")); // split on , or / and remove whitespace // around } if (episode.getTvdbId() != null) { xbmc.setUniqueid(episode.getTvdbId().toString()); } xbmc.setMpaa(episode.getTvShow().getCertification().getName()); xbmc.watched = episode.isWatched(); if (xbmc.watched) { xbmc.playcount = 1; } xbmc.actors.clear(); // actors for tv show episode (guests) for (TvShowActor actor : episode.getGuests()) { xbmc.addActor(actor.getName(), actor.getCharacter(), actor.getThumbUrl()); } // write thumb url to multi ep NFOs // since the video file contains two or more EPs, we can only store 1 thumb file; in this // case we write the thumb url to the NFOs that Kodi can display the proper one if (multiEpisode && StringUtils.isNotBlank(episode.getArtworkUrl(MediaFileType.THUMB))) { xbmc.thumb = episode.getArtworkUrl(MediaFileType.THUMB); } else { xbmc.thumb = ""; } // support of frodo director tags xbmc.director.clear(); if (StringUtils.isNotEmpty(episode.getDirector())) { String directors[] = episode.getDirector().split(", "); for (String director : directors) { xbmc.addDirector(director); } } // support of frodo credits tags xbmc.credits.clear(); if (StringUtils.isNotEmpty(episode.getWriter())) { String writers[] = episode.getWriter().split(", "); for (String writer : writers) { xbmc.addCredits(writer); } } xbmc.tags.clear(); for (String tag : episode.getTags()) { xbmc.tags.add(tag); } // fileinfo Fileinfo info = new Fileinfo(); for (MediaFile mediaFile : episode.getMediaFiles(MediaFileType.VIDEO)) { if (StringUtils.isEmpty(mediaFile.getVideoCodec())) { break; } info.streamdetails.video.codec = mediaFile.getVideoCodec(); info.streamdetails.video.aspect = String.valueOf(mediaFile.getAspectRatio()); info.streamdetails.video.width = mediaFile.getVideoWidth(); info.streamdetails.video.height = mediaFile.getVideoHeight(); info.streamdetails.video.durationinseconds = mediaFile.getDuration(); // "Spec": https://github.com/xbmc/xbmc/blob/master/xbmc/guilib/StereoscopicsManager.cpp if (mediaFile.getVideo3DFormat().equals(MediaFile.VIDEO_3D_SBS) || mediaFile.getVideo3DFormat().equals(MediaFile.VIDEO_3D_HSBS)) { info.streamdetails.video.stereomode = "left_right"; } else if (mediaFile.getVideo3DFormat().equals(MediaFile.VIDEO_3D_TAB) || mediaFile.getVideo3DFormat().equals(MediaFile.VIDEO_3D_HTAB)) { info.streamdetails.video.stereomode = "top_bottom"; // maybe? } for (MediaFileAudioStream as : mediaFile.getAudioStreams()) { Audio audio = new Audio(); if (StringUtils.isNotBlank(as.getCodec())) { audio.codec = as.getCodec().replaceAll("-", "_"); } else { audio.codec = as.getCodec(); } audio.language = as.getLanguage(); audio.channels = String.valueOf(as.getChannelsAsInt()); info.streamdetails.audio.add(audio); } for (MediaFileSubtitle ss : mediaFile.getSubtitles()) { Subtitle sub = new Subtitle(); sub.language = ss.getLanguage(); info.streamdetails.subtitle.add(sub); } break; } // add external subtitles to NFO for (MediaFile mediaFile : episode.getMediaFiles(MediaFileType.SUBTITLE)) { for (MediaFileSubtitle ss : mediaFile.getSubtitles()) { Subtitle sub = new Subtitle(); sub.language = ss.getLanguage(); info.streamdetails.subtitle.add(sub); } } xbmc.fileinfo = info; // add all unsupported tags again xbmc.unsupportedElements.addAll(unsupportedTags); // and marshall it try { Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dat = formatter.format(new Date()); String comment = "<!-- created on " + dat + " - tinyMediaManager " + Globals.settings.getVersion() + " -->\n"; m.setProperty("com.sun.xml.internal.bind.xmlHeaders", comment); Writer w = new StringWriter(); m.marshal(xbmc, w); StringBuilder sb = new StringBuilder(w.toString()); w.close(); // strip out <?xml..> on all xmls except the first if (i > 0) { sb = new StringBuilder(sb.toString().replaceAll("<\\?xml.*\\?>", "")); } // on windows make windows conform linebreaks if (SystemUtils.IS_OS_WINDOWS) { sb = new StringBuilder(sb.toString().replaceAll("(?<!\r)\n", "\r\n")); } outputXml.append(sb); } catch (Exception e) { LOGGER.error("setData " + nfoFile.getAbsolutePath(), e.getMessage()); MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, tvShowEpisodes.get(0), "message.nfo.writeerror", new String[] { ":", e.getLocalizedMessage() })); } } try { FileUtils.write(nfoFile, outputXml, "UTF-8"); for (TvShowEpisode e : tvShowEpisodes) { e.removeAllMediaFiles(MediaFileType.NFO); e.addToMediaFiles(new MediaFile(nfoFile)); } } catch (Exception e) { LOGGER.error("setData " + nfoFile.getAbsolutePath(), e.getMessage()); MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, tvShowEpisodes.get(0), "message.nfo.writeerror", new String[] { ":", e.getLocalizedMessage() })); } }
From source file:org.tinymediamanager.core.tvshow.connector.TvShowToXbmcNfoConnector.java
public static void setData(TvShow tvShow) { if (context == null) { MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, tvShow, "message.nfo.writeerror", new String[] { ":", "Context is null" })); return;//ww w . j ava2s. com } TvShowToXbmcNfoConnector xbmc = null; List<Object> unsupportedTags = new ArrayList<>(); String nfoFilename = "tvshow.nfo"; File nfoFile = new File(tvShow.getPath(), nfoFilename); // load existing NFO if possible if (nfoFile.exists()) { try { Unmarshaller um = context.createUnmarshaller(); Reader in = new InputStreamReader(new FileInputStream(nfoFile), "UTF-8"); xbmc = (TvShowToXbmcNfoConnector) um.unmarshal(in); } catch (Exception e) { LOGGER.error("failed to parse " + nfoFile.getAbsolutePath() + "; " + e.getMessage()); } } // create new if (xbmc == null) { xbmc = new TvShowToXbmcNfoConnector(); } else { // store all unsupported tags for (Object obj : xbmc.actors) { // ugly hack for invalid xml structure if (!(obj instanceof Actor)) { unsupportedTags.add(obj); } } } // set data String tvdbid = tvShow.getIdAsString(Constants.TVDB); if (StringUtils.isNotBlank(tvdbid)) { xbmc.setId(tvdbid); xbmc.episodeguide.url.cache = tvdbid + ".xml"; xbmc.episodeguide.url.url = "http://www.thetvdb.com/api/1D62F2F90030C444/series/" + tvdbid + "/all/" + TvShowModuleManager.SETTINGS.getScraperLanguage().name() + ".xml"; } xbmc.setImdbid(tvShow.getIdAsString(Constants.IMDB)); xbmc.setTitle(tvShow.getTitle()); xbmc.setSorttitle(tvShow.getSortTitle()); xbmc.setRating(tvShow.getRating()); xbmc.setVotes(tvShow.getVotes()); xbmc.setPlot(tvShow.getPlot()); xbmc.setYear(tvShow.getYear()); if (tvShow.getCertification() != null) { xbmc.setMpaa(tvShow.getCertification().getName()); } xbmc.setPremiered(tvShow.getFirstAiredFormatted()); if (StringUtils.isNotEmpty(tvShow.getProductionCompany())) { xbmc.studio = Arrays.asList(tvShow.getProductionCompany().split("\\s*[,\\/]\\s*")); // split on , or / and remove whitespace around } xbmc.setStatus(tvShow.getStatus()); xbmc.genres.clear(); for (MediaGenres genre : tvShow.getGenres()) { xbmc.addGenre(genre.toString()); } xbmc.actors.clear(); for (TvShowActor actor : tvShow.getActors()) { xbmc.addActor(actor.getName(), actor.getCharacter(), actor.getThumbUrl()); } xbmc.tags.clear(); for (String tag : tvShow.getTags()) { xbmc.tags.add(tag); } // add all unsupported tags again xbmc.unsupportedElements.addAll(unsupportedTags); // and marshall it try { Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dat = formatter.format(new Date()); String comment = "<!-- created on " + dat + " - tinyMediaManager " + Globals.settings.getVersion() + " -->\n"; m.setProperty("com.sun.xml.internal.bind.xmlHeaders", comment); Writer w = new StringWriter(); m.marshal(xbmc, w); StringBuilder sb = new StringBuilder(w.toString()); w.close(); // on windows make windows conform linebreaks if (SystemUtils.IS_OS_WINDOWS) { sb = new StringBuilder(sb.toString().replaceAll("(?<!\r)\n", "\r\n")); } FileUtils.write(nfoFile, sb, "UTF-8"); tvShow.removeAllMediaFiles(MediaFileType.NFO); tvShow.addToMediaFiles(new MediaFile(nfoFile)); } catch (Exception e) { e.printStackTrace(); LOGGER.error(nfoFile.getAbsolutePath() + " " + e.getMessage()); MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, tvShow, "message.nfo.writeerror", new String[] { ":", e.getLocalizedMessage() })); } }
From source file:org.wso2.carbon.dssapi.observer.APIObserver.java
@Override public void serviceUpdate(AxisEvent axisEvent, AxisService axisService) { if (axisEvent.getEventType() == AxisEvent.SERVICE_DEPLOY) { DataService dataService = (DataService) axisService.getParameter(DBConstants.DATA_SERVICE_OBJECT) .getValue();/*from www . jav a2s.c o m*/ if (dataService != null) { String location = dataService.getDsLocation(); location = location.substring(0, location.lastIndexOf("/")); File file = new File(location + "/" + dataService.getName() + APIUtil.APPLICATION_XML); if (file.exists()) { Application application; try { JAXBContext jaxbContext = JAXBContext.newInstance(Application.class); Unmarshaller jaxbUnMarshaller = jaxbContext.createUnmarshaller(); jaxbUnMarshaller.setProperty("jaxb.encoding", "UTF-8"); application = (Application) jaxbUnMarshaller.unmarshal(file); String serviceContents = new DataServiceAdmin() .getDataServiceContentAsString(dataService.getName()); XMLStreamReader reader = XMLInputFactory.newInstance() .createXMLStreamReader(new StringReader(serviceContents)); OMElement configElement = (new StAXOMBuilder(reader)).getDocumentElement(); configElement.build(); Data data = new Data(); data.populate(configElement); String tempDeployedTime = new ServiceAdmin( DataHolder.getConfigurationContext().getAxisConfiguration()) .getServiceData(data.getName()).getServiceDeployedTime(); if (!application.getDeployedTime().equalsIgnoreCase(tempDeployedTime)) { APIUtil.updateApi(dataService.getName(), application.getUserName(), data, application.getVersion()); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); application.setDeployedTime(tempDeployedTime); jaxbMarshaller.marshal(application, file); } } catch (JAXBException e) { log.error("An error occurred while reading the data for " + dataService.getName(), e); } catch (XMLStreamException e) { log.error("An error occurred while reading xml data for " + dataService.getName(), e); } catch (AxisFault axisFault) { log.error("An error occurred while reading the service " + dataService.getName(), axisFault); } catch (Exception e) { log.error("Couldn't get service meta data for the service " + dataService.getName(), e); } //Logged observed errors and let the process to continue } } } }
From source file:org.wso2.carbon.event.execution.manager.core.internal.util.ExecutionManagerHelper.java
public static void saveToRegistry(ScenarioConfiguration configuration) throws ExecutionManagerException { try {// w w w.ja v a 2s . c o m Registry registry = ExecutionManagerValueHolder.getRegistryService() .getConfigSystemRegistry(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); StringWriter fileContent = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance(ScenarioConfiguration.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, ExecutionManagerConstants.DEFAULT_CHARSET); jaxbMarshaller.marshal(configuration, fileContent); Resource resource = registry.newResource(); resource.setContent(fileContent.toString()); String resourceCollectionPath = ExecutionManagerConstants.TEMPLATE_CONFIG_PATH + "/" + configuration.getDomain(); String resourcePath = resourceCollectionPath + "/" + configuration.getName() + ExecutionManagerConstants.CONFIG_FILE_EXTENSION; //Collection directory will be created if it is not exist in the registry if (!registry.resourceExists(resourceCollectionPath)) { registry.put(resourceCollectionPath, registry.newCollection()); } if (registry.resourceExists(resourcePath)) { registry.delete(resourcePath); } resource.setMediaType("application/xml"); registry.put(resourcePath, resource); } catch (JAXBException e) { throw new ExecutionManagerException("Could not marshall Scenario: " + configuration.getName() + ", for Domain: " + configuration.getDomain() + ". Could not save to registry.", e); } catch (RegistryException e) { throw new ExecutionManagerException("Could not save Scenario: " + configuration.getName() + ", for Domain: " + configuration.getDomain() + ", to the registry.", e); } }
From source file:org.wso2.carbon.event.template.manager.core.internal.util.TemplateManagerHelper.java
public static void saveToRegistry(ScenarioConfiguration configuration) throws TemplateManagerException { try {/*from w w w. ja v a 2 s . co m*/ Registry registry = TemplateManagerValueHolder.getRegistryService() .getConfigSystemRegistry(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); StringWriter fileContent = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance(ScenarioConfiguration.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, TemplateManagerConstants.DEFAULT_CHARSET); jaxbMarshaller.marshal(configuration, fileContent); Resource resource = registry.newResource(); resource.setContent(fileContent.toString()); String resourceCollectionPath = TemplateManagerConstants.TEMPLATE_CONFIG_PATH + "/" + configuration.getDomain(); String resourcePath = resourceCollectionPath + "/" + configuration.getName() + TemplateManagerConstants.CONFIG_FILE_EXTENSION; //Collection directory will be created if it is not exist in the registry if (!registry.resourceExists(resourceCollectionPath)) { registry.put(resourceCollectionPath, registry.newCollection()); } if (registry.resourceExists(resourcePath)) { registry.delete(resourcePath); } resource.setMediaType("application/xml"); registry.put(resourcePath, resource); } catch (JAXBException e) { throw new TemplateManagerException("Could not marshall Scenario: " + configuration.getName() + ", for Domain: " + configuration.getDomain() + ". Could not save to registry.", e); } catch (RegistryException e) { throw new TemplateManagerException("Could not save Scenario: " + configuration.getName() + ", for Domain: " + configuration.getDomain() + ", to the registry.", e); } }
From source file:org.zaproxy.zap.extension.exportreport.Export.ReportExport.java
public static String generateDUMP(String path, String fileName, String reportTitle, String reportBy, String reportFor, String scanDate, String scanVersion, String reportDate, String reportVersion, String reportDesc, ArrayList<String> alertSeverity, ArrayList<String> alertDetails) throws UnsupportedEncodingException { SiteMap siteMap = Model.getSingleton().getSession().getSiteTree(); SiteNode root = (SiteNode) siteMap.getRoot(); int siteNumber = root.getChildCount(); Report report = new Report(); report.setTitle(entityEncode(reportTitle)); report.setBy(entityEncode(reportBy)); report.setFor(entityEncode(reportFor)); report.setScanDate(entityEncode(scanDate)); report.setScanVersion(entityEncode(scanVersion)); report.setReportDate(entityEncode(reportDate)); report.setReportVersion(entityEncode(reportVersion)); report.setDesc(entityEncode(reportDesc)); String description = Constant.messages.getString("exportreport.details.description.label"); String solution = Constant.messages.getString("exportreport.details.solution.label"); String otherinfo = Constant.messages.getString("exportreport.details.otherinfo.label"); String reference = Constant.messages.getString("exportreport.details.reference.label"); String cweid = Constant.messages.getString("exportreport.details.cweid.label"); String wascid = Constant.messages.getString("exportreport.details.wascid.label"); String requestheader = Constant.messages.getString("exportreport.details.requestheader.label"); String responseheader = Constant.messages.getString("exportreport.details.responseheader.label"); String requestbody = Constant.messages.getString("exportreport.details.requestbody.label"); String responsebody = Constant.messages.getString("exportreport.details.responsebody.label"); try {//ww w . j av a 2 s . co m for (int i = 0; i < siteNumber; i++) { SiteNode site = (SiteNode) root.getChildAt(i); String siteName = ScanPanel.cleanSiteName(site, true); String[] hostAndPort = siteName.split(":"); boolean isSSL = (site.getNodeName().startsWith("https")); Sites s = new Sites(); s.setHost(entityEncode(hostAndPort[0])); s.setName(entityEncode(site.getNodeName())); s.setPort(entityEncode(hostAndPort[1])); s.setSSL(String.valueOf(isSSL)); List<Alert> alerts = site.getAlerts(); Alerts a = new Alerts(); String temp = ""; for (Alert alert : alerts) { if (!alertSeverity.contains(Alert.MSG_RISK[alert.getRisk()])) { continue; } AlertItem item = new AlertItem(); item.setPluginID(entityEncode(Integer.toString(alert.getPluginId()))); item.setAlert(entityEncode(alert.getAlert())); item.setRiskCode(entityEncode(Integer.toString(alert.getRisk()))); item.setRiskDesc(entityEncode(Alert.MSG_RISK[alert.getRisk()])); item.setConfidence(entityEncode(Alert.MSG_CONFIDENCE[alert.getConfidence()])); for (int j = 0; j < alertDetails.size(); j++) { if (alertDetails.get(j).equalsIgnoreCase(description)) item.setDesc(entityEncode(alert.getDescription())); if (alertDetails.get(j).equalsIgnoreCase(solution)) item.setSolution(entityEncode(alert.getSolution())); if (alertDetails.get(j).equalsIgnoreCase(otherinfo) && alert.getOtherInfo() != null && alert.getOtherInfo().length() > 0) { item.setOtherInfo(entityEncode(alert.getOtherInfo())); } if (alertDetails.get(j).equalsIgnoreCase(reference)) item.setReference(entityEncode(alert.getReference())); if (alertDetails.get(j).equalsIgnoreCase(cweid) && alert.getCweId() > 0) item.setCWEID(entityEncode(Integer.toString(alert.getCweId()))); if (alertDetails.get(j).equalsIgnoreCase(wascid)) item.setWASCID(entityEncode(Integer.toString(alert.getWascId()))); temp = alert.getMessage().getRequestHeader().toString(); if (alertDetails.get(j).equalsIgnoreCase(requestheader) && temp != null && temp.length() > 0) { item.setRequestHeader(entityEncode(temp)); } temp = alert.getMessage().getRequestBody().toString(); if (alertDetails.get(j).equalsIgnoreCase(requestbody) && temp != null && temp.length() > 0) { item.setRequestBody(entityEncode(temp)); } temp = alert.getMessage().getResponseHeader().toString(); if (alertDetails.get(j).equalsIgnoreCase(responseheader) && temp != null && temp.length() > 0) { item.setResponseHeader(entityEncode(temp)); } temp = alert.getMessage().getResponseBody().toString(); if (alertDetails.get(j).equalsIgnoreCase(responsebody) && temp != null && temp.length() > 0) { item.setResponseBody(entityEncode(temp)); } } item.setURI(entityEncode(alert.getUri())); if (alert.getParam() != null && alert.getParam().length() > 0) item.setParam(entityEncode(alert.getParam())); if (alert.getAttack() != null && alert.getAttack().length() > 0) item.setAttack(entityEncode(alert.getAttack())); if (alert.getEvidence() != null && alert.getEvidence().length() > 0) item.setEvidence(entityEncode(alert.getEvidence())); a.add(item); } s.setAlerts(a); report.add(s); } javax.xml.bind.JAXBContext jc = javax.xml.bind.JAXBContext.newInstance(Report.class); Marshaller jaxbMarshaller = jc.createMarshaller(); jaxbMarshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, Utils.utf8); // used to be utf-8, might not be able to change to upper case. jaxbMarshaller.marshal(report, new File(path + fileName + Utils.dump)); return path + fileName + Utils.dump; } catch (JAXBException e) { logger.error(e.getMessage(), e); } return ""; }
From source file:psidev.psi.mi.xml.io.impl.PsimiXmlWriter253.java
private String marshall(psidev.psi.mi.xml253.jaxb.EntrySet jEntrySet) throws PsimiXmlWriterException { Writer writer = new StringWriter(4096); try {/*from ww w . j a v a 2 s .c om*/ Marshaller marshaller = getMarshaller(jEntrySet); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.marshal(jEntrySet, writer); writer.close(); return writer.toString(); } catch (Exception e) { throw new PsimiXmlWriterException("En error occured while writing EntrySet", e); } }
From source file:psidev.psi.mi.xml.io.impl.PsimiXmlWriter254.java
private String marshall(psidev.psi.mi.xml254.jaxb.EntrySet jEntrySet) throws PsimiXmlWriterException { Writer writer = new StringWriter(4096); try {/*from ww w . ja va2 s .co m*/ Marshaller marshaller = getMarshaller(jEntrySet); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.marshal(jEntrySet, writer); writer.close(); return writer.toString(); } catch (Exception e) { throw new PsimiXmlWriterException("En error occured while writing EntrySet", e); } }