Example usage for org.xml.sax Attributes getLength

List of usage examples for org.xml.sax Attributes getLength

Introduction

In this page you can find the example usage for org.xml.sax Attributes getLength.

Prototype

public abstract int getLength();

Source Link

Document

Return the number of attributes in the list.

Usage

From source file:ExampleContentHandler.java

public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
        throws SAXException {
    System.out.print("startElement: " + namespaceURI + ", " + localName + ", " + qName);
    int n = atts.getLength();
    for (int i = 0; i < n; i++) {
        System.out.print(", " + atts.getQName(i));
    }/*  w  w  w .j  a  v  a 2 s.  c  o m*/
    System.out.println("");
}

From source file:es.mityc.firmaJava.libreria.utilidades.AnalizadorFicheroFirma.java

public void startElement(String espacioNombres, String nomLocal, String nomCompleto, Attributes atrs) {
    String id = null;/*from   w w w . j  a  va 2s  .c om*/
    int longitud = atrs.getLength();
    for (int i = 0; i < longitud; i++) {
        if (ID.equals(atrs.getLocalName(i))) {
            id = atrs.getValue(i);
        }
    }
    if ((PARTS.equals(nomLocal)) && (PARTS.equals(nomCompleto))) {
        procesando = true;
        try {
            File fichero = File.createTempFile(id + GUION, GUION_TEMPORAL);
            ficheros.add(fichero);
            os = new FileOutputStream(fichero);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

From source file:net.ontopia.xml.CanonicalPrinter.java

@Override
public void startElement(String uri, String localName, String name, Attributes atts) {
    // first: sort attributes
    String[] attNames = new String[atts.getLength()];
    for (int i = 0; i < atts.getLength(); i++) {
        attNames[i] = atts.getQName(i);/*from   w  ww  .j  a va  2 s . co  m*/
    }
    java.util.Arrays.sort(attNames);

    // then write it out in sorted order
    writer.print("<" + name);
    for (int i = 0; i < attNames.length; i++)
        writer.print(" " + attNames[i] + "=\"" + escape(atts.getValue(attNames[i])) + "\"");
    writer.print(">");
}

From source file:net.bible.service.format.osistohtml.TitleHandler.java

public void start(Attributes attrs) {
    //JSword adds the chapter no at the top but hide this because the chapter is in the And Bible header
    boolean addedByJSword = attrs.getLength() == 1
            && OSISUtil.GENERATED_CONTENT.equals(attrs.getValue(OSISUtil.OSIS_ATTR_TYPE));
    // otherwise show if user wants Titles or the title is canonical
    isShowTitle = !addedByJSword && (parameters.isShowTitles()
            || "true".equalsIgnoreCase(attrs.getValue(OSISUtil.OSIS_ATTR_CANONICAL)));

    if (isShowTitle) {
        // ESV has subType butNETtext has lower case subtype so concatenate both and search with contains() 
        String subtype = attrs.getValue(OSISUtil.OSIS_ATTR_SUBTYPE)
                + attrs.getValue(OSISUtil.OSIS_ATTR_SUBTYPE.toLowerCase());
        isMoveBeforeVerse = StringUtils.containsIgnoreCase(subtype, PREVERSE)
                || (!verseInfo.isTextSinceVerse && verseInfo.currentVerseNo > 0);
        if (isMoveBeforeVerse) {
            // section Titles normally come before a verse, so overwrite the, already written verse, which is rewritten on writer.finishedInserting
            writer.beginInsertAt(verseInfo.positionToInsertBeforeVerse);
        }/* w w w. java 2s  .  c  om*/

        // get title type from level
        String titleClass = "heading" + TagHandlerHelper.getAttribute(OSISUtil.OSIS_ATTR_LEVEL, attrs, "1");

        writer.write("<h1 class='" + titleClass + "'>");
    } else {
        writer.setDontWrite(true);
    }
}

From source file:com.bellman.bible.service.format.osistohtml.taghandler.TitleHandler.java

@Override
public void start(Attributes attrs) {
    //JSword adds the chapter no at the top but hide this because the chapter is in the Embedded Bible header
    boolean addedByJSword = attrs.getLength() == 1
            && OSISUtil.GENERATED_CONTENT.equals(attrs.getValue(OSISUtil.OSIS_ATTR_TYPE));
    // otherwise show if user wants Titles or the title is canonical
    isShowTitle = !addedByJSword && (parameters.isShowTitles()
            || "true".equalsIgnoreCase(attrs.getValue(OSISUtil.OSIS_ATTR_CANONICAL)));

    if (isShowTitle) {
        // ESV has subType butcom.bellmantext has lower case subtype so concatenate both and search with contains()
        String subtype = attrs.getValue(OSISUtil.OSIS_ATTR_SUBTYPE)
                + attrs.getValue(OSISUtil.OSIS_ATTR_SUBTYPE.toLowerCase(Locale.ENGLISH));
        isMoveBeforeVerse = (StringUtils.containsIgnoreCase(subtype, PREVERSE)
                || (!verseInfo.isTextSinceVerse && verseInfo.currentVerseNo > 0));
        if (isMoveBeforeVerse) {
            // section Titles normally come before a verse, so overwrite the, already written verse, which is rewritten on writer.finishedInserting
            writer.beginInsertAt(verseInfo.positionToInsertBeforeVerse);
        }//w ww. ja  v  a  2s .c  om

        // get title type from level
        String titleClass = "heading" + TagHandlerHelper.getAttribute(OSISUtil.OSIS_ATTR_LEVEL, attrs, "1");

        writer.write("<h1 class='" + titleClass + "'>");
    } else {
        writer.setDontWrite(true);
    }
}

From source file:net.bible.service.format.osistohtml.taghandler.TitleHandler.java

@Override
public void start(Attributes attrs) {
    //JSword adds the chapter no at the top but hide this because the chapter is in the And Bible header
    boolean addedByJSword = attrs.getLength() == 1
            && OSISUtil.GENERATED_CONTENT.equals(attrs.getValue(OSISUtil.OSIS_ATTR_TYPE));
    // otherwise show if user wants Titles or the title is canonical
    isShowTitle = !addedByJSword && (parameters.isShowTitles()
            || "true".equalsIgnoreCase(attrs.getValue(OSISUtil.OSIS_ATTR_CANONICAL)));

    if (isShowTitle) {
        // ESV has subType butNETtext has lower case subtype so concatenate both and search with contains() 
        String subtype = attrs.getValue(OSISUtil.OSIS_ATTR_SUBTYPE)
                + attrs.getValue(OSISUtil.OSIS_ATTR_SUBTYPE.toLowerCase(Locale.ENGLISH));
        isMoveBeforeVerse = (StringUtils.containsIgnoreCase(subtype, PREVERSE)
                || (!verseInfo.isTextSinceVerse && verseInfo.currentVerseNo > 0));
        if (isMoveBeforeVerse) {
            // section Titles normally come before a verse, so overwrite the, already written verse, which is rewritten on writer.finishedInserting
            writer.beginInsertAt(verseInfo.positionToInsertBeforeVerse);
        }//w ww  .ja va2s.c  o  m

        // get title type from level
        String titleClass = "heading" + TagHandlerHelper.getAttribute(OSISUtil.OSIS_ATTR_LEVEL, attrs, "1");

        writer.write("<h1 class='" + titleClass + "'>");
    } else {
        writer.setDontWrite(true);
    }
}

From source file:net.ontopia.xml.ContentWriter.java

@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
        throws SAXException {
    try {//from   w ww .  ja v  a2s.c o  m
        out.write("<" + localName);
        if (atts != null) {
            for (int i = 0; i < atts.getLength(); i++)
                out.write(" " + atts.getQName(i) + "=\"" + escape(atts.getValue(i)) + "\"");
        }
        out.write('>');
    } catch (IOException e) {
        throw new SAXException(e);
    }

    content = false;
}

From source file:io.lightlink.excel.CopyingTemplateHandler.java

protected void printElementStart(String eName, Attributes attrs) throws SAXException {
    emit("\n<" + eName);

    if (attrs != null) {
        for (int i = 0; i < attrs.getLength(); i++) {
            String aName = attrs.getLocalName(i); // Attr name

            if ("".equals(aName)) {
                aName = attrs.getQName(i);
            }//from   www .  jav a2 s  . c o m

            emit(" " + aName + "=\"" + attrs.getValue(i) + "\"");
        }
    }

    emit(">");
}

From source file:SAXCopy.java

public void startElement(String namespaceURI, String localName, String qName, Attributes atts) {
    System.out.println("<" + qName);
    if (namespaceBegin) {
        System.out.print(" xmlns:" + currentNamespace + "=\"" + currentNamespaceUri + "\"");
        namespaceBegin = false;//from  w  ww  . j  a va 2  s  . co m
    }
    for (int i = 0; i < atts.getLength(); i++) {
        System.out.print(" " + atts.getQName(i) + "=\\" + atts.getValue(i) + "\"");
    }
    System.out.print(">");
}

From source file:importer.handler.post.annotate.Annotation.java

/**
 * Add a start tag to the note body/*from  w  ww  .j  a v  a 2  s  . c  o m*/
 * @param localName the name of the element
 * @param atts its attributes
 */
public void addStartTag(String localName, Attributes atts) {
    if (this.body == null)
        this.body = new StringBuilder();
    this.body.append("<");
    this.body.append(localName);
    for (int i = 0; i < atts.getLength(); i++) {
        if (!atts.getLocalName(i).equals(Splitter.DONE)) {
            this.body.append(" ");
            this.body.append(atts.getLocalName(i));
            this.body.append("=\"");
            this.body.append(atts.getValue(i));
            this.body.append("\"");
        }
    }
    this.body.append(">");
}