Codota Logo
com.manydesigns.portofino.pageactions.text
Code IndexAdd Codota to your IDE (free)

How to use com.manydesigns.portofino.pageactions.text

Best Java code snippets using com.manydesigns.portofino.pageactions.text (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew LinkedList()
  • Codota IconCollections.emptyList()
  • Codota Iconnew ArrayList()
  • Smart code suggestions by Codota
}
origin: com.manydesigns/portofino-pageactions

protected String processContentBeforeView(String content) {
  content = restoreAttachmentUrls(content);
  content = restoreLocalUrls(content);
  return content;
}
origin: com.manydesigns/portofino-pageactions

public Resolution downloadAttachment() {
  return streamAttachment(true);
}
origin: com.manydesigns/portofino-pageactions

  public static Attachment deleteAttachmentByCode(TextConfiguration textConfiguration, String code) {
    Attachment attachment = findAttachmentById(textConfiguration, code);
    if (attachment == null) {
      return null;
    } else {
      textConfiguration.getAttachments().remove(attachment);
      return attachment;
    }
  }
}
origin: com.manydesigns/portofino-pageactions

@Button(list = "manage-attachments", key = "ok", order = 1, type = Button.TYPE_PRIMARY)
@RequiresPermissions(level = AccessLevel.VIEW, permissions = { PERMISSION_EDIT })
public Resolution saveAttachments() {
  if(downloadable == null) {
    downloadable = new String[0];
  }
  if(textConfiguration == null) {
    textConfiguration = new TextConfiguration();
  }
  for(Attachment attachment : textConfiguration.getAttachments()) {
    boolean contained = ArrayUtils.contains(downloadable, attachment.getId());
    attachment.setDownloadable(contained);
  }
  saveConfiguration(textConfiguration);
  return cancel();
}
origin: com.manydesigns/portofino-pageactions

protected void commonUploadAttachment() throws IOException {
  logger.debug("Uploading attachment");
  viewAttachmentUrl = null;
  InputStream attachmentStream = upload.getInputStream();
  String attachmentId = RandomUtil.createRandomId();
  File dataFile = RandomUtil.getCodeFile(
      pageInstance.getDirectory(), ATTACHMENT_FILE_NAME_PATTERN, attachmentId);
  // copy the data
  FileOutputStream fileOutputStream = new FileOutputStream(dataFile);
  IOUtils.copyLarge(attachmentStream, fileOutputStream);
  if(textConfiguration == null) {
    textConfiguration = new TextConfiguration();
  }
  Attachment attachment = TextLogic.createAttachment(
      textConfiguration, attachmentId,
      upload.getFileName(), upload.getContentType(),
      upload.getSize());
  attachment.setDownloadable(uploadDownloadable);
  viewAttachmentUrl =
      generateViewAttachmentUrl(attachmentId);
  saveConfiguration(textConfiguration);
  logger.info("Attachment uploaded: " + upload.getFileName() + " (" + attachmentId + ")");
  IOUtils.closeQuietly(attachmentStream);
  IOUtils.closeQuietly(fileOutputStream);
  upload.delete();
  logger.debug("Upload resources cleaned");
}
origin: com.manydesigns/portofino-pageactions

@Button(list = "configuration", key = "update.configuration", order = 1, type = Button.TYPE_PRIMARY)
@RequiresPermissions(level = AccessLevel.DEVELOP)
@RequiresAuthentication
public Resolution updateConfiguration() throws IOException {
  prepareConfigurationForms();
  readPageConfigurationFromRequest();
  boolean valid = validatePageConfiguration();
  if (valid) {
    updatePageConfiguration();
    SessionMessages.addInfoMessage(ElementsThreadLocals.getText("configuration.updated.successfully"));
    return cancel();
  } else {
    return new ForwardResolution("/m/pageactions/text/configure.jsp");
  }
}
origin: com.manydesigns/portofino-pageactions

  public List<Attachment> getDownloadableAttachments() {
    List<Attachment> downloadableAttachments = new ArrayList<Attachment>();
    for(Attachment attachment : getTextConfiguration().getAttachments()) {
      if(attachment.isDownloadable()) {
        downloadableAttachments.add(attachment);
      }
    }
    return downloadableAttachments;
  }
}
origin: com.manydesigns/portofino-pageactions

/**
 * Processes the content before saving it, in order to encode internal links and attachments, and
 * removing potentially problematic characters.
 * @param content the original content.
 * @return the processed content.
 */
protected String processContentBeforeSave(String content) {
  content = processAttachmentUrls(content);
  content = processLocalUrls(content);
  content = Util.replaceBadUnicodeCharactersWithHtmlEntities(content);
  return content;
}
origin: com.manydesigns/portofino-pageactions

/**
 * Loads the content of the page from a file (see {@link TextAction#locateTextFile()}).
 * Assigns the {@link TextAction#content} field.
 * @throws IOException if there's a problem loading the content.
 */
protected void loadContent() throws IOException {
  textFile = locateTextFile();
  try {
    content = FileUtils.readFileToString(textFile, CONTENT_ENCODING);
    content = processContentBeforeView(content);
  } catch (FileNotFoundException e) {
    content = EMPTY_STRING;
    logger.debug("Content file not found. Content set to empty.", e);
  }
}
origin: com.manydesigns/portofino-pageactions

/**
 * Saves the content of the page to a file (see {@link TextAction#locateTextFile()}).
 * @throws IOException if there's a problem saving the content.
 */
protected void saveContent() throws IOException {
  if (content == null) {
    content = EMPTY_STRING;
  }
  content = processContentBeforeSave(content);
  byte[] contentByteArray = content.getBytes(CONTENT_ENCODING);
  textFile = locateTextFile();
  // copy the data
  FileOutputStream fileOutputStream = new FileOutputStream(textFile);
  try {
    long size = IOUtils.copyLarge(
        new ByteArrayInputStream(contentByteArray), fileOutputStream);
  } catch (IOException e) {
    logger.error("Could not save content", e);
    throw e;
  } finally {
    fileOutputStream.close();
  }
  logger.info("Content saved to: {}", textFile.getAbsolutePath());
}
origin: com.manydesigns/portofino-pageactions

@GET
@Produces(MediaType.TEXT_HTML)
public Response downloadContent() {
  try {
    loadContent();
    return Response.ok(content).build();
  } catch (IOException e) {
    logger.error("Could not load content", e);
    return Response.serverError().entity(e).build();
  }
}
origin: com.manydesigns/portofino-pageactions

@RequiresPermissions(level = AccessLevel.VIEW, permissions = { PERMISSION_EDIT })
@RequiresAuthentication
public Resolution uploadAttachmentFromCKEditor() {
  try {
    uploadDownloadable = false;
    commonUploadAttachment();
    message = null;
  } catch (IOException e) {
    message = "File upload failed!";
    logger.error("Upload failed", e);
  }
  return new ForwardResolution(
      "/m/pageactions/text/upload-attachment.jsp");
}
origin: com.manydesigns/portofino-pageactions

protected String processAttachmentUrls(String content) {
  String baseUrl = StringEscapeUtils.escapeHtml(generateViewAttachmentUrl("").replace("?", "\\?"));
  String patternString = "([^\\s\"]+)\\s*=\\s*\"\\s*" + baseUrl + "([^\"]+)\"";
  Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
  Matcher matcher = pattern.matcher(content);
  int lastEnd = 0;
  StringBuilder sb = new StringBuilder();
  while (matcher.find()) {
    String hrefAttribute = matcher.group(1);
    String attachmentId = matcher.group(2);
    sb.append(content.substring(lastEnd, matcher.start()));
    sb.append("portofino:attachment=\"").append(attachmentId).append("\" ");
    sb.append("portofino:hrefAttribute=\"").append(hrefAttribute).append("\"");
    lastEnd = matcher.end();
  }
  sb.append(content.substring(lastEnd));
  return sb.toString();
}
origin: com.manydesigns/portofino-pageactions

/**
 * Computes the File object used to store this page's content. The default implementation
 * looks for a file with a fixed name in this page's directory, computed by calling
 * {@link TextAction#computeTextFileName()}.
 * @see TextAction#computeTextFileName()
 * @return the document File.
 */
protected File locateTextFile() {
  return new File(pageInstance.getDirectory(), computeTextFileName());
}
origin: com.manydesigns/portofino-pageactions

@Button(list = "pageHeaderButtons", titleKey = "configure", order = 1, icon = Button.ICON_WRENCH,
    group = "pageHeaderButtons")
@RequiresPermissions(level = AccessLevel.EDIT)
@RequiresAuthentication
public Resolution configurePage() {
  prepareConfigurationForms();
  return new ForwardResolution("/m/pageactions/text/configure.jsp");
}
origin: ManyDesigns/Portofino

  public static Attachment deleteAttachmentByCode(TextConfiguration textConfiguration, String code) {
    Attachment attachment = findAttachmentById(textConfiguration, code);
    if (attachment == null) {
      return null;
    } else {
      textConfiguration.getAttachments().remove(attachment);
      return attachment;
    }
  }
}
origin: com.manydesigns/portofino-pageactions

public Resolution viewAttachment() {
  return streamAttachment(false);
}
origin: com.manydesigns/portofino-pageactions

@DefaultHandler
public Resolution execute() throws IOException {
  loadContent();
  if (StringUtils.isEmpty(content)) {
    content = "<em>Empty content. To add content, configure this page.</em>";
  }
  return new ForwardResolution("/m/pageactions/text/read.jsp");
}
origin: com.manydesigns/portofino-pageactions

@Button(list = "manage-attachments-upload", key = "text.attachment.upload", order = 1 , icon=Button.ICON_UPLOAD )
@RequiresPermissions(level = AccessLevel.VIEW, permissions = { PERMISSION_EDIT })
@RequiresAuthentication
public Resolution uploadAttachment() {
  if (upload == null) {
    SessionMessages.addWarningMessage(ElementsThreadLocals.getText("text.attachment.noFileSelected"));
  } else {
    try {
      commonUploadAttachment();
      SessionMessages.addInfoMessage(ElementsThreadLocals.getText("text.attachment.uploadSuccessful"));
    } catch (IOException e) {
      logger.error("Upload failed", e);
      SessionMessages.addErrorMessage(ElementsThreadLocals.getText("text.attachment.uploadFailed"));
    }
  }
  return new RedirectResolution(context.getActionPath())
      .addParameter("manageAttachments")
      .addParameter("returnUrl", returnUrl);
}
origin: com.manydesigns/portofino-pageactions

protected String restoreAttachmentUrls(String content) {
  Pattern pattern = Pattern.compile(PORTOFINO_ATTACHMENT_PATTERN);
  Matcher matcher = pattern.matcher(content);
  int lastEnd = 0;
  StringBuilder sb = new StringBuilder();
  while (matcher.find()) {
    String attachmentId = matcher.group(1);
    //Default to src for old texts
    String hrefAttribute =
        (matcher.groupCount() >= 3 && matcher.group(3) != null) ? matcher.group(3) : "src";
    sb.append(content.substring(lastEnd, matcher.start()))
     .append(hrefAttribute).append("=\"")
     .append(StringEscapeUtils.escapeHtml(generateViewAttachmentUrl(attachmentId)))
     .append("\"");
    lastEnd = matcher.end();
  }
  sb.append(content.substring(lastEnd));
  return sb.toString();
}
com.manydesigns.portofino.pageactions.text

Most used classes

  • TextLogic
  • Attachment
  • TextConfiguration
  • TextAction
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now