Example usage for org.xml.sax.helpers DefaultHandler DefaultHandler

List of usage examples for org.xml.sax.helpers DefaultHandler DefaultHandler

Introduction

In this page you can find the example usage for org.xml.sax.helpers DefaultHandler DefaultHandler.

Prototype

DefaultHandler

Source Link

Usage

From source file:org.mitre.mpf.wfm.camel.operations.mediainspection.MediaInspectionProcessor.java

private Metadata generateExifMetadata(File fileName) throws IOException, TikaException, SAXException {
    Tika tika = new Tika();
    Metadata metadata = new Metadata();
    ContentHandler handler = new DefaultHandler();
    Parser parser = new AutoDetectParser();
    ParseContext context = new ParseContext();
    String mimeType = null;//from   w w w  . j  a  v a 2  s.  co m
    try (InputStream stream = Preconditions.checkNotNull(
            IOUtils.toBufferedInputStream(FileUtils.openInputStream(fileName)), "Cannot open file '%s'",
            fileName)) {
        mimeType = tika.detect(stream);
        metadata.set(Metadata.CONTENT_TYPE, mimeType);
    }
    try (InputStream stream = Preconditions.checkNotNull(
            IOUtils.toBufferedInputStream(FileUtils.openInputStream(fileName)), "Cannot open file '%s'",
            fileName)) {
        parser.parse(stream, handler, metadata, context);
    }
    return metadata;
}

From source file:org.moe.natjgen.XcodeFullDocumentation.java

public XcodeFullDocumentation(Indexer indexer, String lang, String type, String element, String name,
        TextEditGroup editGroup) throws IOException {
    this.editGroup = editGroup;

    if (indexer.getXcodePath() == null) {
        throw new IOException("Xcode path could not be retrieved");
    }/* w  w w.ja  va 2 s  . c  o m*/

    File file = null;
    ArrayList<String> docsets = indexer.getConfiguration().getDocsets();
    for (String docset : docsets) {
        File ds = new File(indexer.getXcodePath(), "Documentation/DocSets");
        ds = new File(ds, docset);
        ds = new File(ds, DocTokensBase + "/" + lang + "/" + type + "/" + element + "/" + name + ".xml");
        if (ds.exists()) {
            file = ds;
            break;
        }
    }

    if (file == null) {
        throw new IOException("no documentation found for /" + lang + "/" + type + "/" + element + "/" + name);
    }

    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser parser = factory.newSAXParser();

        DefaultHandler handler = new DefaultHandler() {

            private final int kROOT = 0;
            private final int kAbstract = 1;
            private final int kDiscussion = 2;
            private final int kParameters = 3;
            private final int kParameter = 31;
            private final int kParameter_Term = 311;
            private final int kParameter_Definition = 312;
            private final int kResultDescription = 4;
            private final int kAvailability = 5;
            private final int kAvailabilityItem = 51;
            private final int kDeclaration = 6;
            private final int kCodeLine = 61;
            private int phase = kROOT;

            private StringBuilder capture;

            private final int maxStackDepth = 1024;
            private boolean contentStack[] = new boolean[maxStackDepth];
            private int contentStackDepth = 0;

            @Override
            public void startElement(String uri, String localName, String qName, Attributes attributes)
                    throws SAXException {
                switch (phase) {
                case kAbstract:
                case kDiscussion:
                case kResultDescription:
                case kParameter_Definition:
                    contentStack[contentStackDepth] = true;
                    ++contentStackDepth;
                    for (HTMLTagReplacement replacement : replacements) {
                        if (qName.equalsIgnoreCase(replacement.xml)) {
                            contentStack[contentStackDepth - 1] = replacement.param;
                            capture.append(replacement.openPlaceholder);
                            break;
                        }
                    }
                case kROOT:
                    if (qName.equalsIgnoreCase("Abstract")) {
                        phase = kAbstract;
                        capture = new StringBuilder();
                    } else if (qName.equalsIgnoreCase("Discussion")) {
                        phase = kDiscussion;
                        capture = new StringBuilder();
                    } else if (qName.equalsIgnoreCase("Parameters")) {
                        phase = kParameters;
                    } else if (qName.equalsIgnoreCase("ResultDescription")) {
                        phase = kResultDescription;
                        capture = new StringBuilder();
                    } else if (qName.equalsIgnoreCase("Availability")) {
                        phase = kAvailability;
                    } else if (qName.equalsIgnoreCase("Declaration")) {
                        phase = kDeclaration;
                    }
                    break;
                case kParameters:
                    if (qName.equalsIgnoreCase("Parameter")) {
                        phase = kParameter;
                    }
                    break;
                case kParameter:
                    if (qName.equalsIgnoreCase("Term")) {
                        phase = kParameter_Term;
                        capture = new StringBuilder();
                    } else if (qName.equalsIgnoreCase("Definition")) {
                        phase = kParameter_Definition;
                        capture = new StringBuilder();
                    }
                    break;
                case kAvailability:
                    if (qName.equalsIgnoreCase("AvailabilityItem")) {
                        phase = kAvailabilityItem;
                        capture = new StringBuilder();
                    }
                    break;
                case kDeclaration:
                    if (qName.equalsIgnoreCase("CodeLine")) {
                        phase = kCodeLine;
                        capture = new StringBuilder();
                    }
                    break;

                default:
                    break;
                }
            }

            @Override
            public void endElement(String uri, String localName, String qName) throws SAXException {
                if (contentStackDepth > 0) {
                    --contentStackDepth;
                    for (HTMLTagReplacement replacement : replacements) {
                        if (qName.equalsIgnoreCase(replacement.xml)) {
                            capture.append(replacement.closePlaceholder);
                            break;
                        }
                    }
                } else {
                    switch (phase) {
                    case kAbstract:
                        if (qName.equalsIgnoreCase("Abstract")) {
                            Abstract = capture.toString();
                            capture = null;
                            phase = kROOT;
                        }
                        break;
                    case kDiscussion:
                        if (qName.equalsIgnoreCase("Discussion")) {
                            Discussion = capture.toString();
                            capture = null;
                            phase = kROOT;
                        }
                        break;
                    case kParameters:
                        if (qName.equalsIgnoreCase("Parameters")) {
                            phase = kROOT;
                        }
                        break;
                    case kResultDescription:
                        if (qName.equalsIgnoreCase("ResultDescription")) {
                            ResultDescription = capture.toString();
                            capture = null;
                            phase = kROOT;
                        }
                        break;
                    case kAvailability:
                        if (qName.equalsIgnoreCase("Availability")) {
                            phase = kROOT;
                        }
                        break;
                    case kDeclaration:
                        if (qName.equalsIgnoreCase("Declaration")) {
                            phase = kROOT;
                        }
                        break;
                    case kParameter:
                        if (qName.equalsIgnoreCase("Parameter")) {
                            phase = kParameters;
                        }
                        break;
                    case kParameter_Term:
                        if (qName.equalsIgnoreCase("Term")) {
                            ParameterNames.add(capture.toString());
                            capture = null;
                            phase = kParameter;
                        }
                        break;
                    case kParameter_Definition:
                        if (qName.equalsIgnoreCase("Definition")) {
                            ParameterDescriptions.add(capture.toString());
                            capture = null;
                            phase = kParameter;
                        }
                        break;
                    case kAvailabilityItem:
                        if (qName.equalsIgnoreCase("AvailabilityItem")) {
                            Availabilities.add(capture.toString());
                            capture = null;
                            phase = kAvailability;
                        }
                        break;
                    case kCodeLine:
                        if (qName.equalsIgnoreCase("CodeLine")) {
                            Declaration = capture.toString();
                            capture = null;
                            phase = kDeclaration;
                        }
                        break;

                    default:
                        break;
                    }
                }
            }

            @Override
            public void characters(char[] ch, int start, int length) throws SAXException {
                if (capture != null) {
                    if (contentStackDepth == 0 || contentStack[contentStackDepth - 1]) {
                        capture.append(new String(ch, start, length));
                    }
                }
            }
        };

        InputStream inputStream = new FileInputStream(file);
        Reader reader = new InputStreamReader(inputStream, "UTF-8");

        InputSource is = new InputSource(reader);
        is.setEncoding("UTF-8");

        parser.parse(is, handler);

    } catch (Exception e) {
        throw new IOException("failed to parse doc", e);
    }
}

From source file:org.mycore.common.MCRUtils.java

public static String parseDocumentType(InputStream in) {
    SAXParser parser = null;// w w  w  .j a va 2 s. co  m

    try {
        parser = SAXParserFactory.newInstance().newSAXParser();
    } catch (Exception ex) {
        String msg = "Could not build a SAX Parser for processing XML input";
        throw new MCRConfigurationException(msg, ex);
    }

    final Properties detected = new Properties();
    final String forcedInterrupt = "mcr.forced.interrupt";

    DefaultHandler handler = new DefaultHandler() {
        @Override
        public void startElement(String uri, String localName, String qName, Attributes attributes) {
            LOGGER.debug("MCRLayoutService detected root element = " + qName);
            detected.setProperty("docType", qName);
            throw new MCRException(forcedInterrupt);
        }
    };

    try {
        parser.parse(new InputSource(in), handler);
    } catch (Exception ex) {
        if (!forcedInterrupt.equals(ex.getMessage())) {
            String msg = "Error while detecting XML document type from input source";
            throw new MCRException(msg, ex);
        }
    }

    String docType = detected.getProperty("docType");
    int pos = docType.indexOf(':') + 1;
    if (pos > 0) {
        //filter namespace prefix
        docType = docType.substring(pos);
    }
    return docType;

}

From source file:org.n52.ifgicopter.spf.xml.SchematronValidator.java

/**
 * Here the real validation process is started.
 * // www.  java  2s  .  com
 * @return true if no schematron rule was violated.
 */
public boolean validate() {
    Transform trans = new Transform();

    /*
     * transform the schematron
     */
    String[] arguments = new String[] { "-x", "org.apache.xerces.parsers.SAXParser", "-w1", "-o",
            DOCS_FOLDER + "/tmp/tmp.xsl", this.schematronFile, DOCS_FOLDER + "/iso_svrl_for_xslt2.xsl",
            "generate-paths=yes" };
    trans.doTransform(arguments, "java net.sf.saxon.Transform");

    /*
     * transform the instance
     */
    String report = DOCS_FOLDER + "/tmp/"
            + this.xmlInstanceFile.substring(this.xmlInstanceFile.lastIndexOf("/") + 1) + ".report.xml";
    arguments = new String[] { "-x", "org.apache.xerces.parsers.SAXParser", "-w1", "-o", report,
            this.xmlInstanceFile, DOCS_FOLDER + "/tmp/tmp.xsl" };
    trans.doTransform(arguments, "java net.sf.saxon.Transform");

    LocatorImpl locator = new LocatorImpl();
    /*
     * an extension of DefaultHandler
     */
    DefaultHandler handler = new DefaultHandler() {

        private String failTmp;
        private Locator locator2;
        private boolean insideFail = false;

        @Override
        public void startElement(String uri, String localName, String qName, Attributes attributes)
                throws SAXException {
            if (qName.endsWith("failed-assert")) {
                this.failTmp = "Assertion error at \"" + attributes.getValue("test") + "\" (line "
                        + this.locator2.getLineNumber() + "): ";
                this.insideFail = true;
            }
        }

        @Override
        public void endElement(String uri, String localName, String qName) throws SAXException {
            if (qName.endsWith("failed-assert")) {
                SchematronValidator.this.assertFails.add(this.failTmp);
                this.failTmp = null;
                this.insideFail = false;
            }
        }

        @Override
        public void characters(char[] ch, int start, int length) throws SAXException {
            if (this.insideFail) {
                this.failTmp += new String(ch, start, length).trim();
            }
        }

        @Override
        public void setDocumentLocator(Locator l) {
            this.locator2 = l;
        }

    };
    handler.setDocumentLocator(locator);

    try {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        parser.parse(new File(report), handler);
    } catch (SAXException e) {
        log.warn(e.getMessage(), e);
    } catch (IOException e) {
        log.warn(e.getMessage(), e);
    } catch (ParserConfigurationException e) {
        log.warn(e.getMessage(), e);
    }

    return (this.assertFails.size() == 0) ? true : false;
}

From source file:org.opencastproject.caption.converters.DFXPCaptionConverter.java

/**
 * {@inheritDoc} Uses SAX parser to quickly read the document and retrieve available languages.
 * /*w  w w.j a  v a  2  s. c  om*/
 * @see org.opencastproject.caption.api.CaptionConverter#getLanguageList(java.io.InputStream)
 */
@Override
public String[] getLanguageList(InputStream input) throws CaptionConverterException {

    // create lang list
    final List<String> langList = new LinkedList<String>();

    // get SAX parser
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
        SAXParser parser = factory.newSAXParser();
        // create handler
        DefaultHandler handler = new DefaultHandler() {
            @Override
            public void startElement(String uri, String localName, String qName, Attributes attributes)
                    throws SAXException {
                if ("div".equals(qName)) {
                    // we found div tag - let's make a lookup for language
                    String lang = attributes.getValue("xml:lang");
                    if (lang == null) {
                        // should never happen
                        logger.warn("Missing xml:lang attribute for div element.");
                    } else if (langList.contains(lang)) {
                        logger.warn("Multiple div elements with same language.");
                    } else {
                        langList.add(lang);
                    }
                }
            }
        };

        // parse stream
        parser.parse(input, handler);
    } catch (ParserConfigurationException e) {
        // should not happen
        throw new RuntimeException(e);
    } catch (SAXException e) {
        throw new CaptionConverterException("Could not parse captions", e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return langList.toArray(new String[0]);
}

From source file:org.openstreetmap.josm.tools.ImageProvider.java

/**
 * Reads the wiki page on a certain file in html format in order to find the real image URL.
 */// ww w  .  java2  s  . co  m
private static String getImgUrlFromWikiInfoPage(final String base, final String fn) {

    /** Quit parsing, when a certain condition is met */
    class SAXReturnException extends SAXException {
        private String result;

        public SAXReturnException(String result) {
            this.result = result;
        }

        public String getResult() {
            return result;
        }
    }

    try {
        final XMLReader parser = XMLReaderFactory.createXMLReader();
        parser.setContentHandler(new DefaultHandler() {
            @Override
            public void startElement(String uri, String localName, String qName, Attributes atts)
                    throws SAXException {
                System.out.println();
                if (localName.equalsIgnoreCase("img")) {
                    String val = atts.getValue("src");
                    if (val.endsWith(fn))
                        throw new SAXReturnException(val); // parsing done, quit early
                }
            }
        });

        parser.setEntityResolver(new EntityResolver() {
            public InputSource resolveEntity(String publicId, String systemId) {
                return new InputSource(new ByteArrayInputStream(new byte[0]));
            }
        });

        parser.parse(new InputSource(new MirroredInputStream(base + fn,
                new File(Main.pref.getPreferencesDir(), "images").toString())));
    } catch (SAXReturnException r) {
        return r.getResult();
    } catch (Exception e) {
        System.out.println("INFO: parsing " + base + fn + " failed:\n" + e);
        return null;
    }
    System.out.println("INFO: parsing " + base + fn + " failed: Unexpected content.");
    return null;
}

From source file:org.orbeon.oxf.resources.TaminoImport.java

private boolean isXMLFile(File file) {
    try {/*  w  w  w . j a  va2s  .  c o  m*/
        XMLUtils.newSAXParser(XMLUtils.ParserConfiguration.PLAIN).parse(file, new DefaultHandler());
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:org.sakaiproject.assignment.impl.conversion.AssignmentSubmissionAccess.java

/**
 * @param xml//from  ww  w .ja  v a  2  s.c om
 * @throws EntityParseException
 */
public void parse(String xml) throws Exception {
    Reader r = new StringReader(xml);
    InputSource ss = new InputSource(r);

    SAXParser p = null;
    if (parserFactory == null) {
        parserFactory = SAXParserFactory.newInstance();
        parserFactory.setNamespaceAware(false);
        parserFactory.setValidating(false);
    }
    try {
        p = parserFactory.newSAXParser();
    } catch (ParserConfigurationException e) {
        log.warn("{}:parse {}", this, e.getMessage());
        throw new SAXException("Failed to get a parser ", e);
    }
    final Map<String, Object> props = new HashMap<String, Object>();
    saxSerializableProperties.setSerializableProperties(props);

    p.parse(ss, new DefaultHandler() {

        /*
         * (non-Javadoc)
         * 
         * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String,
         *      java.lang.String, java.lang.String, org.xml.sax.Attributes)
         */
        @Override
        public void startElement(String uri, String localName, String qName, Attributes attributes)
                throws SAXException {

            if ("property".equals(qName)) {

                String name = attributes.getValue("name");
                String enc = StringUtils.trimToNull(attributes.getValue("enc"));
                String value = null;
                if ("BASE64".equalsIgnoreCase(enc)) {
                    String charset = StringUtils.trimToNull(attributes.getValue("charset"));
                    if (charset == null)
                        charset = "UTF-8";

                    value = Xml.decode(charset, attributes.getValue("value"));
                } else {
                    value = attributes.getValue("value");
                }

                // deal with multiple valued lists
                if ("list".equals(attributes.getValue("list"))) {
                    // accumulate multiple values in a list
                    Object current = props.get(name);

                    // if we don't have a value yet, make a list to
                    // hold
                    // this one
                    if (current == null) {
                        List values = new ArrayList();
                        props.put(name, values);
                        values.add(value);
                    }

                    // if we do and it's a list, add this one
                    else if (current instanceof List) {
                        ((List) current).add(value);
                    }

                    // if it's not a list, it's wrong!
                    else {
                        log.warn("construct(el): value set not a list: {}", name);
                    }
                } else {
                    props.put(name, value);
                }
            } else if ("submission".equals(qName)) {
                setId(attributes.getValue("id"));
                setAssignment(StringUtils.trimToNull(attributes.getValue("assignment")));
                setContext(StringUtils.trimToNull(attributes.getValue("context")));
                setDatereturned(StringUtils.trimToNull(attributes.getValue("datereturned")));
                setDatesubmitted(StringUtils.trimToNull(attributes.getValue("datesubmitted")));
                setFeedbackcomment(StringUtils.trimToNull(attributes.getValue("feedbackcomment")));
                if (StringUtils.trimToNull(attributes.getValue("feedbackcomment-html")) != null) {
                    setFeedbackcomment_html(
                            StringUtils.trimToNull(attributes.getValue("feedbackcomment-html")));
                } else if (StringUtils.trimToNull(attributes.getValue("feedbackcomment-formatted")) != null) {
                    setFeedbackcomment_html(
                            StringUtils.trimToNull(attributes.getValue("feedbackcomment-formatted")));
                }
                setFeedbacktext(StringUtils.trimToNull(attributes.getValue("feedbacktext")));

                if (StringUtils.trimToNull(attributes.getValue("feedbacktext-html")) != null) {
                    setFeedbacktext_html(StringUtils.trimToNull(attributes.getValue("feedbacktext-html")));
                } else if (StringUtils.trimToNull(attributes.getValue("feedbacktext-formatted")) != null) {
                    setFeedbacktext_html(StringUtils.trimToNull(attributes.getValue("feedbacktext-formatted")));
                }

                // get number of decimals
                String factor = StringUtils.trimToNull(attributes.getValue("scaled_factor"));
                if (factor == null) {
                    factor = String.valueOf(AssignmentConstants.DEFAULT_SCALED_FACTOR);
                }
                m_factor = Integer.valueOf(factor);

                // get grade
                String grade = StringUtils.trimToNull(attributes.getValue("scaled_grade"));
                if (grade == null) {
                    grade = StringUtils.trimToNull(attributes.getValue("grade"));
                    if (grade != null) {
                        try {
                            Integer.parseInt(grade);
                            // for the grades in points, multiple those by factor
                            grade = grade + factor.substring(1);
                        } catch (Exception e) {
                            log.warn("{}:parse grade {}", this, e.getMessage());
                        }
                    }
                }
                setGrade(grade);

                setGraded(StringUtils.trimToNull(attributes.getValue("graded")));
                setGradedBy(StringUtils.trimToNull(attributes.getValue("gradedBy")));
                setGradereleased(StringUtils.trimToNull(attributes.getValue("gradereleased")));
                setLastmod(StringUtils.trimToNull(attributes.getValue("lastmod")));

                addElementsToList("feedbackattachment", feedbackattachments, attributes, false);
                addElementsToList("submittedattachment", submittedattachments, attributes, false);

                setPledgeflag(StringUtils.trimToNull(attributes.getValue("pledgeflag")));
                setReturned(StringUtils.trimToNull(attributes.getValue("returned")));
                setReviewReport(StringUtils.trimToNull(attributes.getValue("reviewReport")));
                setReviewScore(StringUtils.trimToNull(attributes.getValue("reviewScore")));
                setReviewStatus(StringUtils.trimToNull(attributes.getValue("reviewStatus")));
                setSubmitted(StringUtils.trimToNull(attributes.getValue("submitted")));

                // submittedtext and submittedtext_html are base-64
                setSubmittedtext(StringUtils.trimToNull(attributes.getValue("submittedtext")));
                setSubmittedtext_html(StringUtils.trimToNull(attributes.getValue("submittedtext-html")));
                setSubmitterId(StringUtils.trimToNull(attributes.getValue("submitterid")));

                addElementsToList("submitter", submitters, attributes, false);
                // for backward compatibility of assignments without submitter ids
                if (getSubmitterId() == null && submitters.size() > 0) {
                    setSubmitterId(submitters.get(0));
                }
                addElementsToList("grade", grades, attributes, false);
            }
        }
    });
}

From source file:org.sakaiproject.assignment.impl.conversion.impl.AssignmentSubmissionAccess.java

/**
 * @param xml/*from   w  w w .  j a  v a2  s.  co m*/
 * @throws EntityParseException
 */
public void parse(String xml) throws Exception {
    Reader r = new StringReader(xml);
    InputSource ss = new InputSource(r);

    SAXParser p = null;
    if (parserFactory == null) {
        parserFactory = SAXParserFactory.newInstance();
        parserFactory.setNamespaceAware(false);
        parserFactory.setValidating(false);
    }
    try {
        p = parserFactory.newSAXParser();
    } catch (ParserConfigurationException e) {
        log.warn(this + ":parse " + e.getMessage());
        throw new SAXException("Failed to get a parser ", e);
    }
    final Map<String, Object> props = new HashMap<String, Object>();
    saxSerializableProperties.setSerializableProperties(props);

    p.parse(ss, new DefaultHandler() {

        /*
         * (non-Javadoc)
         * 
         * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String,
         *      java.lang.String, java.lang.String, org.xml.sax.Attributes)
         */
        @Override
        public void startElement(String uri, String localName, String qName, Attributes attributes)
                throws SAXException {

            if ("property".equals(qName)) {

                String name = attributes.getValue("name");
                String enc = StringUtils.trimToNull(attributes.getValue("enc"));
                String value = null;
                if ("BASE64".equalsIgnoreCase(enc)) {
                    String charset = StringUtils.trimToNull(attributes.getValue("charset"));
                    if (charset == null)
                        charset = "UTF-8";

                    value = Xml.decode(charset, attributes.getValue("value"));
                } else {
                    value = attributes.getValue("value");
                }

                // deal with multiple valued lists
                if ("list".equals(attributes.getValue("list"))) {
                    // accumulate multiple values in a list
                    Object current = props.get(name);

                    // if we don't have a value yet, make a list to
                    // hold
                    // this one
                    if (current == null) {
                        List values = new ArrayList();
                        props.put(name, values);
                        values.add(value);
                    }

                    // if we do and it's a list, add this one
                    else if (current instanceof List) {
                        ((List) current).add(value);
                    }

                    // if it's not a list, it's wrong!
                    else {
                        log.warn("construct(el): value set not a list: " + name);
                    }
                } else {
                    props.put(name, value);
                }
            } else if ("submission".equals(qName)) {
                setId(attributes.getValue("id"));
                setAssignment(StringUtils.trimToNull(attributes.getValue("assignment")));
                setContext(StringUtils.trimToNull(attributes.getValue("context")));
                setDatereturned(StringUtils.trimToNull(attributes.getValue("datereturned")));
                setDatesubmitted(StringUtils.trimToNull(attributes.getValue("datesubmitted")));
                setFeedbackcomment(StringUtils.trimToNull(attributes.getValue("feedbackcomment")));
                if (StringUtils.trimToNull(attributes.getValue("feedbackcomment-html")) != null) {
                    setFeedbackcomment_html(
                            StringUtils.trimToNull(attributes.getValue("feedbackcomment-html")));
                } else if (StringUtils.trimToNull(attributes.getValue("feedbackcomment-formatted")) != null) {
                    setFeedbackcomment_html(
                            StringUtils.trimToNull(attributes.getValue("feedbackcomment-formatted")));
                }
                setFeedbacktext(StringUtils.trimToNull(attributes.getValue("feedbacktext")));

                if (StringUtils.trimToNull(attributes.getValue("feedbacktext-html")) != null) {
                    setFeedbacktext_html(StringUtils.trimToNull(attributes.getValue("feedbacktext-html")));
                } else if (StringUtils.trimToNull(attributes.getValue("feedbacktext-formatted")) != null) {
                    setFeedbacktext_html(StringUtils.trimToNull(attributes.getValue("feedbacktext-formatted")));
                }

                // get number of decimals
                String factor = StringUtils.trimToNull(attributes.getValue("scaled_factor"));
                if (factor == null) {
                    factor = String.valueOf(AssignmentConstants.DEFAULT_SCALED_FACTOR);
                }
                m_factor = Integer.valueOf(factor);

                // get grade
                String grade = StringUtils.trimToNull(attributes.getValue("scaled_grade"));
                if (grade == null) {
                    grade = StringUtils.trimToNull(attributes.getValue("grade"));
                    if (grade != null) {
                        try {
                            Integer.parseInt(grade);
                            // for the grades in points, multiple those by factor
                            grade = grade + factor.substring(1);
                        } catch (Exception e) {
                            log.warn(this + ":parse grade " + e.getMessage());
                        }
                    }
                }
                setGrade(grade);

                setGraded(StringUtils.trimToNull(attributes.getValue("graded")));
                setGradedBy(StringUtils.trimToNull(attributes.getValue("gradedBy")));
                setGradereleased(StringUtils.trimToNull(attributes.getValue("gradereleased")));
                setLastmod(StringUtils.trimToNull(attributes.getValue("lastmod")));

                addElementsToList("feedbackattachment", feedbackattachments, attributes, false);
                addElementsToList("submittedattachment", submittedattachments, attributes, false);

                setPledgeflag(StringUtils.trimToNull(attributes.getValue("pledgeflag")));
                setReturned(StringUtils.trimToNull(attributes.getValue("returned")));
                setReviewReport(StringUtils.trimToNull(attributes.getValue("reviewReport")));
                setReviewScore(StringUtils.trimToNull(attributes.getValue("reviewScore")));
                setReviewStatus(StringUtils.trimToNull(attributes.getValue("reviewStatus")));
                setSubmitted(StringUtils.trimToNull(attributes.getValue("submitted")));

                // submittedtext and submittedtext_html are base-64
                setSubmittedtext(StringUtils.trimToNull(attributes.getValue("submittedtext")));
                setSubmittedtext_html(StringUtils.trimToNull(attributes.getValue("submittedtext-html")));
                setSubmitterId(StringUtils.trimToNull(attributes.getValue("submitterid")));

                addElementsToList("submitter", submitters, attributes, false);
                addElementsToList("log", submissionLog, attributes, false);
                addElementsToList("grade", grades, attributes, false);
            }
        }
    });
}

From source file:org.sakaiproject.calendar.impl.ExclusionSeqRecurrenceRule.java

public ContentHandler getContentHandler(Map<String, Object> services) {
    return new DefaultHandler() {
        /*//  w  ww . j a  v a 2s  .  c o  m
         * (non-Javadoc)
         * 
         * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String,
         *      java.lang.String, java.lang.String, org.xml.sax.Attributes)
         */
        @Override
        public void startElement(String uri, String localName, String qName, Attributes attributes)
                throws SAXException {
            // the children (time ranges)
            if ("exclude".equals(qName)) {
                try {
                    m_exclusions.add(new Integer(attributes.getValue("sequence")));
                } catch (Exception e) {
                    M_log.warn("set: while reading exclude sequence: " + e);
                }
            }
        }

    };
}