예제 #1
0
파일: mainwindow.cpp 프로젝트: smurav/xml36
bool MainWindow::OpenXMLDocument(const QString &file_name) {
  FreeXMLDocument();

  xmlParserCtxtPtr parser = xmlNewParserCtxt();
  if (0 == parser)
    return false;

  xml_doc_ptr_ = xmlCtxtReadFile(parser,
                                 file_name.toLocal8Bit().data(),
                                 NULL,
                                 XML_PARSE_NOBLANKS);// | XML_PARSE_DTDVALID);
  if (false == parser->valid) {
    QMessageBox::critical(this, tr("Открытие XML документа"),
                          tr("Структура файла %1 не соответствует "
                          "DTD-диаграмме").arg(file_name),
                          QMessageBox::Ok);
    SetCurrentFileName("", false);
    xmlFreeParserCtxt(parser);
    FreeXMLDocument();
    return false;
  }
  AddItem(xmlDocGetRootElement(xml_doc_ptr_));
  xmlFreeParserCtxt(parser);
  UpdateButtons();
  return true;
}
예제 #2
0
파일: mainwindow.cpp 프로젝트: smurav/xml36
void MainWindow::on_actionNew_triggered() {
  if (!MaybeSave())
    return;

  static int sequence_number = 1;
  SetCurrentFileName(tr("doc%1.xml").arg(sequence_number++), true);
  SetModified(true);

  FreeXMLDocument();
  xml_doc_ptr_ = xmlNewDoc(BAD_CAST "1.0");
  UpdateButtons();
}
예제 #3
0
static CFURLRef FindJnlpURLInFile(char* fileName) {
    XMLNode* doc = NULL;
    CFURLRef returnValue = NULL;
    char* jnlbuffer = NULL;

    /* Parse XML document. */
    if (!ReadFileToBuffer(fileName, &jnlbuffer)) {
        return NULL;
    }

    doc = ParseXMLDocument(jnlbuffer);
    if (doc != NULL) {
        XMLNode* node = NULL;
        char *codebase = NULL;
        char *href = NULL;
        CFStringRef baseURLString = NULL;
        CFStringRef hrefString = NULL;
        CFMutableStringRef fullURL = NULL;

        node = FindXMLChild(doc, "jnlp");
        require(node != NULL, bail);
        codebase = FindXMLAttribute(node->_attributes, "codebase");
        require(codebase != NULL, bail);
        href = FindXMLAttribute(node->_attributes, "href");
        require(href != NULL, bail);

        baseURLString = CFStringCreateWithCString(NULL, codebase, kCFStringEncodingUTF8);
        require(baseURLString != NULL, bail);

        fullURL = CFStringCreateMutableCopy(NULL, 0, baseURLString);
        hrefString = CFStringCreateWithCString(NULL, href, kCFStringEncodingUTF8);
        require(hrefString != NULL, bail);

        // a relative JNLP path needs a URL that starts at the specificed codebase
        if (!CFStringHasSuffix(fullURL, CFSTR("/")))
            CFStringAppend(fullURL, CFSTR("/"));
        CFStringAppend(fullURL, hrefString);

        returnValue = CFURLCreateWithString(NULL, fullURL, NULL);
bail:
        if (baseURLString != NULL) CFRelease(baseURLString);
        if (hrefString != NULL) CFRelease(hrefString);
        if (fullURL != NULL) CFRelease(fullURL);
        FreeXMLDocument(doc);
    }

    free(jnlbuffer);
    return returnValue;
}
예제 #4
0
/* Parse the XML Launch file 
 *
 * Looks for the following path: <jnlp><resources><j2se version=attr>
 */
static void ParseXMLLaunchFile(char* s, JNLFile* jnlfile) {   
    XMLNode* doc = NULL;
    XMLNode* node = NULL;
    XMLNode* resources = NULL;
    XMLNode* tempnode = NULL;
    char* str;
    char* codebase;
    char* href;
    char *name;
    char *value;

    /* added for getting canonical home */
    char* firstjar = NULL;
    char* mainjar = NULL;
    char* str2;  

    jnlfile->jreVersion = NULL;
    jnlfile->jreLocation = NULL;
    jnlfile->isPlayer = FALSE;
    jnlfile->canonicalHome = NULL;

    /* Parse XML document. */
    doc = ParseXMLDocument(s);
    if (doc != NULL) {
      node = FindXMLChild(doc, "jnlp");      
     
      if (node != NULL) {
        codebase = FindXMLAttribute(node->_attributes, "codebase");
        href = FindXMLAttribute(node->_attributes, "href");
	if ((codebase != NULL) && (href != NULL)) {
	  if (strstr(href, "http:") == href) { 
	    jnlfile->jnlp_url = href;
	  } else {
	    char *last;
	    jnlfile->jnlp_url = malloc(strlen(codebase) + strlen(href) + 2);
	    strcpy(jnlfile->jnlp_url, codebase);
	    last = codebase + (strlen(codebase) - 1);
	    if (*last != '/') {
	      strcat(jnlfile->jnlp_url, "/");
	    }
	    strcat(jnlfile->jnlp_url, href);
	  }
	  /* canonical home is equal to href if href exist */
	  jnlfile->canonicalHome = malloc(strlen(jnlfile->jnlp_url) + 1);
	  strcpy(jnlfile->canonicalHome, jnlfile->jnlp_url);	
	}
      }

      /* find main jar to generate canonical home if no href */
      if (node != NULL && jnlfile->canonicalHome == NULL) {
         tempnode = FindXMLChild(node->_sub, "resources");
         if (tempnode != NULL) { 
        
	    tempnode = FindXMLChild(tempnode->_sub, "jar");
	  
	    /* go thru all jars and find main jar */	   
	    while (tempnode && mainjar == NULL) {	     
	      str = FindXMLAttribute(tempnode->_attributes, "href");	     
	      if (firstjar == NULL) {
		firstjar = malloc(strlen(str) + 1);	      
		strcpy(firstjar, str);	     
	      }	    
	      str2 = FindXMLAttribute(tempnode->_attributes, "main");	     
	      if (str2 != NULL && sysStrCaseCmp(str2, "true") == 0) {
		mainjar = malloc(strlen(str) + 1);	      
		strcpy(mainjar, str);		
	      }	   
	      tempnode = tempnode->_next;	      
	    }
	    /* if no main jar, return first jar */
	    if (mainjar == NULL) {
	      mainjar = strdup(firstjar);	     
	    }

	    if (codebase != NULL && mainjar != NULL) {
	      /* generate canonicalHome */
	      char *last;
	      jnlfile->canonicalHome = malloc(strlen(codebase) + strlen(mainjar) + 2);
	      strcpy(jnlfile->canonicalHome, codebase);
	      last = codebase + (strlen(codebase) - 1);
	      if (*last != '/') {
		strcat(jnlfile->canonicalHome, "/");
	      }
	      strcat(jnlfile->canonicalHome, mainjar);
	     
	    }
	 }
      }
     

      if (node != NULL) {
         resources = FindXMLChild(node->_sub, "resources");
         if (resources != NULL) { 
            node = FindXMLChild(resources->_sub, "j2se");
            if (node != NULL) {
		  str = FindXMLAttribute(node->_attributes, "version");
		  if (str != NULL) jnlfile->jreVersion = strdup(str);
		  str = FindXMLAttribute(node->_attributes, "href");
		  if (str != NULL) jnlfile->jreLocation = strdup(str);
		  
		  str = FindXMLAttribute(node->_attributes, "max-heap-size");
		  if (str != NULL) jnlfile->maxHeap = strdup(str);
		  str = FindXMLAttribute(node->_attributes, "initial-heap-size");
		  if (str != NULL) jnlfile->initialHeap = strdup(str);
            }
            node = FindXMLChild(resources->_sub, "property");
            while (node != NULL) {
                name = FindXMLAttribute(node->_attributes, "name");
                if (name != NULL) {
                    value = FindXMLAttribute(node->_attributes, "value");
                    if (value != NULL) {
                        if (isSecureProperty(name)) {
                            char *auxArg = malloc(16+strlen(name)+strlen(value));
                            sprintf(auxArg, "%s=%s",name, value);
                            addAuxArg(jnlfile, auxArg);
                        }
                    }    
                }
                node = FindXMLChild(node->_next, "property");
            }
         }
      }
    }

    /* Check for player */
    if (doc != NULL && FindXMLChild(doc, "player") != NULL) {
         jnlfile->isPlayer = TRUE;
    }

    free(firstjar);
    free(mainjar);
    FreeXMLDocument(doc);
}
예제 #5
0
파일: mainwindow.cpp 프로젝트: smurav/xml36
MainWindow::~MainWindow() {
  FreeXMLDocument();
  FreeXMLSchema();
  delete ui_;
  ui_ = 0;
}