Exemple #1
0
 private void exportAttributes(Map<String, Object> attrMap) {
   for (Map.Entry<String, Object> e : attrMap.entrySet()) {
     if (e.getKey().equals(WikiPage.CHANGENOTE))
       exportProperty("wiki:changeNote", (String) e.getValue(), STRING);
     else exportProperty(e.getKey(), e.getValue().toString(), STRING);
   }
 }
Exemple #2
0
  private void exportAcl(Acl acl) {
    if (acl != null) {
      ArrayList<String> propval = new ArrayList<String>();
      for (Enumeration<AclEntry> ee = acl.entries(); ee.hasMoreElements(); ) {
        AclEntry ae = ee.nextElement();

        StringBuilder sb = new StringBuilder();

        sb.append("ALLOW \"");
        sb.append(ae.getPrincipal().getName());
        sb.append("\" ");

        for (Enumeration<Permission> permissions = ae.permissions();
            permissions.hasMoreElements(); ) {
          Permission perm = permissions.nextElement();

          sb.append(perm.getActions());
          sb.append(",");
        }

        propval.add(sb.toString());
      }

      exportProperty("wiki:acl", propval.toArray(new String[propval.size()]), STRING);
    }
  }
Exemple #3
0
  private void exportPageHeader(
      String title, String wiki, String author, Date lastModified, boolean isAttachment)
      throws IOException {
    m_out.println(" <sv:node sv:name='" + StringEscapeUtils.escapeXml(title.toLowerCase()) + "'>");

    exportProperty("jcr:primaryType", "nt:unstructured", NAME);
    exportProperty("jcr:mixinTypes", new String[] {"mix:referenceable", "mix:lockable"}, NAME);
    exportProperty("wiki:author", author, STRING);
    exportProperty("jcr:uuid", mkUuid(wiki, title), STRING);

    exportProperty("wiki:lastModified", m_isoFormat.format(lastModified), DATE);

    exportProperty("wiki:contentType", guessMimeType(title, isAttachment), STRING);

    exportProperty("wiki:title", title, STRING);
  }
Exemple #4
0
  protected void exportPage(WikiEngine engine, WikiPage p) throws IOException, ProviderException {
    String name = p.getName();
    String title = name;
    boolean isAttachment = p instanceof Attachment;

    title = generateTitle(name, title, isAttachment);

    exportPageHeader(p.getName(), p.getWiki(), p.getAuthor(), p.getLastModified(), isAttachment);

    Map<String, Object> attrMap = p.getAttributes();

    exportAttributes(attrMap);

    //
    //  ACLs
    //

    Acl acl = p.getAcl();

    exportAcl(acl);

    //
    //  Export page content
    //

    exportProperty("wiki:content", engine.getPureText(p), STRING);

    //
    //  Finally, list attachment.  According to JCR rules, these must be last.
    //
    /*
    Collection<Attachment> atts = m_engine.getAttachmentManager().listAttachments( p );

    for( Attachment a : atts )
    {
        exportPage( a );
    }
    */
    exportPageFooter();
  }
Exemple #5
0
  protected void export(String dir) throws IOException {
    System.out.println(
        "Exporting a FileSystemProvider/RCSFileProvider/VersioningFileProvider compatible repository.");
    System.out.println(
        "This version does not export attributes, ACLs or attachments. Please use --properties for that.");

    File df = new File(dir);

    File[] pages =
        df.listFiles(
            new FilenameFilter() {

              public boolean accept(File dir, String name) {
                return name.endsWith(FileSystemProvider.FILE_EXT);
              }
            });

    exportDocumentHeader();

    for (File f : pages) {
      String pageName = f.getName();
      pageName = pageName.replace(".txt", "");
      exportPageHeader(pageName, "Main", "TBD", new Date(f.lastModified()), false);

      // File content

      FileInputStream in = new FileInputStream(f);
      exportProperty("wiki:content", FileUtil.readContents(in, "UTF-8"), STRING);
      in.close();

      exportPageFooter();
    }
    exportDocumentFooter();

    System.out.println("...done");
  }