Exemplo n.º 1
0
 private void copyEntry(IInputSource source, IOutputTarget target, String entryPath)
     throws CoreException {
   try {
     InputStream in = getInputStream(source, entryPath);
     if (in != null) {
       OutputStream out = getOutputStream(target, entryPath);
       if (out != null) {
         try {
           FileUtils.transfer(in, out, true);
         } finally {
           long time = source.getEntryTime(entryPath);
           if (time >= 0) {
             target.setEntryTime(entryPath, time);
           }
           Exception e2 = checkChecksum(source, entryPath, in, null);
           if (e2 instanceof CoreException) {
             throw (CoreException) e2;
           }
         }
       }
     }
   } catch (IOException e) {
     Core.getLogger().log(e);
   } catch (CoreException e) {
     if (e.getType() == Core.ERROR_WRONG_PASSWORD || e.getType() == Core.ERROR_CANCELLATION)
       throw e;
     Core.getLogger().log(e);
   }
 }
Exemplo n.º 2
0
 private static void setThemeStyles(
     IWorkbook workbook,
     IStyleSheet styleSheet,
     ISheet sheet,
     IStyle theme,
     String... sheetStyleNames) {
   IStyle sheetTheme = theme.getDefaultStyle(Styles.FAMILY_MAP);
   if (sheetTheme == null) return;
   IStyle sheetStyle = styleSheet.findStyle(sheet.getStyleId());
   if (sheetStyle != null) {
     sheetStyle =
         Core.getWorkbookBuilder().createWorkbook().getStyleSheet().importStyle(sheetStyle);
   }
   String value = null;
   for (String styleName : sheetStyleNames) {
     value = sheetTheme.getProperty(styleName);
     if (value != null) {
       if (sheetStyle == null)
         sheetStyle =
             Core.getWorkbookBuilder()
                 .createWorkbook()
                 .getStyleSheet()
                 .createStyle(sheet.getStyleType());
       sheetStyle.setProperty(styleName, value);
     } else if (sheetStyle != null) {
       sheetStyle.setProperty(styleName, value);
     }
   }
   if (sheetStyle != null) {
     sheetStyle = workbook.getStyleSheet().importStyle(sheetStyle);
     if (sheetStyle != null) {
       sheet.setStyleId(sheetStyle.getId());
     }
   }
 }
Exemplo n.º 3
0
  @Before
  public void setUp() throws Exception {
    IMarkerSheet globalMarkers;
    InputStream markerSheetStream =
        new URL("platform:/plugin/org.xmind.core.runtime.tests/samples/markers.xml").openStream();
    try {
      globalMarkers = Core.getMarkerSheetBuilder().loadFromStream(markerSheetStream, null);
    } finally {
      markerSheetStream.close();
    }
    IInputSource source =
        new BundleResourceInputSource(
            "org.xmind.core.runtime.tests", "/samples/sample1.xmind"); // $NON-NLS-2$
    workbook = Core.getWorkbookBuilder().loadFromInputSource(source, new ByteArrayStorage(), null);
    workbook.getMarkerSheet().setParentSheet(globalMarkers);

    axisProvider = new CoreAxisProvider();
  }
Exemplo n.º 4
0
 /*
  * (non-Javadoc)
  *
  * @see org.xmind.core.io.IOutputTarget#close()
  */
 public void close() {
   try {
     zip.flush();
     zip.close();
     return;
   } catch (IOException e) {
     Core.getLogger().log(e);
   }
 }
Exemplo n.º 5
0
 /*
  * (non-Javadoc)
  *
  * @see org.xmind.core.io.IOutputTarget#getEntryStream(java.lang.String)
  */
 public OutputStream getEntryStream(String entryName) {
   try {
     this.currentEntry = new ZipEntry(entryName);
     zip.putNextEntry(currentEntry);
     return new ZipEntryOutputStream(zip);
   } catch (IOException e) {
     Core.getLogger().log(e);
     return null;
   }
 }
Exemplo n.º 6
0
 private void loadMarkerSheet() throws IOException, CoreException {
   try {
     IMarkerSheet markerSheet =
         ((MarkerSheetBuilderImpl) Core.getMarkerSheetBuilder())
             .loadFromInputSource(source, this, new WorkbookMarkerResourceProvider(workbook));
     workbook.setMarkerSheet((MarkerSheetImpl) markerSheet);
   } catch (IOException e) {
     throw e;
   } catch (CoreException e) {
     if (e.getType() != Core.ERROR_NO_SUCH_ENTRY) throw e;
   }
 }
Exemplo n.º 7
0
 private void loadStyleSheet() throws IOException, CoreException {
   try {
     IStyleSheet styleSheet =
         ((StyleSheetBuilderImpl) Core.getStyleSheetBuilder()).loadFromInputSource(source, this);
     ((StyleSheetImpl) styleSheet).setManifest(manifest);
     workbook.setStyleSheet((StyleSheetImpl) styleSheet);
   } catch (IOException e) {
     throw e;
   } catch (CoreException e) {
     if (e.getType() != Core.ERROR_NO_SUCH_ENTRY) throw e;
   }
 }
Exemplo n.º 8
0
 private Document forceLoadXML(String entryPath) throws IOException, CoreException {
   try {
     return loadXMLFile(source, entryPath);
   } catch (Throwable e) {
     if (e instanceof CoreException) {
       CoreException coreEx = (CoreException) e;
       if (coreEx.getType() == Core.ERROR_WRONG_PASSWORD
           || coreEx.getType() == Core.ERROR_CANCELLATION) {
         throw coreEx;
       }
     }
     // in case the file is damaged,
     // try continue loading
     Core.getLogger().log(e, "Faild to load " + entryPath); // $NON-NLS-1$
     return createDocument();
   }
 }
Exemplo n.º 9
0
 private ITopic createDummyTopic(IBranchPart sourceBranch, boolean newTopic) {
   ITopic topic;
   if (sourceBranch == null && newTopic) {
     ITopic centralTopic = (ITopic) viewer.getAdapter(ITopic.class);
     topic = centralTopic.getOwnedWorkbook().createTopic();
     centralTopic.add(topic, ITopic.DETACHED);
   } else if (sourceBranch != null) {
     ITopic sourceTopic = sourceBranch.getTopic();
     topic = sourceTopic.getOwnedWorkbook().createTopic();
     topic.setTitleText(sourceTopic.getTitleText());
     topic.setStyleId(sourceTopic.getStyleId());
     topic.setTitleWidth(sourceTopic.getTitleWidth());
     ((TopicImpl) topic).setCoreEventSupport(new CoreEventSupport());
   } else {
     topic = Core.getWorkbookBuilder().createWorkbook().createTopic();
   }
   return topic;
 }