@Test
  public void testImageOutputConvertsNitroImages() {
    Item item = new Item();
    item.setImage("http://ichef.bbci.co.uk/images/ic/1024x576/legacy/episode/p01fxcbg.jpg");

    Element imageElem = programInfoOutputter.createImageDescriptionElem(item, "86", "48");

    assertEquals(
        "http://ichef.bbci.co.uk/images/ic/86x48/legacy/episode/p01fxcbg.jpg",
        imageElem.getAttribute("url").getValue());
    assertEquals("image/jpeg", imageElem.getAttribute("mimeValue").getValue());
    assertEquals("86", imageElem.getAttribute("width").getValue());
    assertEquals("48", imageElem.getAttribute("height").getValue());
  }
  @Test
  public void testImageOutputConvertsDynamiteImages() {
    Item item = new Item();
    item.setImage("http://ichef.bbci.co.uk/programmeimages/episode/b03c4rs8_640_360.jpg");

    Element imageElem = programInfoOutputter.createImageDescriptionElem(item, "86", "48");

    assertEquals(
        "http://ichef.bbci.co.uk/programmeimages/episode/b03c4rs8_86_48.jpg",
        imageElem.getAttribute("url").getValue());
    assertEquals("image/jpeg", imageElem.getAttribute("mimeValue").getValue());
    assertEquals("86", imageElem.getAttribute("width").getValue());
    assertEquals("48", imageElem.getAttribute("height").getValue());
  }
Esempio n. 3
0
  private boolean checkSemanticsAttribute(Element e, String value) {
    Attribute atr = e.getAttribute("semantics");

    if (atr == null || !atr.getValue().contains(value)) return false;

    return true;
  }
  /**
   * Read urn.
   *
   * @param file the file
   * @return The URN specified in the METS file or null if the METS file doesn't specify an URN
   * @throws IOException Signals that an I/O exception has occurred.
   * @throws ParseException the parse exception
   * @author Thomas Kleinke
   */
  public String readURN(File file) throws IOException, ParseException {

    FileInputStream fileInputStream = new FileInputStream(file);
    BOMInputStream bomInputStream = new BOMInputStream(fileInputStream);

    XMLReader xmlReader = null;
    SAXParserFactory spf = SAXParserFactory.newInstance();
    try {
      xmlReader = spf.newSAXParser().getXMLReader();
    } catch (Exception e) {
      fileInputStream.close();
      bomInputStream.close();
      throw new IOException("Error creating SAX parser", e);
    }
    xmlReader.setErrorHandler(err);
    NodeFactory nodeFactory = new PremisXmlReaderNodeFactory();
    Builder parser = new Builder(xmlReader, false, nodeFactory);
    logger.trace("Successfully built builder and XML reader");

    try {
      String urn = null;

      Document doc = parser.build(bomInputStream);
      Element root = doc.getRootElement();

      Element dmdSecEl = root.getFirstChildElement("dmdSec", METS_NS);
      if (dmdSecEl == null) return null;

      Element mdWrapEl = dmdSecEl.getFirstChildElement("mdWrap", METS_NS);
      if (mdWrapEl == null) return null;

      Element xmlDataEl = mdWrapEl.getFirstChildElement("xmlData", METS_NS);
      if (xmlDataEl == null) return null;

      Element modsEl = xmlDataEl.getFirstChildElement("mods", MODS_NS);
      if (modsEl == null) return null;

      Elements identifierEls = modsEl.getChildElements("identifier", MODS_NS);
      for (int i = 0; i < identifierEls.size(); i++) {
        Element element = identifierEls.get(i);
        Attribute attribute = element.getAttribute("type");
        if (attribute.getValue().toLowerCase().equals("urn")) urn = element.getValue();
      }

      if (urn != null && urn.equals("")) urn = null;

      return urn;
    } catch (ValidityException ve) {
      throw new IOException(ve);
    } catch (ParsingException pe) {
      throw new IOException(pe);
    } catch (IOException ie) {
      throw new IOException(ie);
    } finally {
      fileInputStream.close();
      bomInputStream.close();
    }
  }
Esempio n. 5
0
  /**
   * Parse the type attribute of <Expr>, <Ind>, <Data> and <Var> elements.
   *
   * @param element The element whose type attribute should be parsed.
   * @return A unique numeric identifier generated by the type system.
   * @throws ParseException Thrown if the type specified in the type attribute is invalid.
   */
  private int parseTypeAttribute(Element element) throws ParseException {
    Attribute type = element.getAttribute(tagNames.TYPE);

    int typeid = Types.IOBJECT;

    if (type != null) {
      typeid = Types.typeID(type.getValue().trim());
      if (typeid == -1) {
        throw new ParseException("Type " + type.getValue().trim() + " is not defined.");
      }
    }

    return typeid;
  }
  /**
   * @param text
   * @param validate
   * @return
   * @throws org.purl.sword.base.UnmarshallException
   */
  public SwordValidationInfo unmarshall(Element text, Properties validationProperties)
      throws UnmarshallException {
    if (!isInstanceOf(text, xmlName)) {
      return handleIncorrectElement(text, validationProperties);
    }

    ArrayList<SwordValidationInfo> validationItems = new ArrayList<SwordValidationInfo>();
    ArrayList<SwordValidationInfo> attributeItems = new ArrayList<SwordValidationInfo>();

    try {
      initialise();

      // get the attributes
      int attributeCount = text.getAttributeCount();
      Attribute attribute = null;
      for (int i = 0; i < attributeCount; i++) {
        attribute = text.getAttribute(i);
        if (ATTRIBUTE_TYPE.equals(attribute.getQualifiedName())) {
          boolean success = true;
          String value = attribute.getValue();
          if (ContentType.TEXT.toString().equals(value)) {
            type = ContentType.TEXT;
          } else if (ContentType.HTML.toString().equals(value)) {
            type = ContentType.HTML;
          } else if (ContentType.XHTML.toString().equals(value)) {
            type = ContentType.XHTML;
          } else {
            log.error("Unable to parse extract type in " + getQualifiedName());
            SwordValidationInfo info =
                new SwordValidationInfo(
                    xmlName,
                    new XmlName(attribute),
                    "Invalid content type has been specified",
                    SwordValidationInfoType.ERROR);
            info.setContentDescription(value);
            attributeItems.add(info);
            success = false;
          }

          if (success) {
            SwordValidationInfo info = new SwordValidationInfo(xmlName, new XmlName(attribute));
            info.setContentDescription(type.toString());
            attributeItems.add(info);
          }
        } else {
          SwordValidationInfo info =
              new SwordValidationInfo(
                  xmlName,
                  new XmlName(attribute),
                  SwordValidationInfo.UNKNOWN_ATTRIBUTE,
                  SwordValidationInfoType.INFO);
          info.setContentDescription(attribute.getValue());
          attributeItems.add(info);
        }
      }

      // retrieve all of the sub-elements
      int length = text.getChildCount();
      if (length > 0) {
        content = unmarshallString(text);
      }

    } catch (Exception ex) {
      log.error("Unable to parse an element in " + getQualifiedName() + ": " + ex.getMessage());
      throw new UnmarshallException("Unable to parse an element in " + getQualifiedName(), ex);
    }

    SwordValidationInfo result = null;
    if (validationProperties != null) {
      result = validate(validationItems, attributeItems, validationProperties);
    }
    return result;
  }
Esempio n. 7
0
 /** @see net.sf.memoranda.Event#getRepeat() */
 public int getRepeat() {
   Attribute a = _elem.getAttribute("repeat-type");
   if (a != null) return new Integer(a.getValue()).intValue();
   return 0;
 }
Esempio n. 8
0
 /** @see net.sf.memoranda.Event#getId() */
 public String getId() {
   Attribute a = _elem.getAttribute("id");
   if (a != null) return a.getValue();
   return null;
 }
Esempio n. 9
0
 /** @see net.sf.memoranda.Event#getPeriod() */
 public int getPeriod() {
   Attribute a = _elem.getAttribute("period");
   if (a != null) return new Integer(a.getValue()).intValue();
   return 0;
 }
Esempio n. 10
0
 /** @see net.sf.memoranda.Event#getEndDate() */
 public CalendarDate getEndDate() {
   Attribute a = _elem.getAttribute("endDate");
   if (a != null) return new CalendarDate(a.getValue());
   return null;
 }
Esempio n. 11
0
 /** @see net.sf.memoranda.Event#getNote() */
 public String getNote() {
   return new String(_elem.getAttribute("note").getValue());
 }
Esempio n. 12
0
 /** @see net.sf.memoranda.Event#getMinute() */
 public int getMinute() {
   return new Integer(_elem.getAttribute("min").getValue()).intValue();
 }
Esempio n. 13
0
 /** @see net.sf.memoranda.Event#getHour() */
 public int getHour() {
   return new Integer(_elem.getAttribute("hour").getValue()).intValue();
 }
Esempio n. 14
0
 /** @see net.sf.memoranda.Event#getWorkinDays() */
 public boolean getWorkingDays() {
   Attribute a = _elem.getAttribute("workingDays");
   if (a != null && a.getValue().equals("true")) return true;
   return false;
 }
Esempio n. 15
0
  /**
   * Removes a model. Removes extension and any files.
   *
   * @param model
   */
  public void removeModel(IDSTest model, String pluginID) {

    // Remove from DSBusinessModel
    dsBusinessModel.getTests().remove(model);
    for (Endpoint ep : dsBusinessModel.getEndpoints()) {
      if (ep.getTests() != null) {
        ep.getTests().remove(model);
        logger.debug("Removed model " + model.getName() + " from EP " + ep.getName());
      }
    }

    // Remove extensions in models.container plugin
    // =============================================
    File pluginXMLfile;
    try {
      pluginXMLfile = new File(FileUtil.getFilePath("plugin.xml", pluginID));

      Builder parser = new Builder();
      Document doc = parser.build(pluginXMLfile);
      Element root = doc.getRootElement();

      Element extension = null;

      // Find extension in plugin.xml, if exists
      Elements existingExtensions = root.getChildElements("extension");
      if (existingExtensions != null && existingExtensions.size() > 0) {
        for (int i = 0; i < existingExtensions.size(); i++) {
          extension = existingExtensions.get(i);

          // If exists a model with same name, remove it
          Elements existingTests = extension.getChildElements("test");
          if (existingTests != null && existingTests.size() > 0) {
            for (int j = 0; j < existingTests.size(); j++) {
              Element test = existingTests.get(j);
              String testName = test.getAttribute("name").getValue();

              // Remove spaces included by XML serialization
              while (testName.contains("  ")) testName = testName.replace("  ", " ");

              if (model.getName().equals(testName)) {
                test.getParent().removeChild(test);
                logger.debug("Removing existing model extension: " + model.getName());

                // Also remove the files
                Elements resources = test.getChildElements("resource");
                for (int rescnt = 0; rescnt < resources.size(); rescnt++) {
                  Element resource = resources.get(rescnt);
                  String path = resource.getAttribute("path").getValue();
                  try {
                    File reFile = new File(FileUtil.getFilePath(path, pluginID));
                    if (reFile.exists()) {
                      logger.debug("Removing file: " + reFile);
                      reFile.delete();
                    } else logger.debug("Unable to locate file to remove: " + path);
                  } catch (Exception e) {
                    logger.error("Problems removing file: " + path);
                  }
                }
              }
            }
          }
        }
      }

      // Serialize the updated plugin.xml to file
      Serializer serializer = new Serializer(new FileOutputStream(pluginXMLfile));
      serializer.setIndent(4);
      serializer.setMaxLength(64);
      serializer.write(doc);

    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ValidityException e) {
      e.printStackTrace();
    } catch (ParsingException e) {
      e.printStackTrace();
    }
  }