Java Code Examples for javax.swing.text.html.HTML#Tag

The following examples show how to use javax.swing.text.html.HTML#Tag . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HtmlRichTextConverter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private HTML.Tag findTag( final AttributeSet attr ) {
  final Enumeration names = attr.getAttributeNames();
  while ( names.hasMoreElements() ) {
    final Object name = names.nextElement();
    final Object o = attr.getAttribute( name );
    if ( o instanceof HTML.Tag ) {
      if ( HTML.Tag.CONTENT == o ) {
        continue;
      }
      if ( HTML.Tag.COMMENT == o ) {
        continue;
      }
      return (HTML.Tag) o;
    }
  }
  return null;
}
 
Example 2
Source File: HtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** This method analizes the tag t and adds some \n chars and spaces to the
  * tmpDocContent.The reason behind is that we need to have a readable form
  * for the final document. This method modifies the content of tmpDocContent.
  * @param t the Html tag encounted by the HTML parser
  */
protected void customizeAppearanceOfDocumentWithStartTag(HTML.Tag t){
  boolean modification = false;
  if (HTML.Tag.P == t){
    int tmpDocContentSize = tmpDocContent.length();
    if ( tmpDocContentSize >= 2 &&
         '\n' != tmpDocContent.charAt(tmpDocContentSize - 2)
       ) { tmpDocContent.append("\n"); modification = true;}
  }// End if
  if (modification == true){
    Long end = new Long (tmpDocContent.length());
    Iterator<CustomObject> anIterator = stack.iterator();
    while (anIterator.hasNext ()){
      // get the object and move to the next one
      CustomObject obj = anIterator.next();
      // sets its End index
      obj.setEnd(end);
    }// End while
  }//End if
}
 
Example 3
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public ViewFactory getViewFactory() {
  return new HTMLEditorKit.HTMLFactory() {
    @Override public View create(Element elem) {
      View view = super.create(elem);
      if (view instanceof LabelView) {
        System.out.println("debug: " + view.getAlignment(View.Y_AXIS));
      }
      AttributeSet attrs = elem.getAttributes();
      Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
      Object o = Objects.nonNull(elementName) ? null : attrs.getAttribute(StyleConstants.NameAttribute);
      if (o instanceof HTML.Tag) {
        HTML.Tag kind = (HTML.Tag) o;
        if (kind == HTML.Tag.IMG) {
          return new ImageView(elem) {
            @Override public float getAlignment(int axis) {
              // .8125f magic number...
              return axis == View.Y_AXIS ? .8125f : super.getAlignment(axis);
            }
          };
        }
      }
      return view;
    }
  };
}
 
Example 4
Source File: DodsURLExtractor.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void handleStartTag(HTML.Tag tag, MutableAttributeSet attributes, int position) {
  isTitle = (tag == HTML.Tag.TITLE);

  // System.out.println(" "+tag);
  if (wantURLS && tag == HTML.Tag.A)
    extractHREF(attributes);
}
 
Example 5
Source File: ButtonsHTMLParser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void handleEndTag(HTML.Tag t, int pos) {
    String tag = t.toString();
    logger.log(Level.FINE, "EndTag <{0}>", tag);
    if (TAG_TITLE.equalsIgnoreCase(tag)) {
        readingTitle = false;
    }
    if (TAG_FORM.equalsIgnoreCase(tag)) {
        readingForm = false;
    }
}
 
Example 6
Source File: HtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** This method is called when the HTML parser encounts an empty tag
  */
@Override
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos){
  // fire the status listener if the elements processed exceded the rate
  if ((++elements % ELEMENTS_RATE) == 0)
    fireStatusChangedEvent("Processed elements : " + elements);

  // construct a feature map from the attributes list
  // these are empty elements
  FeatureMap fm = Factory.newFeatureMap();

  // take all the attributes an put them into the feature map
  if (0 != a.getAttributeCount ()){

     // Out.println("HAS  attributes = " + a.getAttributeCount ());
      Enumeration<?> enumeration = a.getAttributeNames ();
      while (enumeration.hasMoreElements ()){
        Object attribute = enumeration.nextElement ();
        fm.put ( attribute.toString(),(a.getAttribute(attribute)).toString());

      }//while

  }//if

  // create the start index of the annotation
  Long startIndex = new Long(tmpDocContent.length());

  // initialy the start index is equal with the End index
  CustomObject obj = new CustomObject(t.toString(),fm,startIndex,startIndex);

  // we add the object directly into the colector
  // we don't add it to the stack because this is an empty tag
  colector.add(obj);

  // Just analize the tag t and add some\n chars and spaces to the
  // tmpDocContent.The reason behind is that we need to have a readable form
  // for the final document.
  customizeAppearanceOfDocumentWithSimpleTag(t);

}
 
Example 7
Source File: AnalizeWebParse.java    From howsun-javaee-framework with Apache License 2.0 5 votes vote down vote up
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
	if (t == HTML.Tag.IMG) {
		// get a src
		String src = (String) a.getAttribute(HTML.Attribute.SRC);
		if (src == null) {
			return;
		}

		if (Pattern.matches(regex, src)) {
			imgs.add(src);
		}
	}
}
 
Example 8
Source File: HTMLTextArea.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
protected boolean isSupportedBreakFlowTag(AttributeSet attr) {
    Object o = attr.getAttribute(StyleConstants.NameAttribute);

    if (o instanceof HTML.Tag) {
        HTML.Tag tag = (HTML.Tag) o;

        if ((tag == HTML.Tag.HTML) || (tag == HTML.Tag.HEAD) || (tag == HTML.Tag.BODY) || (tag == HTML.Tag.HR)) {
            return false;
        }

        return (tag).breaksFlow();
    }

    return false;
}
 
Example 9
Source File: HTMLPanel.java    From littleluck with Apache License 2.0 5 votes vote down vote up
@Override
public View create(Element element) {
    AttributeSet attrs = element.getAttributes();
    Object elementName =
            attrs.getAttribute(AbstractDocument.ElementNameAttribute);
    Object o = (elementName != null) ?
            null : attrs.getAttribute(StyleConstants.NameAttribute);
    if (o instanceof HTML.Tag) {
        if (o == HTML.Tag.OBJECT) {
            return new ComponentView(element);
        }
    }
    return super.create(element);
}
 
Example 10
Source File: Html2Text.java    From ObjectLogger with Apache License 2.0 5 votes vote down vote up
@Override
public void handleEndTag(HTML.Tag t, int pos) {
    if (stringBuilder.length() != 0
            && t.isBlock()
            && !stringBuilder.toString().endsWith(lineBreak)) {
        stringBuilder.append(lineBreak);
    }
}
 
Example 11
Source File: Html2Text.java    From ObjectLogger with Apache License 2.0 5 votes vote down vote up
@Override
public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
    if (stringBuilder.length() != 0
            && t.isBlock()
            && !stringBuilder.toString().endsWith(lineBreak)) {
        stringBuilder.append(lineBreak);
    }
}
 
Example 12
Source File: DodsURLExtractor.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet attributes, int position) {
  isTitle = false; // (tag == HTML.Tag.TITLE); // ??

  // System.out.println(" "+tag);
  if (wantURLS && tag == HTML.Tag.A)
    extractHREF(attributes);
}
 
Example 13
Source File: bug7165725.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
    elist.add(pIndent() + "Tag(<" + t.toString() + ">, " +
            a.getAttributeCount() + " attrs)");
}
 
Example 14
Source File: bug7165725.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void handleEndTag(HTML.Tag t, int pos) {
    unIndent();
    elist.add(pIndent() + "Tag end(</" + t.toString() + ">)");
}
 
Example 15
Source File: bug7165725.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) {
    elist.add(pIndent() + "Tag(<" + t.toString() + ">, " +
            a.getAttributeCount() + " attrs)");
}
 
Example 16
Source File: bug7165725.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void handleEndTag(HTML.Tag t, int pos) {
    unIndent();
    elist.add(pIndent() + "Tag end(</" + t.toString() + ">)");
}
 
Example 17
Source File: HtmlDocumentHandler.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/** This method is called when the HTML parser encounts the end of a tag
     * that means that the tag is paired by a beginning tag
     */
  @Override
  public void handleEndTag(HTML.Tag t, int pos){
    // obj is for internal use
    CustomObject obj = null;

    // end of STYLE tag
    if(HTML.Tag.STYLE.equals(t)) {
      isInsideStyleTag = false;
    } // if

    // If the stack is not empty then we get the object from the stack
    if (!stack.isEmpty()){
      obj = stack.pop();
      // Before adding it to the colector, we need to check if is an
      // emptyAndSpan one. See CustomObject's isEmptyAndSpan field.
      if (obj.getStart().equals(obj.getEnd())){
        // The element had an end tag and its start was equal to its end. Hence
        // it is anEmptyAndSpan one.
        obj.getFM().put("isEmptyAndSpan","true");
      }// End iff
      // we add it to the colector
      colector.add(obj);
    }// End if

    // If element has text between, then customize its apearance
    if ( obj != null &&
         obj.getStart().longValue() != obj.getEnd().longValue()
       )
      // Customize the appearance of the document
      customizeAppearanceOfDocumentWithEndTag(t);

    // if t is the </HTML> tag then we reached the end of theHTMLdocument
    if (t == HTML.Tag.HTML){
      // replace the old content with the new one
      doc.setContent (new DocumentContentImpl(tmpDocContent.toString()));

      // If basicAs is null then get the default annotation
      // set from this gate document
      if (basicAS == null)
        basicAS = doc.getAnnotations(
                                GateConstants.ORIGINAL_MARKUPS_ANNOT_SET_NAME);

      // sort colector ascending on its id
      Collections.sort(colector);
      // iterate through colector and construct annotations
      while (!colector.isEmpty()){
        obj = colector.getFirst();
        colector.remove(obj);
          // Construct an annotation from this obj
          try{
            if (markupElementsMap == null){
               basicAS.add( obj.getStart(),
                            obj.getEnd(),
                            obj.getElemName(),
                            obj.getFM()
                           );
            }else{
              String annotationType =
                     markupElementsMap.get(obj.getElemName());
              if (annotationType != null)
                 basicAS.add( obj.getStart(),
                              obj.getEnd(),
                              annotationType,
                              obj.getFM()
                             );
            }
          }catch (InvalidOffsetException e){
              Err.prln("Error creating an annot :" + obj + " Discarded...");
          }// end try
//        }// end if
      }//while

      // notify the listener about the total amount of elements that
      // has been processed
      fireStatusChangedEvent("Total elements : " + elements);

    }//else

  }
 
Example 18
Source File: TagElement.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public HTML.Tag getHTMLTag() {
    return htmlTag;
}
 
Example 19
Source File: bug7165725.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void handleEndTag(HTML.Tag t, int pos) {
    unIndent();
    elist.add(pIndent() + "Tag end(</" + t.toString() + ">)");
}
 
Example 20
Source File: bug7165725.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
    elist.add(pIndent() + "Tag start(<" + t.toString() + " " + a + ">, " +
            a.getAttributeCount() + " attrs)");
    indent();
}