Package net.java.textilej.parser

Examples of net.java.textilej.parser.ImageAttributes


    @Override
    public void emit() {
      String imageUrl = group(1);
      String optionsString = group(2);

      ImageAttributes attributes = new ImageAttributes();
      if (optionsString != null) {
        String[] options = optionsString.split("\\s*\\|\\s*");
        for (String option: options) {
          if ("center".equals(option)) {
            attributes.setAlign(Align.Middle);
          } else if ("left".equals(option)) {
            attributes.setAlign(Align.Left);
          } else if ("right".equals(option)) {
            attributes.setAlign(Align.Right);
          } else if ("none".equals(option)) {
            attributes.setAlign(null);
          } else if ("thumb".equals(option)||"thumbnail".equals(option)) {
            // ignore
          } else if (option.matches("\\d+px")) {
            try {
              int size = Integer.parseInt(option.substring(0,option.length()-2));
              attributes.setWidth(size);
              attributes.setHeight(size);
            } catch (NumberFormatException e) {
              // ignore
            }
          } else if ("frameless".equals(option)) {
            attributes.setBorder(0);
          } else if ("frame".equals(option)) {
            attributes.setBorder(1);
          } else {
            attributes.setTitle(option);
          }
        }
      }
      builder.image(attributes, imageUrl);
    }
View Full Code Here


 
  private void applyImageAttributes(Attributes attributes) {
    int border = 0;
    Align align = null;
    if (attributes instanceof ImageAttributes) {
      ImageAttributes imageAttributes = (ImageAttributes) attributes;
      border = imageAttributes.getBorder();
      align = imageAttributes.getAlign();
    }
    if (xhtmlStrict) {
      String borderStyle = String.format("border-width: %spx;",border);
      String alignStyle = null;
      if (align != null) {
        switch (align) {
        case Center:
        case Right:
        case Left:
          alignStyle = "text-align: "+align.name().toLowerCase()+";";
          break;
        case Bottom:
        case Baseline:
        case Top:
        case Middle:
          alignStyle = "vertical-align: "+align.name().toLowerCase()+";";
          break;
        case Texttop:
          alignStyle = "vertical-align: text-top;";
          break;
        case Absmiddle:
          alignStyle = "vertical-align: middle;";
          break;
        case Absbottom:
          alignStyle = "vertical-align: bottom;";
          break;
        }
      }
      String additionalStyles = borderStyle;
      if (alignStyle != null) {
        additionalStyles += alignStyle;
      }
      if (attributes.getCssStyle() == null || attributes.getCssStyle().length() == 0) {
        attributes.setCssStyle(additionalStyles);
      } else {
        attributes.setCssStyle(additionalStyles+attributes.getCssStyle());
      }
    }
    applyAttributes(attributes);
    boolean haveAlt = false;
   
    if (attributes instanceof ImageAttributes) {
      ImageAttributes imageAttributes = (ImageAttributes) attributes;
      if (imageAttributes.getHeight() != -1) {
        writer.writeAttribute("height", Integer.toString(imageAttributes.getHeight()));
      }
      if (imageAttributes.getWidth() != -1) {
        writer.writeAttribute("width", Integer.toString(imageAttributes.getWidth()));
      }
      if (!xhtmlStrict && align != null) {
        writer.writeAttribute("align", align.name().toLowerCase());
      }
      if (imageAttributes.getAlt() != null) {
        haveAlt = true;
        writer.writeAttribute("alt", imageAttributes.getAlt());
      }
    }
    if (attributes.getTitle() != null) {
      writer.writeAttribute("title", attributes.getTitle());
      if (!haveAlt) {
View Full Code Here

      }
     
      if (hyperlinkBoundaryText.equals("\"")) {
        builder.link(href, hyperlinkSrc);
      } else {
        builder.imageLink(new ImageAttributes(),href, hyperlinkSrc);
      }
    }
View Full Code Here

      String namedLinkUrl = href==null?null:((TextileContentState)getState()).getNamedLinkUrl(href);
      if (namedLinkUrl != null) {
        href = namedLinkUrl;
      }
     
      ImageAttributes attributes = new ImageAttributes();
      attributes.setTitle(altAndTitle);
      attributes.setAlt(altAndTitle);
      if (alignment != null) {
        if ("<".equals(alignment)) {
          attributes.setAlign(Align.Left);
        } else if (">".equals(alignment)) {
          attributes.setAlign(Align.Right);
        } else if ("=".equals(alignment)) {
          attributes.setAlign(Align.Center);
        }
      }
      Textile.configureAttributes(this, attributes, ATTRIBUTES_OFFSET,false);
      if (href != null) {
        builder.imageLink(attributes, href, imageUrl);
View Full Code Here

TOP

Related Classes of net.java.textilej.parser.ImageAttributes

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.