private static StructuredName makeStructuredName( String givenName, String familyName, @Nullable String sourceType) { StructuredName structuredName = new StructuredName(); structuredName.setGiven(givenName); structuredName.setFamily(familyName); if (sourceType != null) { structuredName.setParameter(SOURCE_PARAM_NAME_TYPE, sourceType); } return structuredName; }
/** * Exports a Site. * * @param host host serving the site * @param domain the domain of the site, if not the default * @param webspace the webspace (name) of the site * @param exportRevisions whether or not to export page's revisions * @param sitesService SitesService with which to access the site * @param rootDirectory directory in which to export * @param progressListener ProgressListener to monitor progress on the export */ void exportSite(String host, @Nullable String domain, String webspace, boolean exportRevisions, SitesService sitesService, File rootDirectory, ProgressListener progressListener); }
/** * Imports a Site. * * @param host host serving the site * @param domain the domain of the site, if not the default * @param webspace the webspace (name) of the site * @param importRevisions whether or not to import revisions * @param sitesService SitesService with which to access the site * @param rootDirectory directory in which to export * @param progressListener ProgressListener to monitor import progress */ public void importSite(String host, @Nullable String domain, String webspace, boolean importRevisions, SitesService sitesService, File rootDirectory, ProgressListener progressListener); }
/** * Returns the site URL corresponding to the given host, domain, and webspace. */ public static URL getSiteUrl(String host, @Nullable String domain, String webspace) { try { if (domain == null) { return new URL("https://" + host + "/site/" + webspace); } else { return new URL("https://" + host + "/a/" + domain + "/" + webspace); } } catch (MalformedURLException e) { LOGGER.log(Level.WARNING, "Invalid host, domain, or webspace!"); throw new RuntimeException(e); } }
/** * Returns the feed URL corresponding to the given host, domain, and webspace. */ public static URL getFeedUrl(String host, @Nullable String domain, String webspace) { try { if (domain == null) { return new URL("https://" + host + "/feeds/content/site/" + webspace); } else { return new URL("https://" + host + "/feeds/content/" + domain + "/" + webspace); } } catch (MalformedURLException e) { LOGGER.log(Level.WARNING, "Invalid host, domain, or webspace!"); throw new RuntimeException(e); } } }
@Override public void importSite(String host, @Nullable String domain, String webspace, boolean importRevisions, SitesService sitesService, File rootDirectory, ProgressListener progressListener) { URL feedUrl = UrlUtils.getFeedUrl(host, domain, webspace); URL siteUrl = UrlUtils.getSiteUrl(host, domain, webspace); progressListener.setStatus("Scanning directory."); int numPages = getNumPages(rootDirectory); List<BasePageEntry<?>> ancestors = Lists.newLinkedList(); for (File subDirectory : rootDirectory.listFiles()) { if (subDirectory.isDirectory() && !subDirectory.getName().startsWith("_")) { importPage(subDirectory, importRevisions, ancestors, feedUrl, siteUrl, sitesService, progressListener, numPages); } } progressListener.setProgress(1.0); progressListener.setStatus("Import complete."); }
@Override public void exportSite(String host, @Nullable String domain, String webspace, boolean exportRevisions, SitesService sitesService, File rootDirectory, ProgressListener progressListener) {
@Override public XmlElement renderList(ListPageEntry entry, @Nullable List<ListItemEntry> listItems) { XmlElement table = new XmlElement("table").setAttribute("border", "1"); XmlElement header = new XmlElement("tr").setAttribute("class", "gs:data"); for (Column col : entry.getData().getColumns()) { XmlElement cell = new XmlElement("th"); cell.setAttribute("class", "gs:column"); cell.setAttribute("title", col.getIndex()); cell.addText(col.getName()); header.addElement(cell); } XmlElement authorCell = new XmlElement("th"); header.addElement(authorCell.addText("Author")); XmlElement updatedCell = new XmlElement("th"); header.addElement(updatedCell.addText("Updated")); XmlElement revisionCell = new XmlElement("th"); header.addElement(revisionCell.addText("Version")); table.addElement(header); if (listItems != null) { for (ListItemEntry item : listItems) { table.addElement(getRow(item)); } } return table; }