コード例 #1
0
ファイル: ExportFactory.java プロジェクト: SerNet/verinice
 /**
  * Creates a SyncLink instance out of a {@link CnALink} instance. SyncLink is a JAXB Xml class
  * generated out of verinice import and export XML schema files: sernet/verinice/service/sync
  * sync.xsd data.xsd mapping.xsd
  *
  * @param syncLink
  * @param link
  */
 public static void transform(CnALink link, List<SyncLink> syncLinkXmlList) {
   SyncLink syncLink = new SyncLink();
   syncLink.setDependant(ExportFactory.createExtId(link.getDependant()));
   syncLink.setDependency(ExportFactory.createExtId(link.getDependency()));
   syncLink.setRelationId(link.getRelationId());
   if (link.getComment() != null && !link.getComment().isEmpty()) {
     syncLink.setComment(link.getComment());
   }
   syncLinkXmlList.add(syncLink);
 }
コード例 #2
0
ファイル: ExportFactory.java プロジェクト: SerNet/verinice
 /** @param attachment */
 public static String createZipFileName(Attachment attachment) {
   StringBuilder sb = new StringBuilder();
   sb.append(VeriniceArchive.FILES).append("/");
   sb.append(attachment.getDbId()).append("-");
   // avoid problems with non-ASCII file names
   String fileName = attachment.getFileName();
   fileName = ExportFactory.replaceNonAsciiChars(fileName);
   sb.append(fileName);
   return sb.toString().replaceAll(" ", "_");
 }
コード例 #3
0
ファイル: ExportCommand.java プロジェクト: SerNet/verinice
 private byte[] exportRiskAnalyses() {
   if (!isRiskAnalysis()) {
     return null;
   }
   final RiskAnalysisExporter exporter = new RiskAnalysisExporter();
   exporter.setCommandService(getCommandService());
   exporter.setRiskAnalysisIdSet(riskAnalysisIdSet);
   exporter.run();
   final ByteArrayOutputStream bos = new ByteArrayOutputStream();
   ExportFactory.marshal(exporter.getRisk(), bos);
   return bos.toByteArray();
 }
コード例 #4
0
ファイル: ExportCommand.java プロジェクト: SerNet/verinice
  /**
   * Creates the verinice archive after createXmlData() was called.
   *
   * @return the verinice archive as byte[]
   * @throws CommandException
   */
  private byte[] createVeriniceArchive() throws CommandException {
    try {
      final ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
      final ZipOutputStream zipOut = new ZipOutputStream(byteOut);

      ExportFactory.createZipEntry(zipOut, VeriniceArchive.VERINICE_XML, xmlData);
      if (isRiskAnalysis()) {
        ExportFactory.createZipEntry(zipOut, VeriniceArchive.RISK_XML, xmlDataRiskAnalysis);
      }
      ExportFactory.createZipEntry(
          zipOut, VeriniceArchive.DATA_XSD, StreamFactory.getDataXsdAsStream());
      ExportFactory.createZipEntry(
          zipOut, VeriniceArchive.MAPPING_XSD, StreamFactory.getMappingXsdAsStream());
      ExportFactory.createZipEntry(
          zipOut, VeriniceArchive.SYNC_XSD, StreamFactory.getSyncXsdAsStream());
      ExportFactory.createZipEntry(
          zipOut, VeriniceArchive.RISK_XSD, StreamFactory.getRiskXsdAsStream());
      ExportFactory.createZipEntry(
          zipOut, VeriniceArchive.README_TXT, StreamFactory.getReadmeAsStream());

      for (final Attachment attachment : getAttachmentSet()) {
        LoadAttachmentFile command = new LoadAttachmentFile(attachment.getDbId(), true);
        command = getCommandService().executeCommand(command);
        if (command.getAttachmentFile() != null
            && command.getAttachmentFile().getFileData() != null) {
          ExportFactory.createZipEntry(
              zipOut,
              ExportFactory.createZipFileName(attachment),
              command.getAttachmentFile().getFileData());
        }
        command.setAttachmentFile(null);
      }

      zipOut.close();
      byteOut.close();
      return byteOut.toByteArray();
    } catch (final IOException e) {
      getLog().error("Error while creating zip output stream", e);
      throw new RuntimeCommandException(e);
    }
  }
コード例 #5
0
ファイル: ExportCommand.java プロジェクト: SerNet/verinice
 private void exportLinks(final SyncData syncData) {
   for (final CnALink link : linkSet) {
     CnATreeElement dependant = link.getDependant();
     dependant = getFromCache(dependant);
     if (dependant == null) {
       log.warn("Dependant of link not found. Check access rights. " + link.getId());
       continue;
     }
     link.setDependant(dependant);
     CnATreeElement dependency = link.getDependency();
     dependency = getFromCache(dependency);
     if (dependency == null) {
       log.warn("Dependency of link not found. Check access rights. " + link.getId());
       continue;
     }
     link.setDependency(dependency);
     ExportFactory.transform(link, syncData.getSyncLink());
   }
 }
コード例 #6
0
ファイル: ExportCommand.java プロジェクト: SerNet/verinice
  /**
   * Export (i.e. "create XML representation of" the given cnATreeElement and its successors. For
   * this, child elements are exported recursively. All elements that have been processed are
   * returned as a list of {@code syncObject}s with their respective attributes, represented as
   * {@code syncAttribute}s.
   *
   * @return XML representation of elements
   * @throws CommandException
   */
  private byte[] export() throws CommandException {
    if (getLog().isInfoEnabled()) {
      getLog().info("Max number of threads is: " + getMaxNumberOfThreads());
    }

    getCache().removeAll();

    final SyncVnaSchemaVersion formatVersion = createVersionData();

    final SyncData syncData = new SyncData();
    final ExportTransaction exportTransaction = new ExportTransaction();

    for (final CnATreeElement element : elements) {
      exportTransaction.setElement(element);
      exportElement(exportTransaction);
      syncData.getSyncObject().add(exportTransaction.getTarget());
    }

    exportLinks(syncData);

    if (getLog().isDebugEnabled()) {
      final Statistics s = getCache().getStatistics();
      getLog().debug("Cache size: " + s.getObjectCount() + ", hits: " + s.getCacheHits());
    }

    final SyncMapping syncMapping = new SyncMapping();
    createMapping(syncMapping.getMapObjectType());

    final SyncRequest syncRequest = new SyncRequest();
    syncRequest.setSourceId(sourceId);
    syncRequest.setSyncData(syncData);
    syncRequest.setSyncMapping(syncMapping);
    syncRequest.setSyncVnaSchemaVersion(formatVersion);

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ExportFactory.marshal(syncRequest, bos);
    return bos.toByteArray();
  }