Package org.pirkaengine.core.parser

Examples of org.pirkaengine.core.parser.Fragment$Attribute


                                {
                                    skey.textToShow = trans.get(f);
                                    f = org.size();
                                }

                            Attribute a;
                            if ((a = keyEl.getAttribute(length)) != null)
                                skey.keyWidth = Integer.parseInt(a.getValue());

                            line.add(skey);
                        } else
                            line.add(SpecialKey.getKeyboardKey(fontName, special));
                    }
View Full Code Here


            factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
            reader = factory.createXMLStreamReader(createProxy(input));
            FragmentParser parser = new FragmentParser(reader);
            parser.parseFragments();
            LinkedList<Fragment> fragments = new LinkedList<Fragment>();
            Fragment preFragment = null;
            for (Fragment fragment : parser.fragments) {
                // サイズ0の断片は圧縮
                if (preFragment != null && preFragment.offset == fragment.offset) {
                    // Empty Element Tag
                    if (preFragment.type == Fragment.Type.TAG_END && fragment.type == Fragment.Type.TAG_START) {
View Full Code Here

                value = PrkAttribute.ATTR.name;
            }
            if (key != null) {
                // ルート要素に属性が付いている場合は最初に設定したダミーのFragmentを削除しておく
                if (offsetTagStart == 0) fragments.clear();
                fragments.addFirst(new Fragment(offsetTagStart, Fragment.Type.TAG_START, key, value, attrs, prkAttrs,
                        pathAttrs));
                if (isLoop || key.equals(PrkAttribute.BLOCK.name)) {
                    fragments.addFirst(Fragment.create(offsetTagEnd + 1, Fragment.Type.TEXT).build());
                }
                depth.nest();
View Full Code Here

            throws ParseException {
        StringBuilder text = struct.getText();
        ListIterator<Fragment> iter = struct.getFragments().listIterator();
        assert iter.hasNext();
        while (iter.hasNext()) {
            Fragment fragment = iter.next();
            if (PrkElement.COMPONENT.name.equals(fragment.prkKey)) {
                PrkComponent comp = new PrkComponent();
                comp.setType(fragment.prkValue);
                for (String key : fragment.attributes().keySet()) {
                    comp.putAttr(key, fragment.attributes().get(key));
                }
                template.add(comp);
                text.delete(fragment.offset, text.length());
                continue;
            }
View Full Code Here

            LinkedList<Node> nodes = new LinkedList<Node>();
            Node nextNode = null;
            while (true) {
                if (!iter.hasNext()) throw new TemplateBuildFailedException("format error"); // TODO
                // message
                Fragment nextFrag = iter.next();
                nextNode = this.toNode(template, text, nextFrag, iter, replaces, charset); // 再帰
                if (nextNode instanceof StartTagNode) break; // 再帰終了
                nodes.addFirst(nextNode);
            }
            StartTagNode start = (StartTagNode) nextNode;
            Node compositeNode = CompositeNode.newNode(start, end, nodes.toArray(new Node[nodes.size()]));
            if (compositeNode instanceof BlockNode) {
                BlockNode block = (BlockNode) compositeNode;
                String id = block.startTagNode.attrValue;
                if (replaces == null) {
                    // 置換対象がない場合は積み上げる
                    this.blocks.put(id, block);
                } else if (replaces.containsKey(id)) {
                    // 置換対象があれば置換する
                    return new BlockNode(start, end, replaces.get(id).nodes);
                } else {
                    // そのまま使うのでなにもしない
                }
            }
            return compositeNode;
        case TAG_EMPTY_ELEMENTS:
            if (PrkElement.REPLACE.name.equals(fragment.prkKey)) {
                tagText = getTagText(str);
                start = new StartTagNode(tagText, fragment.prkKey, fragment.prkValue, fragment.prkAttributes(),
                        fragment.pathAttributes(), fragment.attributes());
                end = new EndTagNode(str);
                return new ReplaceNode(start, end, new Node[] {});
            } else if (PrkElement.INCLUDE.name.equals(fragment.prkKey)) {
                // prk: include
                // TODO 相対パスの解決
                try {
                    XhtmlTemplate includeTemplate = new XhtmlTemplate(fragment.prkValue);
                    File includeFile = loader.toFile(fragment.prkValue, template.templateName);
                    XhtmlStruct includeStruct = parse(includeFile, charset);
                    buildTemplate(includeTemplate, includeStruct, null, charset);
                    // IncludeNode node = new IncludeNode(includeTemplate);
                    // template.stack(node);
                    template.components.addAll(includeTemplate.components);
                    for (String name : includeTemplate.functions.keySet()) {
                        template.functions.put(name, includeTemplate.functions.get(name));
                    }
                    // text.delete(fragment.offset, text.length());
                    return new IncludeNode(includeTemplate);
                } catch (Exception e) {
                    throw new ParseException(e);
                }
            } else if (PrkElement.VAL.name.equals(fragment.prkKey)) {
                return new ValNode(fragment.prkValue, fragment.attributes().get("value"));
            } else {
                String tagName = getTagText(str);
                return new EmptyElementTagNode(tagName, fragment.prkKey, fragment.prkValue, fragment.prkAttributes(),
                        fragment.pathAttributes(), fragment.attributes());
            }
        case DEF_START:
            throw new AssertionError();
        case DEF_CDATA:
            throw new AssertionError();
        case DEF_END:
            // ENDは無視
            if (!iter.hasNext()) throw new TemplateBuildFailedException("format error"); // TODO
            // message
            Fragment cdataFrag = iter.next();
            if (cdataFrag.type != Fragment.Type.DEF_CDATA) throw new TemplateBuildFailedException("format error"); // TODO
            // message
            StringBuilder script = new StringBuilder(text.substring(cdataFrag.offset));
            script.delete(0, script.indexOf("<![CDATA[") + "<![CDATA[".length());
            script.setLength(script.lastIndexOf("]]>"));
            text.delete(cdataFrag.offset, text.length());
            if (!iter.hasNext()) throw new TemplateBuildFailedException("format error"); // TODO
            // message
            Fragment startFrag = iter.next();
            if (startFrag.type != Fragment.Type.DEF_START) throw new TemplateBuildFailedException("format error"); // TODO
            // message
            text.delete(startFrag.offset, text.length());
            Fragment.Attribute[] flgAttrs = startFrag.attributeArray();
            assert flgAttrs.length == 3 : startFrag;
            assert flgAttrs[0].key.equals("language") : startFrag;
            assert flgAttrs[1].key.equals("type") : startFrag;
            assert flgAttrs[1].value.equals("function") : startFrag;
            assert flgAttrs[2].key.equals("name") : startFrag;
View Full Code Here

    this.handleQCInformation();

    this.ncFile.addAttribute( null, qcFlagsAtt );

    // Add some general metadata in global attributes.
    this.ncFile.addAttribute( null, new Attribute( "title",
                                                   new StringBuffer("NGDC archived ")
                                                   .append( datasetIdAtt.getStringValue())
                                                   .append( " data with start time ")
                                                   .append( startDateAtt.getStringValue())
                                                   .toString()));
    this.ncFile.addAttribute( null, new Attribute( "Convention", _Coordinate.Convention));

    // Add some THREDDS specific metadata in global attributes.
    this.ncFile.addAttribute( null, new Attribute( "thredds_creator", "DOD/USAF/SMC > Space and Missile Systems Center (SMC), U.S. Air Force, U.S. Department of Defense"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_contributor", "DOC/NOAA/NESDIS/NGDC > National Geophysical Data Center, NESDIS, NOAA, U.S. Department of Commerce"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_contributor_role", "archive"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_publisher", "DOC/NOAA/NESDIS/NGDC > National Geophysical Data Center, NESDIS, NOAA, U.S. Department of Commerce"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_publisher_url", "http://dmsp.ngdc.noaa.gov/"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_publisher_email", "ngdc.dmsp@noaa.gov"));
    this.ncFile.addAttribute( null, new Attribute( "thredds_summary",
                                                   new StringBuffer("This dataset contains data from the DMSP ").append( spacecraftIdAtt.getStringValue())
                                                   .append( " satellite OLS instrument and includes both visible smooth and thermal smooth imagery with 2.7km resolution.")
                                                   .append( " The start time for this data is ").append( startDateAtt.getStringValue())
                                                   .append( " and the northerly equatorial crossing longitude is ").append( startLongitudeAtt.getNumericValue())
                                                   .append( ".  The DMSP satellite is a polar-orbiting satellite crossing the equator, depending on the satellite, at either dawn/dusk or noon/midnight.")
                                                   .append( " This data is in the NOAA/NGDC DMSP archive format.")
                                                   .toString()));
    this.ncFile.addAttribute( null, new Attribute( "thredds_history", ""));
    this.ncFile.addAttribute( null, new Attribute( "thredds_timeCoverage_start", startDateAtt.getStringValue()));
    this.ncFile.addAttribute( null, new Attribute( "thredds_timeCoverage_end", endDateAtt.getStringValue()));
    this.ncFile.addAttribute( null, new Attribute( "thredds_geospatialCoverage",
                                                   new StringBuffer("Polar orbit with northerly equatorial crossing at longitude ")
                                                   .append( ascendingNodeAtt.getNumericValue()).append( ".")
                                                   .toString()));

View Full Code Here

   * @throws IOException if any problems reading the file (or validating the file).
   */
  private void handleFileInformation()
          throws IOException
  {
    fileIdAtt = new Attribute( this.fileIdAttName,
                               (String) headerInfo.get( HeaderInfoTitle.FILE_ID.toString() ) );
    datasetIdAtt = new Attribute( this.datasetIdAttName,
                                  (String) headerInfo.get( HeaderInfoTitle.DATA_SET_ID.toString() ) );
    recordSizeInBytes = Integer.parseInt( (String) headerInfo.get( HeaderInfoTitle.RECORD_BYTES.toString() ) );
    numRecords = Integer.parseInt( (String) headerInfo.get( HeaderInfoTitle.NUM_RECORDS.toString() ) );
    numHeaderRecords = Integer.parseInt( (String) headerInfo.get( HeaderInfoTitle.NUM_HEADER_RECORDS.toString() ) );
    numDataRecords = Integer.parseInt( (String) headerInfo.get( HeaderInfoTitle.NUM_DATA_RECORDS.toString() ) );
View Full Code Here

   * @throws IOException if any problems reading the file (or validating the file).
   */
  private void handleProcessingInformation()
          throws IOException
  {
    suborbitHistoryAtt = new Attribute( this.suborbitHistoryAttName,
                                        (String) headerInfo.get( HeaderInfoTitle.SUBORBIT_HISTORY.toString() ) );
    processingSystemAtt = new Attribute( this.processingSystemAttName,
                                         (String) headerInfo.get( HeaderInfoTitle.PROCESSING_SYSTEM.toString() ) );
    String processingDateString = (String) headerInfo.get( HeaderInfoTitle.PROCESSING_DATE.toString() );
    try
    {
      processingDate = DateFormatHandler.ALT_DATE_TIME.getDateFromDateTimeString( processingDateString );
    }
    catch ( ParseException e )
    {
      throw new IOException( "Invalid DMSP file: processing date string <" + processingDateString + "> not parseable: " + e.getMessage() );
    }
    processingDateAtt = new Attribute(
            this.processingDateAttName,
            DateFormatHandler.ISO_DATE_TIME.getDateTimeStringFromDate( processingDate ) );
  }
View Full Code Here

  /**
   * Parse the satellite information from the header.
   */
  private void handleSatelliteInformation()
  {
    spacecraftIdAtt = new Attribute(
            this.spacecraftIdAttName,
            (String) headerInfo.get( HeaderInfoTitle.SPACECRAFT_ID.toString() ) );
    noradIdAtt = new Attribute(
            this.noradIdAttName,
            (String) headerInfo.get( HeaderInfoTitle.NORAD_ID.toString() ) );
  }
View Full Code Here

    }
    catch ( ParseException e )
    {
      throw new IOException( "Invalid DMSP file: start date/time string <" + startDateTimeUTC + "> not parseable: " + e.getMessage() );
    }
    this.startDateAtt = new Attribute( this.startDateAttName,
                                       DateFormatHandler.ISO_DATE_TIME.getDateTimeStringFromDate( this.startDate));

    // Read the end date UTC information.
    time = (String) headerInfo.getHeaderInfoTitle.END_TIME_UTC.toString());
    String endDateTimeUTC = (String) headerInfo.getHeaderInfoTitle.END_DATE_UTC.toString())
                            + "T" + time.substring( 0, time.indexOf( '.')+4)
                            + "GMT";
    try
    {
      this.endDate = DateFormatHandler.ISO_DATE_TIME.getDateFromDateTimeString( endDateTimeUTC);
    }
    catch ( ParseException e )
    {
      throw new IOException( "Invalid DMSP file: end date/time string <" + endDateTimeUTC + "> not parseable: " + e.getMessage() );
    }
    this.endDateAtt = new Attribute( this.endDateAttName,
                                       DateFormatHandler.ISO_DATE_TIME.getDateTimeStringFromDate( this.endDate));

    // Read the local start/end date/time
    this.startDateLocalAtt = new Attribute( this.startDateLocalAttName,
                                            (String) HeaderInfoTitle.START_DATE_LOCAL.toString());
    this.startTimeLocalAtt = new Attribute( this.startTimeLocalAttName,
                                            (String) HeaderInfoTitle.START_TIME_LOCAL.toString());

    // Read the start latitude/longitude information.
    String startLatLon = (String) headerInfo.getHeaderInfoTitle.START_LAT_LON.toString());
    String[] latLon = startLatLon.split( " ");
    Double lat, lon;
    if ( latLon.length != 2) throw new IOException( "Invalid DMSP file: start lat/lon <" + startLatLon + "> invalid.");
    try
    {
      lat = Double.valueOf( latLon[0]);
      lon = Double.valueOf( latLon[1]);
    }
    catch ( NumberFormatException e )
    {
      throw new IOException( "Invalid DMSP file: start lat/lon string <" + startLatLon + "> not parseable: " + e.getMessage() );
    }
    this.startLatitudeAtt = new Attribute( this.startLatitudeAttName, lat);
    this.startLongitudeAtt = new Attribute( this.startLongitudeAttName, lon);

    // Read the end latitude/longitude information.
    String endLatLon = (String) headerInfo.getHeaderInfoTitle.END_LAT_LON.toString());
    latLon = endLatLon.split( " ");
    if ( latLon.length != 2) throw new IOException( "Invalid DMSP file: end lat/lon <" + endLatLon + "> invalid.");
    try
    {
      lat = Double.valueOf( latLon[0]);
      lon = Double.valueOf( latLon[1]);
    }
    catch ( NumberFormatException e )
    {
      throw new IOException( "Invalid DMSP file: end lat/lon string <" + endLatLon + "> not parseable: " + e.getMessage() );
    }
    this.endLatitudeAtt = new Attribute( this.endLatitudeAttName, lat);
    this.endLongitudeAtt = new Attribute( this.endLongitudeAttName, lon);

    // Read the start sub-solar coordinates.
    this.startSubsolarCoordsAtt = new Attribute( this.startSubsolarCoordsAttName,
                                                 (String) headerInfo.get( HeaderInfoTitle.START_SUBSOLAR_COORD.toString()));

    // Read the end sub-solar coordinates.
    this.endSubsolarCoordsAtt = new Attribute( this.endSubsolarCoordsAttName,
                                               (String) headerInfo.get( HeaderInfoTitle.END_SUBSOLAR_COORD.toString()));

    // Read the start lunar coordinates.
    this.startLunarCoordsAtt = new Attribute( this.startLunarCoordsAttName,
                                              (String) headerInfo.get( HeaderInfoTitle.START_LUNAR_COORD.toString()));

    // Read the end lunar coordinates.
    this.endLunarCoordsAtt = new Attribute( this.endLunarCoordsAttName,
                                            (String) headerInfo.get( HeaderInfoTitle.END_LUNAR_COORD.toString()));

    // Read the ascending node.
    Double ascendingNode = Double.valueOf( (String) headerInfo.get( HeaderInfoTitle.ASCENDING_NODE.toString()) );
    this.ascendingNodeAtt = new Attribute( this.ascendingNodeAttName, ascendingNode);

    Double nodeHeading = Double.valueOf( (String) headerInfo.get( HeaderInfoTitle.NODE_HEADING.toString()) );
    this.nodeHeadingAtt = new Attribute( this.nodeHeadingAttName, nodeHeading);
  }
View Full Code Here

TOP

Related Classes of org.pirkaengine.core.parser.Fragment$Attribute

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.