public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) { try { return new PackageAPI(new Package(), context); } catch (PackageException e) { return null; } }
/** * Load this package in memory from a byte array. It may be installed later using {@link #install(XWikiContext)}. * Your should prefer {@link #Import(InputStream, XWikiContext) which may avoid loading the package twice in memory. * * @param file a byte array containing the content of a zipped package file * @param context current XWikiContext * @return an empty string, useless. * @throws IOException while reading the ZipFile * @throws XWikiException when package content is broken */ public String Import(byte file[], XWikiContext context) throws IOException, XWikiException { return Import(new ByteArrayInputStream(file), context); }
public boolean add(String docFullName, String language, XWikiContext context) throws XWikiException { return add(docFullName, language, DocumentInfo.ACTION_NOT_DEFINED, context); }
} else if (entry.getName().compareTo(DefaultPackageFileName) == 0) { description = fromXml(new CloseShieldInputStream(zis)); } else { XWikiDocument doc = null; try { doc = readFromXML(new CloseShieldInputStream(zis)); } catch (Throwable ex) { LOG.warn("Failed to parse document [" + entry.getName() + ex.getMessage()); addToErrors(entry.getName().replaceAll("/", "."), context); this.filter(doc, context); docsToLoad.add(doc); } catch (ExcludeDocumentException e) { if (documentExistInPackageFile(doc.getFullName(), doc.getLanguage(), description)) { this.add(doc, context); } else { LOG.warn("document " + doc.getDocumentReference() + " does not exist in package definition." addToSkipped(doc.getFullName(), context); updateFileInfos(description); } catch (DocumentException e) { throw new PackageException(XWikiException.ERROR_XWIKI_UNKNOWN, "Error when reading the XML");
count += readFromDir(file, context, description); } else { boolean validWikiDoc = false; XWikiDocument doc = readFromXML(domdoc); filter(doc, context); if (documentExistInPackageFile(doc.getFullName(), doc.getLanguage(), description)) { add(doc, context);
addToSkipped(doc.getFullName() + ":" + doc.getLanguage(), context); return DocumentInfo.INSTALL_OK; addToErrors(doc.getFullName() + ":" + doc.getLanguage(), context); return DocumentInfo.INSTALL_IMPOSSIBLE; addToErrors(doc.getFullName() + ":" + doc.getLanguage(), context); if (LOG.isErrorEnabled()) { LOG.error("Failed to delete document " + previousdoc.getDocumentReference()); boolean packageHasHistory = this.documentContainsHistory(doc); context.getWiki().saveDocument(doc.getDoc(), saveMessage, context); doc.getDoc().saveAllAttachments(false, true, context); addToInstalled(doc.getFullName() + ":" + doc.getLanguage(), context); addToErrors(doc.getFullName() + ":" + doc.getLanguage(), context); if (LOG.isErrorEnabled()) { LOG.error("Failed to save document " + doc.getFullName(), e);
public String exportToDir(File dir, XWikiContext context) throws IOException, XWikiException { if (!dir.exists()) { if (!dir.mkdirs()) { Object[] args = new Object[1]; args[0] = dir.toString(); throw new XWikiException(XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_MKDIR, "Error creating directory {0}", null, args); } } for (int i = 0; i < this.files.size(); i++) { DocumentInfo docinfo = this.files.get(i); XWikiDocument doc = docinfo.getDoc(); addToDir(doc, dir, this.withVersions, context); } addInfosToDir(dir, context); return ""; }
public String export(OutputStream os, XWikiContext context) throws IOException, XWikiException { if (this.files.size() == 0) { return "No Selected file"; } ZipOutputStream zos = new ZipOutputStream(os); for (int i = 0; i < this.files.size(); i++) { DocumentInfo docinfo = this.files.get(i); XWikiDocument doc = docinfo.getDoc(); addToZip(doc, zos, this.withVersions, context); } addInfosToZip(zos, context); zos.finish(); zos.flush(); return ""; }
public void addDocumentFilter(Object filter) throws PackageException { this.plugin.addDocumentFilter(filter); }
public void backupWiki() throws XWikiException, IOException { this.plugin.addAllWikiDocuments(getXWikiContext()); this.export(); }
public boolean add(XWikiDocument doc, XWikiContext context) throws XWikiException { return add(doc, DocumentInfo.ACTION_NOT_DEFINED, context); }
/** * Load a package in memory from a byte array. It may be installed later using {@link #install()}. * Your should prefer {@link #Import(InputStream, XWikiContext) which may avoid loading the package twice in memory. * * @param file an byte array containing a zipped package file * @return an empty string, useless. * @throws IOException while reading the ZipFile * @throws XWikiException when package content is broken */ public String Import(byte file[]) throws IOException, XWikiException { return this.plugin.Import(file, getXWikiContext()); }
public boolean add(String docFullName, XWikiContext context) throws XWikiException { return add(docFullName, DocumentInfo.ACTION_NOT_DEFINED, context); }
/** * Load a package in memory from an InputStream. It may be installed later using {@link #install()}. * * @param is an InputStream of a zipped package file * @return an empty string, useless. * @throws IOException while reading the ZipFile * @throws XWikiException when package content is broken * @since 2.3M2 */ public String Import(InputStream file) throws IOException, XWikiException { return this.plugin.Import(file, getXWikiContext()); }
public boolean add(String docFullName, int DefaultAction) throws XWikiException { return this.plugin.add(docFullName, DefaultAction, getXWikiContext()); }
/** * Similar to {@link #Import(byte[])}, except expected errors are catch. This version should be privileged * when using the packager API from velocity scripts since it will not display stack-trace in case of error * (for example if the passed file is not a valid package). * * @param data the file to create the package from, as a byte array. * * @return true if the package creation succeeded, false otherwise. If the package creation failed, * the error message is placed in the velocity context under the <code>import_error</code> key, * * @since 2.2M1 */ public boolean importPackageFromByteArray(byte data[]) { try { this.plugin.Import(data, getXWikiContext()); return true; } catch (XWikiException e) { getXWikiContext().put("import_error", e.getMessage()); return false; } catch (IOException e) { getXWikiContext().put("import_error", e.getMessage()); return false; } }
public boolean add(String docFullName) throws XWikiException { return this.plugin.add(docFullName, getXWikiContext()); }
public boolean add(String docFullName, String language, int DefaultAction, XWikiContext context) throws XWikiException { XWikiDocument doc = context.getWiki().getDocument(docFullName, context); if ((language == null) || (language.equals(""))) { add(doc, DefaultAction, context); } else { add(doc.getTranslatedDocument(language, context), DefaultAction, context); } return true; }
public boolean updateDoc(String docFullName, int action, XWikiContext context) throws XWikiException { XWikiDocument doc = new XWikiDocument(); doc.setFullName(docFullName, context); return add(doc, action, context); }
public boolean add(String docFullName, int DefaultAction, XWikiContext context) throws XWikiException { XWikiDocument doc = context.getWiki().getDocument(docFullName, context); add(doc, DefaultAction, context); List<String> languages = doc.getTranslationList(context); for (String language : languages) { if (!((language == null) || (language.equals("")) || (language.equals(doc.getDefaultLanguage())))) { add(doc.getTranslatedDocument(language, context), DefaultAction, context); } } return true; }